2 #include <tclap/CmdLine.h> 6 #include <itkTimeProbe.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 argc,
char **argv)
17 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
19 TCLAP::ValueArg<std::string> refLTArg(
"i",
"input",
"Test Image",
true,
"",
"test image",cmd);
20 TCLAP::ValueArg<std::string> dataLTArg(
"I",
"database",
"Database Image List",
true,
"",
"database image list",cmd);
22 TCLAP::ValueArg<std::string> maskArg(
"m",
"maskname",
"Computation mask",
true,
"",
"computation mask",cmd);
23 TCLAP::ValueArg<std::string> resArg(
"o",
"outputpval",
"P-values output image",
true,
"",
"P-values output image",cmd);
25 TCLAP::ValueArg<std::string> dbMeanDistAveArg(
"d",
"dbmeanave",
"DB average mean distance image",
true,
"",
"DB average mean distance image",cmd);
26 TCLAP::ValueArg<std::string> dbMeanDistStdArg(
"D",
"dbmeanstd",
"DB std mean distance image",
true,
"",
"DB std mean distance image",cmd);
27 TCLAP::ValueArg<std::string> dbCovDistAveArg(
"",
"dbcovave",
"DB average covariance distance image",
true,
"",
"DB average covariance distance image",cmd);
28 TCLAP::ValueArg<std::string> dbCovDistStdArg(
"",
"dbcovstd",
"DB std covariance distance image",
true,
"",
"DB std covariance distance image",cmd);
30 TCLAP::ValueArg<std::string> resScoreArg(
"O",
"outputscore",
"Score output image",
false,
"",
"Score output image",cmd);
31 TCLAP::ValueArg<std::string> resNumPatchesArg(
"",
"outputnpatches",
"Number of patches output image",
false,
"",
"Number of patches output image",cmd);
33 TCLAP::ValueArg<double> weightThrArg(
"w",
"weightthr",
"NL weight threshold: patches around have to be similar enough (default: 0.0)",
false,0.0,
"NL weight threshold",cmd);
34 TCLAP::ValueArg<double> meanThrArg(
"M",
"patchmeanthr",
"Tolerance for means test (test if meansTest > meanDatabase + M * stdDatabase, default: M=2.5)",
false,2.5,
"NL mean patch proportion",cmd);
35 TCLAP::ValueArg<double> varThrArg(
"c",
"patchcovthr",
"Tolerance for covariance test (test if covDist > meanDatabase + c * stdDatabase, default: c=2.5)",
false,2.5,
"NL covariance patch proportion",cmd);
37 TCLAP::ValueArg<double> betaArg(
"b",
"beta",
"Beta parameter for local noise estimation (default: 1)",
false,1,
"Beta for local noise estimation",cmd);
39 TCLAP::ValueArg<unsigned int> nbpArg(
"p",
"numberofthreads",
"Number of threads to run on (default: all cores)",
false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),
"number of threads",cmd);
41 TCLAP::ValueArg<unsigned int> patchHSArg(
"",
"patchhalfsize",
"Patch half size in each direction (default: 1)",
false,1,
"patch half size",cmd);
42 TCLAP::ValueArg<unsigned int> patchSSArg(
"",
"patchstepsize",
"Patch step size for searching (default: 1)",
false,1,
"patch search step size",cmd);
43 TCLAP::ValueArg<unsigned int> patchNeighArg(
"n",
"patchneighborhood",
"Patch half neighborhood size (default: 2)",
false,2,
"patch search neighborhood size",cmd);
49 catch (TCLAP::ArgException& e)
51 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
55 typedef itk::VectorImage<double,3> LogTensorImageType;
58 itk::CStyleCommand::Pointer callback = itk::CStyleCommand::New();
61 NLComparisonImageFilterType::Pointer mainFilter = NLComparisonImageFilterType::New();
62 mainFilter->SetComputationMask(
anima::readImage < itk::Image <unsigned char, 3> > (maskArg.getValue()));
63 mainFilter->SetNumberOfWorkUnits(nbpArg.getValue());
65 mainFilter->SetWeightThreshold(weightThrArg.getValue());
66 mainFilter->SetMeanThreshold(meanThrArg.getValue());
67 mainFilter->SetVarianceThreshold(varThrArg.getValue());
69 mainFilter->SetPatchHalfSize(patchHSArg.getValue());
70 mainFilter->SetSearchStepSize(patchSSArg.getValue());
71 mainFilter->SetSearchNeighborhood(patchNeighArg.getValue());
72 mainFilter->SetBetaParameter(betaArg.getValue());
74 mainFilter->SetInput(0,anima::readImage <LogTensorImageType> (refLTArg.getValue()));
75 mainFilter->AddObserver(itk::ProgressEvent(), callback);
77 std::ifstream fileIn(dataLTArg.getValue());
82 fileIn.getline(tmpStr,2048);
84 if (strcmp(tmpStr,
"") == 0)
87 std::cout <<
"Loading database image " << tmpStr <<
"..." << std::endl;
88 mainFilter->AddDatabaseInput(anima::readImage <LogTensorImageType> (tmpStr));
92 mainFilter->SetDatabaseMeanDistanceAverage(
anima::readImage < itk::Image <double, 3> > (dbMeanDistAveArg.getValue()));
93 mainFilter->SetDatabaseMeanDistanceStd(
anima::readImage < itk::Image <double, 3> > (dbMeanDistStdArg.getValue()));
95 mainFilter->SetDatabaseCovarianceDistanceAverage(
anima::readImage < itk::Image <double, 3> > (dbCovDistAveArg.getValue()));
96 mainFilter->SetDatabaseCovarianceDistanceStd(
anima::readImage < itk::Image <double, 3> > (dbCovDistStdArg.getValue()));
100 mainFilter->Update();
102 catch (itk::ExceptionObject &e)
104 std::cerr << e << std::endl;
108 anima::writeImage < itk::Image <double, 3> > (resArg.getValue(),mainFilter->GetOutput(0));
110 if (resScoreArg.getValue() !=
"")
111 anima::writeImage < itk::Image <double, 3> > (resScoreArg.getValue(),mainFilter->GetOutput(1));
113 if (resNumPatchesArg.getValue() !=
"")
114 anima::writeImage < itk::Image <double, 3> > (resNumPatchesArg.getValue(),mainFilter->GetOutput(2));
void eventCallback(itk::Object *caller, const itk::EventObject &event, void *clientData)
int main(int argc, char **argv)
void writeImage(std::string filename, OutputImageType *img)
itk::SmartPointer< ImageType > readImage(std::string filename)