1 /*=========================================================================
4 Module: $RCSfile: clitkImageUncertainty.cxx,v $
6 Date: $Date: 2011/03/03 15:03:30 $
7 Version: $Revision: 1.3 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*/
19 #ifndef CLITKIMAGEUNCERTAINTY_CXX
20 #define CLITKIMAGEUNCERTAINTY_CXX
23 =================================================
24 * @file clitkImageUncertainty.cxx
25 * @author David Sarrut <david.sarrut@creatis.insa-lyon.fr>
26 * @date 04 Jul 2006 14:03:57
31 =================================================*/
34 #include "clitkImageUncertainty_ggo.h"
35 #include "clitkImageCommon.h"
36 #include "clitkCommon.h"
37 #include "clitkPortability.h"
40 #include "itkImageRegionConstIterator.h"
41 #include "itkImageRegionIterator.h"
43 //====================================================================
44 int main(int argc, char * argv[]) {
47 GGO(clitkImageUncertainty, args_info);
50 typedef float PixelType;
51 const unsigned int Dimension=3;
52 typedef itk::Image< PixelType, Dimension > ImageType;
55 ImageType::Pointer input =
56 clitk::readImage<ImageType>(args_info.input_arg, args_info.verbose_flag);
57 ImageType::Pointer inputSquared =
58 clitk::readImage<ImageType>(args_info.inputSquared_arg, args_info.verbose_flag);
61 ImageType::Pointer output = ImageType::New();
62 output->SetRegions(input->GetLargestPossibleRegion());
63 output->CopyInformation(input);
67 typedef itk::ImageRegionConstIterator<ImageType> ConstIteratorType;
68 ConstIteratorType pi(input, input->GetLargestPossibleRegion());
69 ConstIteratorType pii(inputSquared, inputSquared->GetLargestPossibleRegion());
72 typedef itk::ImageRegionIterator<ImageType> IteratorType;
73 IteratorType po(output, output->GetLargestPossibleRegion());
76 int NumberOfEvents = args_info.NumberOfEvents_arg;
77 while ( !pi.IsAtEnd() ) {
78 double squared = pii.Get();
79 double mean = pi.Get();
80 double uncert = sqrt((NumberOfEvents*squared - mean*mean) / (NumberOfEvents-1));
81 if(!args_info.absolute_flag)
82 uncert /= std::abs(mean);
83 if (!IsNormal(uncert)) uncert = args_info.default_arg;
91 // DD(clitk::GetExtension(args_info.output_arg));
92 if (clitk::GetExtension(args_info.output_arg) != "txt") {
93 clitk::writeImage<ImageType>(output, args_info.output_arg, args_info.verbose_flag);
97 clitk::openFileForWriting(os, args_info.output_arg);
98 typedef itk::ImageRegionConstIterator<ImageType> IteratorType;
99 IteratorType pi(output, output->GetLargestPossibleRegion());
101 os << "# Image size = " << output->GetLargestPossibleRegion().GetSize() << std::endl;
102 os << "# Image spacing = " << output->GetSpacing() << std::endl;
103 os << "# Number of events = " << NumberOfEvents << std::endl;
104 while (!pi.IsAtEnd()) {
105 os << pi.Get() << std::endl;
112 #endif /* end #define CLITKIMAGEUNCERTAINTY_CXX */