4 #include <tclap/CmdLine.h> 7 #include <itkCommand.h> 10 void eventCallback (itk::Object* caller,
const itk::EventObject& event,
void* clientData)
12 itk::ProcessObject * processObject = (itk::ProcessObject*) caller;
13 std::cout<<
"\033[K\rProgression: "<<(int)(processObject->GetProgress() * 100)<<
"%"<<std::flush;
16 int main(
int ac,
const char** av)
19 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
21 TCLAP::ValueArg<std::string> inputArg(
"i",
29 TCLAP::ValueArg<std::string> outputArg(
"o",
31 "Output denoised image",
34 "Output denoised image",
37 TCLAP::ValueArg<unsigned int> weightMethod(
"W",
39 "Thr weight method -> 0: Exponential, 1: Rician, default: Exponential(0)",
42 "The Weighting method",
45 TCLAP::ValueArg<double> weightThrArg(
"w",
47 "Weight threshold: patches around have to be similar enough -> default: 0.0",
53 TCLAP::ValueArg<double> betaArg(
"b",
55 "Beta parameter for local noise estimation -> default: 1",
58 "Beta for local noise estimation",
61 TCLAP::ValueArg<double> meanMinArg(
"m",
63 "Minimun mean threshold (default: 0.95)",
66 "Minimun mean threshold",
69 TCLAP::ValueArg<double> varMinArg(
"v",
71 "Minimun variance threshold -> default: 0.5",
74 "Minimun variance threshold",
77 TCLAP::ValueArg<unsigned int> nbpArg(
"p",
79 "Number of threads to run on -> default : automatically determine",
81 itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),
85 TCLAP::ValueArg<unsigned int> patchHSArg(
"S",
87 "Patch half size in each direction -> default: 1",
93 TCLAP::ValueArg<unsigned int> patchSSArg(
"s",
95 "Patch step size for searching -> default: 1",
98 "Patch search step size",
101 TCLAP::ValueArg<unsigned int> patchNeighArg(
"n",
103 "Patch half neighborhood size -> default: 5",
106 "Patch search neighborhood size",
113 catch (TCLAP::ArgException& e)
115 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
120 itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(inputArg.getValue().c_str(),
121 itk::ImageIOFactory::ReadMode);
125 std::cerr <<
"Itk could not find a suitable IO factory for the input" << std::endl;
130 imageIO->SetFileName(inputArg.getValue());
131 imageIO->ReadImageInformation();
133 itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
136 unsigned int const nbDimension = imageIO->GetNumberOfDimensions ();
137 std::cout<<
"Image has "<<nbDimension<<
" dimension.\n";
143 std::cerr<<
"ERROR !\nInput has only two dimension, you should use the animaNLMeans command.";
150 std::cerr<<
"This command is designed for temporal images.\nIf you want to compute a simple volume, you should use the animaNLMeans command.\nContinue? (y/n) ";
161 std::cerr<<
"Please press \"n\" or \"y\".\nContinue? (y/n) ";
166 std::cout<<
"preparing filter..." << std::endl;
168 typedef itk::Image<double, 3> ImageType;
171 FilterType::Pointer filter = FilterType::New();
172 filter->SetInput(anima::readImage <ImageType> (inputArg.getValue()));
174 filter->SetWeightThreshold(weightThrArg.getValue());
175 filter->SetPatchHalfSize(patchHSArg.getValue());
176 filter->SetSearchStepSize(patchSSArg.getValue());
177 filter->SetSearchNeighborhood(patchNeighArg.getValue());
178 filter->SetBetaParameter(betaArg.getValue());
179 filter->SetMeanMinThreshold(meanMinArg.getValue());
180 filter->SetVarMinThreshold(varMinArg.getValue());
181 filter->SetWeightMethod(FilterType::EXP);
182 if (weightMethod.getValue())
183 filter->SetWeightMethod(FilterType::RICIAN);
185 filter->SetNumberOfWorkUnits(nbpArg.getValue());
191 anima::writeImage <ImageType> (outputArg.getValue(),filter->GetOutput());
193 catch( itk::ExceptionObject & err )
195 std::cerr <<
"Itk cannot write output, be sure to use a valid extension..." << std::endl;
196 std::cerr << err << std::endl;
203 std::cout<<
"preparing filter..." << std::endl;
205 typedef itk::Image<double, 4> ImageType;
208 FilterType::Pointer filter = FilterType::New();
209 filter->SetInput(anima::readImage <ImageType> (inputArg.getValue()));
211 filter->SetWeightThreshold(weightThrArg.getValue());
212 filter->SetPatchHalfSize(patchHSArg.getValue());
213 filter->SetSearchStepSize(patchSSArg.getValue());
214 filter->SetSearchNeighborhood(patchNeighArg.getValue());
215 filter->SetBetaParameter(betaArg.getValue());
216 filter->SetMeanMinThreshold(meanMinArg.getValue());
217 filter->SetVarMinThreshold(varMinArg.getValue());
218 filter->SetWeightMethod(FilterType::EXP);
219 if (weightMethod.getValue())
220 filter->SetWeightMethod(FilterType::RICIAN);
222 filter->SetNumberOfWorkUnits(nbpArg.getValue());
224 filter->AddObserver(itk::ProgressEvent(), callback );
229 anima::writeImage <ImageType> (outputArg.getValue(),filter->GetOutput());
231 catch( itk::ExceptionObject & err )
233 std::cerr <<
"Itk cannot write output, be sure to use a valid extension..." << std::endl;
234 std::cerr << err << std::endl;
241 itk::ExceptionObject excp;
242 excp.SetDescription(
"The file uses a number of dimension that is not supported in this application");
247 std::cout << std::endl;
int main(int ac, const char **av)
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)