1 #include <tclap/CmdLine.h> 6 #include <itkComposeImageFilter.h> 10 std::vector<std::string>
inputs;
15 template <
class InputImageType>
20 typedef itk::VectorImage<typename InputImageType::PixelType, InputImageType::ImageDimension> OutputImageType;
22 typedef itk::ComposeImageFilter<InputImageType, OutputImageType> ComposeImageFilterType;
23 typename ComposeImageFilterType::Pointer composeImageFilter = ComposeImageFilterType::New();
28 composeImageFilter->SetInput(i, anima::readImage<InputImageType>(args.
inputs[i]));
32 std::string inputName = args.
inputs[0];
33 anima::setMultipleImageFilterInputsFromFileName<InputImageType,ComposeImageFilterType>(inputName,composeImageFilter);
36 composeImageFilter->Update();
38 anima::writeImage<OutputImageType>(args.
output, composeImageFilter->GetOutput());
41 template <
class ComponentType,
int dimension>
45 if(imageIO->GetNumberOfComponents() != 1)
47 itk::ExceptionObject excp(__FILE__, __LINE__,
"Number of components not supported.", ITK_LOCATION);
52 typedef itk::Image<ComponentType, dimension> ImageType;
53 vectorize<ImageType>(args);
57 template <
class ComponentType>
64 int main(
int ac,
const char** av)
66 TCLAP::CmdLine cmd(
"animaVectorizeImage is used to combine several scalar images into a multicomponent Vector image." 67 "INRIA / IRISA - VisAGeS/Empenn Team",
71 TCLAP::MultiArg<std::string> inputArg(
"i",
73 "input images (list in text file or multiple arguments)",
78 TCLAP::ValueArg<std::string> outputArg(
"o",
90 catch (TCLAP::ArgException& e)
92 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
96 itk::ImageIOBase::Pointer
imageIO = itk::ImageIOFactory::CreateImageIO(inputArg.getValue()[0].c_str(),itk::ImageIOFactory::ReadMode);
103 std::ifstream fileIn (inputArg.getValue()[0].c_str());
105 fileIn.getline(tmpStr,2048);
107 while ((strcmp(tmpStr,
"") == 0) && (!fileIn.eof()))
108 fileIn.getline(tmpStr,2048);
111 imageIO = itk::ImageIOFactory::CreateImageIO(tmpStr,itk::ImageIOFactory::ReadMode);
117 std::cerr <<
"Itk could not find suitable IO factory for the input" << std::endl;
121 imageIO->SetFileName(tmpStr);
122 imageIO->ReadImageInformation();
123 args.fileList =
true;
129 imageIO->SetFileName(inputArg.getValue()[0]);
130 imageIO->ReadImageInformation();
133 args.inputs = inputArg.getValue(); args.output = outputArg.getValue();
135 if(args.output !=
"")
141 catch ( itk::ExceptionObject & err )
143 std::cerr <<
"Itk cannot vectorize, be sure to use valid arguments..." << std::endl;
144 std::cerr << err << std::endl;
int main(int ac, const char **av)
std::vector< std::string > inputs
void vectorize(const arguments &args)
itk::ImageIOBase::Pointer imageIO
unsigned int nbComponents
void checkIfComponentsAreVectors(itk::ImageIOBase::Pointer imageIO, const arguments &args)
#define ANIMA_RETRIEVE_COMPONENT_TYPE(imageIO, function,...)
void retrieveNbDimensions(itk::ImageIOBase::Pointer imageIO, const arguments &args)
#define ANIMA_RETRIEVE_NUMBER_OF_DIMENSIONS(imageIO, ComponentType, function,...)