3 #include <tclap/CmdLine.h> 6 #include <itkCommand.h> 9 void eventCallback (itk::Object* caller,
const itk::EventObject& event,
void* clientData)
11 itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
12 std::cout<<
"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<
"%"<<std::flush;
15 int main(
int ac,
const char** av)
18 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
20 TCLAP::ValueArg<std::string> inputArg(
"i",
28 TCLAP::ValueArg<std::string> outputArg(
"o",
30 "Output denoised image",
33 "Output denoised image",
36 TCLAP::ValueArg<unsigned int> weightMethod(
"W",
38 "Thr weight method -> 0: Exponential, 1: Rician, default: Exponential(0)",
41 "The Weighting method",
44 TCLAP::ValueArg<double> weightThrArg(
"w",
46 "Weight threshold: patches around have to be similar enough -> default: 0.0",
52 TCLAP::ValueArg<double> betaArg(
"b",
54 "Beta parameter for local noise estimation -> default: 1",
57 "Beta for local noise estimation",
60 TCLAP::ValueArg<double> meanMinArg(
"m",
62 "Minimun mean threshold (default: 0.95)",
65 "Minimun mean threshold",
68 TCLAP::ValueArg<double> varMinArg(
"v",
70 "Minimun variance threshold -> default: 0.5",
73 "Minimun variance threshold",
76 TCLAP::ValueArg<unsigned int> nbpArg(
"p",
78 "Number of threads to run on -> default : automatically determine",
80 itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),
84 TCLAP::ValueArg<unsigned int> patchHSArg(
"S",
86 "Patch half size in each direction -> default: 1",
92 TCLAP::ValueArg<unsigned int> patchSSArg(
"s",
94 "Patch step size for searching -> default: 1",
97 "Patch search step size",
100 TCLAP::ValueArg<unsigned int> patchNeighArg(
"n",
102 "Patch half neighborhood size -> default: 5",
105 "Patch search neighborhood size",
112 catch (TCLAP::ArgException& e)
114 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
119 itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(inputArg.getValue().c_str(),
120 itk::ImageIOFactory::ReadMode);
124 std::cerr <<
"Itk could not find a suitable IO factory for the input" << std::endl;
129 imageIO->SetFileName(inputArg.getValue());
130 imageIO->ReadImageInformation();
132 unsigned int const nbDimension = imageIO->GetNumberOfDimensions ();
133 std::cout<<
"Image has "<<nbDimension<<
" dimension.\n";
135 itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
142 std::cout<<
"preparing filter..." << std::endl;
144 typedef itk::Image<double, 2> ImageType;
147 FilterType::Pointer filter = FilterType::New();
148 filter->SetInput(anima::readImage <ImageType> (inputArg.getValue()));
150 filter->SetWeightThreshold(weightThrArg.getValue());
151 filter->SetPatchHalfSize(patchHSArg.getValue());
152 filter->SetSearchStepSize(patchSSArg.getValue());
153 filter->SetSearchNeighborhood(patchNeighArg.getValue());
154 filter->SetBetaParameter(betaArg.getValue());
155 filter->SetMeanMinThreshold(meanMinArg.getValue());
156 filter->SetVarMinThreshold(varMinArg.getValue());
157 filter->SetWeightMethod(FilterType::EXP);
158 if (weightMethod.getValue())
159 filter->SetWeightMethod(FilterType::RICIAN);
161 filter->SetNumberOfWorkUnits(nbpArg.getValue());
163 filter->AddObserver(itk::ProgressEvent(), callback );
168 anima::writeImage <ImageType> (outputArg.getValue(),filter->GetOutput());
170 catch( itk::ExceptionObject & err )
172 std::cerr <<
"Itk cannot write output, be sure to use a valid extension..." << std::endl;
173 std::cerr << err << std::endl;
181 std::cout<<
"preparing filter..." << std::endl;
183 typedef itk::Image<double, 3> ImageType;
186 FilterType::Pointer filter = FilterType::New();
187 filter->SetInput(anima::readImage <ImageType> (inputArg.getValue()));
189 filter->SetWeightThreshold(weightThrArg.getValue());
190 filter->SetPatchHalfSize(patchHSArg.getValue());
191 filter->SetSearchStepSize(patchSSArg.getValue());
192 filter->SetSearchNeighborhood(patchNeighArg.getValue());
193 filter->SetBetaParameter(betaArg.getValue());
194 filter->SetMeanMinThreshold(meanMinArg.getValue());
195 filter->SetVarMinThreshold(varMinArg.getValue());
196 filter->SetWeightMethod(FilterType::EXP);
197 if (weightMethod.getValue())
198 filter->SetWeightMethod(FilterType::RICIAN);
200 filter->SetNumberOfWorkUnits(nbpArg.getValue());
202 filter->AddObserver(itk::ProgressEvent(), callback );
207 anima::writeImage <ImageType> (outputArg.getValue(),filter->GetOutput());
209 catch( itk::ExceptionObject & err )
211 std::cerr <<
"Itk cannot write output, be sure to use a valid extension..." << std::endl;
212 std::cerr << err << std::endl;
219 std::cerr<<
"WARNING !\nInput is a 4D image, you should use the animaNLMeans-temporal command.\nContinue anyway? (y/n) ";
229 std::cerr<<
"Please press \"n\" or \"y\".\nContinue anyway? (y/n) ";
234 std::cout<<
"preparing filter...\n";
236 typedef itk::Image<double, 4> ImageType;
239 FilterType::Pointer filter = FilterType::New();
240 filter->SetInput(anima::readImage <ImageType> (inputArg.getValue()));
242 filter->SetWeightThreshold(weightThrArg.getValue());
243 filter->SetPatchHalfSize(patchHSArg.getValue());
244 filter->SetSearchStepSize(patchSSArg.getValue());
245 filter->SetSearchNeighborhood(patchNeighArg.getValue());
246 filter->SetBetaParameter(betaArg.getValue());
247 filter->SetMeanMinThreshold(meanMinArg.getValue());
248 filter->SetVarMinThreshold(varMinArg.getValue());
249 filter->SetWeightMethod(FilterType::EXP);
250 if (weightMethod.getValue())
251 filter->SetWeightMethod(FilterType::RICIAN);
253 filter->SetNumberOfWorkUnits(nbpArg.getValue());
255 filter->AddObserver(itk::ProgressEvent(), callback );
260 anima::writeImage <ImageType> (outputArg.getValue(),filter->GetOutput());
262 catch( itk::ExceptionObject & err )
264 std::cerr <<
"Itk cannot write output, be sure to use a valid extension..." << std::endl;
265 std::cerr << err << std::endl;
272 itk::ExceptionObject excp;
273 excp.SetDescription(
"The file uses a number of dimension that is not supported in this application");
278 std::cout << std::endl;
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
int main(int ac, const char **av)