24 #ifndef itkDiffusion_CoherenceEnhancingDiffusionCommandLine_h
25 #define itkDiffusion_CoherenceEnhancingDiffusionCommandLine_h
33 namespace CoherenceEnhancingDiffusionCommandLine
39 "Input image filename. 2D and 3D images supported. Required.\n" <<
40 "Output image filename. Required.\n" <<
41 "Diffusion time. Suggested range: 0.5-5, up to 50 for strong noise. Default: 2.\n" <<
42 "Lambda. Small values detect more edges. Suggested range: 0.05, 0.0001. Default: 0.01\n" <<
43 "Weickert diffusion type. Accepted values: CED, cCED, EED, cEED, Isotropic. Default: CED.\n" <<
44 "Noise scale. Suggested range: 0.5 - 4. Default 1.\n" <<
45 "Feature scale. Suggested range: 2-6. Default 2.\n"
51 int Execute(
int argc,
char * argv[]);
53 template<
int VDimension>
56 template<
int VDimension,
typename ScalarType,
typename ComponentType>
57 int Execute(
int argc,
char * argv[],
int nComponents);
59 template<
int VDimension,
typename ScalarType,
typename PixelType,
typename ExportPixelType>
60 int Execute(
int argc,
char * argv[]);
77 const char * imageFileName = argv[1];
80 if( imageIO.IsNull() )
82 std::cerr <<
"Could not create ImageIO" << std::endl;
85 imageIO->SetFileName( imageFileName );
86 imageIO->ReadImageInformation();
88 const unsigned int imageDimension = imageIO->GetNumberOfDimensions();
90 const unsigned int nComponents = imageIO->GetNumberOfComponents();
92 switch( imageDimension )
95 return Execute<2>(argc,argv,componentType,nComponents);
97 return Execute<3>(argc,argv,componentType,nComponents);
99 itkGenericExceptionMacro(
"Sorry, unsupported image dimension.");
103 template<
int Dimension>
106 switch(componentType)
109 return Execute<Dimension, float, unsigned char>(argc,argv,nComponents);
111 return Execute<Dimension, float, float>(argc,argv,nComponents);
113 return Execute<Dimension, double, double>(argc,argv,nComponents);
115 itkGenericExceptionMacro(
"Sorry, unsupported component type");
119 template<
int Dimension,
typename ScalarType,
typename ComponentType>
120 int Execute(
int argc,
char * argv[],
int nComponents)
125 return Execute<Dimension,ScalarType,ScalarType,ComponentType>(argc,argv);
131 itkGenericExceptionMacro(
"Sorry, unsupported number of components");
135 template<
int Dimension,
typename ScalarType,
typename PixelType,
typename ExportPixelType>
136 int Execute(
int argc,
char * argv[])
141 typename ReaderType::Pointer reader = ReaderType::New();
143 const char * imageFileName = argv[1];
144 const char * outputFileName = argv[2];
145 reader->SetFileName(imageFileName);
148 typename DiffusionFilterType::Pointer diffusionFilter = DiffusionFilterType::New();
149 diffusionFilter->SetInput(reader->GetOutput());
152 diffusionFilter->AddObserver(ProgressEvent(), reportDiffusionProgress);
155 if( argIndex < argc )
157 const double diffusionTime = std::stod(argv[argIndex++]);
158 if(diffusionTime==0) itkGenericExceptionMacro(
"Error: Unrecognized diffusion time (third argument).\n");
159 diffusionFilter->SetDiffusionTime(diffusionTime);
162 if( argIndex < argc )
164 const double lambda = std::stod(argv[argIndex++]);
165 if(lambda==0.) itkGenericExceptionMacro(
"Error: Unrecognized lambda (fourth argument).\n");
166 diffusionFilter->SetLambda(lambda);
169 if( argIndex < argc )
171 const char * enhancement = argv[argIndex++];
172 if(!strcmp(enhancement,
"EED"))
173 diffusionFilter->SetEnhancement(DiffusionFilterType::EED);
174 else if(!strcmp(enhancement,
"cEED"))
175 diffusionFilter->SetEnhancement(DiffusionFilterType::cEED);
176 else if(!strcmp(enhancement,
"CED"))
177 diffusionFilter->SetEnhancement(DiffusionFilterType::CED);
178 else if(!strcmp(enhancement,
"cCED"))
179 diffusionFilter->SetEnhancement(DiffusionFilterType::cCED);
180 else if(!strcmp(enhancement,
"Isotropic"))
181 diffusionFilter->SetEnhancement(DiffusionFilterType::Isotropic);
183 itkGenericExceptionMacro(
"Error: Unrecognized enhancement (fifth argument).\n");
186 if( argIndex < argc )
188 const double noiseScale = std::stod(argv[argIndex++]);
189 if(noiseScale==0.) itkGenericExceptionMacro(
"Error: Unrecognized noiseScale (sixth argument).\n");
190 diffusionFilter->SetNoiseScale(noiseScale);
193 if( argIndex < argc )
195 const double featureScale = std::stod(argv[argIndex++]);
196 if(featureScale==0.) itkGenericExceptionMacro(
"Error: Unrecognized featureScale (seventh argument).\n");
197 diffusionFilter->SetFeatureScale(featureScale);
200 if( argIndex < argc )
202 const double exponent = std::stod(argv[argIndex++]);
203 if(exponent==0.) itkGenericExceptionMacro(
"Error: Unrecognized exponent (eighth argument).\n");
204 diffusionFilter->SetExponent(exponent);
207 if( argIndex < argc )
209 itkGenericExceptionMacro(
"Error: excessive number of arguments");
229 typename CasterType::Pointer caster = CasterType::New();
230 caster->SetInput(diffusionFilter->GetOutput());
234 typename WriterType::Pointer writer = WriterType::New();
235 writer->SetInput(caster->GetOutput());
236 writer->SetFileName(outputFileName);
242 std::cout <<
"Took: " << clock.
GetMean() <<
" seconds\n";
virtual MeanType GetMean() const
Computes the time passed between two points in code.
LinearAnisotropicDiffusionCommandLine::ReportProgressToCOutType ReportProgressToCOutType
A templated class holding a n-Dimensional vector.
Coherence enhancing diffusion and edge enhancing diffusion.
int Execute(int argc, char *argv[])
SmartPointer< Self > Pointer
Writes image data to a single file.
Data source that reads image data from a single file.
static ImageIOBasePointer CreateImageIO(const char *path, FileModeType mode)
Templated n-dimensional image class.
Casts input pixels to output pixel type.