1 #include <tclap/CmdLine.h> 3 #include <itkImageFileReader.h> 4 #include <itkImageFileWriter.h> 13 int main(
int ac,
const char** av)
15 TCLAP::CmdLine cmd(
"INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
17 TCLAP::ValueArg<std::string> inArg(
"i",
"input",
"Input image",
true,
"",
"input image",cmd);
18 TCLAP::ValueArg<std::string> outArg(
"o",
"output",
"Output resampled image",
true,
"",
"output image",cmd);
20 TCLAP::ValueArg<unsigned int> pyrNumArg(
"p",
"pyr-num",
"number of pyramid levels",
false,4,
"number of pyramid level",cmd);
21 TCLAP::ValueArg<unsigned int> pyrLevelArg(
"l",
"pyr-level",
"pyramid level image required",
false,1,
"pyramid level",cmd);
23 TCLAP::ValueArg<unsigned int> nbpArg(
"T",
"numberofthreads",
"Number of threads to run on (default : all cores)",
false,itk::MultiThreaderBase::GetGlobalDefaultNumberOfThreads(),
"number of threads",cmd);
29 catch (TCLAP::ArgException& e)
31 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
35 const unsigned int Dimension = 3;
36 typedef double PixelType;
38 typedef itk::Image< PixelType, Dimension > ImageType;
40 typedef itk::ImageFileReader<ImageType> ReaderType;
41 typedef itk::ImageFileWriter<ImageType> WriterType;
43 itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(inArg.getValue().c_str(),
44 itk::ImageIOFactory::ReadMode);
48 std::cerr <<
"Itk could not find suitable IO factory for the input" << std::endl;
53 imageIO->SetFileName(inArg.getValue());
54 imageIO->ReadImageInformation();
56 unsigned int numComponents = imageIO->GetNumberOfComponents();
58 bool tensorImage =
false;
59 if (numComponents == 6)
61 else if (numComponents != 1)
63 std::cerr <<
"Error: not a tensor or scalar image, don't know what to do" << std::endl;
69 ReaderType::Pointer reader = ReaderType::New();
70 reader->SetImageIO(imageIO);
71 reader->SetFileName(inArg.getValue());
78 PyramidType::Pointer imagePyramid = PyramidType::New();
79 imagePyramid->SetInput(reader->GetOutput());
80 ResampleFilterType::Pointer resampler = ResampleFilterType::New();
81 imagePyramid->SetImageResampler(resampler);
82 imagePyramid->SetNumberOfLevels(pyrNumArg.getValue());
83 imagePyramid->SetNumberOfWorkUnits(nbpArg.getValue());
84 imagePyramid->Update();
86 if (pyrLevelArg.getValue() >= imagePyramid->GetNumberOfLevels())
88 std::cerr <<
"Error: unable to compute a pyramid image so far, max is: " << imagePyramid->GetNumberOfLevels() - 1 << std::endl;
92 ImageType::Pointer outputImage = imagePyramid->GetOutput(pyrLevelArg.getValue());
93 outputImage->DisconnectPipeline();
95 WriterType::Pointer outWriter = WriterType::New();
96 outWriter->SetInput(outputImage);
97 outWriter->SetFileName(outArg.getValue());
98 outWriter->SetUseCompression(
true);
104 typedef itk::VectorImage <PixelType,Dimension> VectorImageType;
105 typedef itk::ImageFileReader<VectorImageType> VectorReaderType;
106 typedef itk::ImageFileWriter<VectorImageType> VectorWriterType;
108 VectorReaderType::Pointer vectorReader = VectorReaderType::New();
109 vectorReader->SetImageIO(imageIO);
110 vectorReader->Update();
113 LogTensorFilterType::Pointer tensorLogger = LogTensorFilterType::New();
115 tensorLogger->SetInput(vectorReader->GetOutput());
116 tensorLogger->SetScaleNonDiagonal(
false);
117 tensorLogger->SetNumberOfWorkUnits(nbpArg.getValue());
119 tensorLogger->Update();
124 ResampleFilterType::Pointer vectorResampler = ResampleFilterType::New();
125 vectorResampler->SetFiniteStrainReorientation(
true);
127 VectorPyramidType::Pointer vectorImagePyramid = VectorPyramidType::New();
128 vectorImagePyramid->SetInput(vectorReader->GetOutput());
129 vectorImagePyramid->SetImageResampler(vectorResampler);
130 vectorImagePyramid->SetNumberOfLevels(pyrNumArg.getValue());
131 vectorImagePyramid->SetNumberOfWorkUnits(nbpArg.getValue());
132 vectorImagePyramid->Update();
134 if (pyrLevelArg.getValue() >= vectorImagePyramid->GetNumberOfLevels())
136 std::cerr <<
"Error: unable to compute a pyramid image so far, max is: " << vectorImagePyramid->GetNumberOfLevels() - 1 << std::endl;
140 VectorImageType::Pointer vectorOutputImage = vectorImagePyramid->GetOutput(pyrLevelArg.getValue());
141 vectorOutputImage->DisconnectPipeline();
144 ExpTensorFilterType::Pointer tensorExper = ExpTensorFilterType::New();
146 tensorExper->SetInput(vectorOutputImage);
147 tensorExper->SetScaleNonDiagonal(
false);
148 tensorExper->SetNumberOfWorkUnits(nbpArg.getValue());
150 tensorExper->Update();
152 VectorWriterType::Pointer outVecWriter = VectorWriterType::New();
153 outVecWriter->SetInput(tensorExper->GetOutput());
154 outVecWriter->SetFileName(outArg.getValue());
155 outVecWriter->SetUseCompression(
true);
156 outVecWriter->Update();
Computes a pyramid of images using the provided resampler to perform resampling.
int main(int ac, const char **av)