1 #include <tclap/CmdLine.h> 4 #include <itkOrientImageFilter.h> 17 template <
class ImageType>
21 typename ImageType::Pointer
input = anima::readImage<ImageType>(args.
input);
25 typename ImageType::Pointer spaceImage = anima::readImage<ImageType>(args.
space);
27 input->CopyInformation(spaceImage);
30 std::vector < vnl_vector_fixed <double,3> > gradients;
35 GFReaderType gfReader;
37 gfReader.SetGradientIndependentNormalization(
false);
41 gradients = gfReader.GetGradients();
58 std::string outGradFileName = args.
input;
61 outGradFileName = args.
output;
63 std::size_t pointLocation = outGradFileName.find_last_of(
'.');
64 outGradFileName = outGradFileName.substr(0,pointLocation);
68 tmpStr = args.
output.substr(pointLocation + 1);
70 tmpStr = args.
input.substr(pointLocation + 1);
74 pointLocation = outGradFileName.find_last_of(
'.');
75 outGradFileName = outGradFileName.substr(0,pointLocation);
78 outGradFileName +=
".bvec";
79 std::ofstream outGrads(outGradFileName);
80 outGrads.precision(15);
81 for (
unsigned int i = 0;i < 3;++i)
83 for (
unsigned int j = 0;j < gradients.size();++j)
84 outGrads << gradients[j][i] <<
" ";
85 outGrads << std::endl;
92 input->SetMetaDataDictionary(itk::MetaDataDictionary());
97 template <
class ComponentType,
int dimension>
104 template <
class ComponentType>
111 int main(
int ac,
const char** av)
113 TCLAP::CmdLine cmd(
"animaConvertImage can be used to rewrite an image in a new compatible format ie: nii to nrrd. " 114 "It can also be used to display generic information on an image such as size, origin etc. using the --info option. " 115 "If an image file is given to the --space option it will be used to rewrite the input in the same " 116 "real coordinates repair. " 117 "The --reorient option allow to reorient the image in either the AXIAL, CORONAL or SAGITALL orientation. " 118 "Note that the reorientation is performed after the change of coordinate space if --space and --reorient " 119 "are given together.\n" 120 "INRIA / IRISA - VisAGeS/Empenn Team",
' ',ANIMA_VERSION);
122 TCLAP::ValueArg<std::string> inputArg(
"i",
130 TCLAP::ValueArg<std::string> outputArg(
"o",
138 TCLAP::SwitchArg infoArg(
"I",
140 "Display info on the image or not",
143 TCLAP::ValueArg<std::string> reorientArg(
"R",
148 "Reorient the image in 'AXIAL' or 'CORONAL' or 'SAGITTAL' direction. [defalut: No reorientation]",
151 TCLAP::ValueArg<std::string> gradsArg(
"g",
"grad",
"input gradients (apply converted image orientation matrix to get to MrTrix compatible format (iamge coordinates)",
false,
"",
"Input gradients",cmd);
153 TCLAP::ValueArg<std::string> spaceArg(
"s",
158 "Image used as space reference.",
165 catch (TCLAP::ArgException& e)
167 std::cerr <<
"Error: " << e.error() <<
"for argument " << e.argId() << std::endl;
172 itk::ImageIOBase::Pointer
imageIO = itk::ImageIOFactory::CreateImageIO(inputArg.getValue().c_str(),
173 itk::ImageIOFactory::ReadMode);
177 std::cerr <<
"Itk could not find suitable IO factory for the input" << std::endl;
182 imageIO->SetFileName(inputArg.getValue());
183 imageIO->ReadImageInformation();
186 args.
input = inputArg.getValue(); args.
output = outputArg.getValue(); args.
displayInfo = infoArg.getValue();
187 args.
reorient = reorientArg.getValue(); args.
space = spaceArg.getValue();
190 int numDimensions = imageIO->GetNumberOfDimensions() - 1;
193 std::cout <<
"NUMBER OF DIMENSIONS: " << imageIO->GetNumberOfDimensions() << std::endl;
195 std::cout <<
"SIZE : [";
196 for(
int dim = 0; dim < numDimensions; ++dim)
197 std::cout << imageIO->GetDimensions(dim) <<
", ";
198 std::cout << imageIO->GetDimensions(numDimensions) <<
"]" << std::endl;
200 std::cout <<
"ORIGIN : [";
201 for(
int dim = 0; dim < numDimensions; ++dim)
202 std::cout << imageIO->GetOrigin(dim) <<
", ";
203 std::cout << imageIO->GetOrigin(numDimensions) <<
"]" << std::endl;
205 std::cout <<
"SPACING : [";
206 for(
int dim = 0; dim < numDimensions; ++dim)
207 std::cout << imageIO->GetSpacing(dim) <<
", ";
208 std::cout << imageIO->GetSpacing(numDimensions) <<
"]" << std::endl;
210 std::cout <<
"DIRECTIONS :" << std::endl;
211 for(
unsigned int dir = 0; dir < imageIO->GetNumberOfDimensions(); ++dir)
213 std::cout <<
"\tDIM " << dir <<
" : [";
214 for (
int dim = 0; dim < numDimensions; ++dim)
215 std::cout << imageIO->GetDirection(dim)[dir] <<
", ";
216 std::cout << imageIO->GetDirection(numDimensions)[dir] <<
"]" << std::endl;
218 std::cout <<
"NUMBER OF COMPONENTS: "<< imageIO->GetNumberOfComponents()<< std::endl;
219 std::cout <<
"COMPONENT TYPE: "<< itk::ImageIOBase::GetComponentTypeAsString(imageIO->GetComponentType()) << std::endl;
228 catch ( itk::ExceptionObject & err )
230 std::cerr <<
"Itk cannot convert, be sure to use valid arguments..." << std::endl;
231 std::cerr << err << std::endl;
void checkIfComponentsAreVectors(itk::ImageIOBase::Pointer imageIO, const arguments &args)
itk::SmartPointer< ImageType > reorientImage(typename itk::SmartPointer< ImageType > input, itk::SpatialOrientation::ValidCoordinateOrientationFlags orientation)
void SetGradientFileName(std::string fName)
itk::ImageIOBase::Pointer imageIO
void reorientGradients(typename itk::SmartPointer< ImageType > input, std::vector< GradientType > &gradients)
#define ANIMA_RETRIEVE_COMPONENT_TYPE(imageIO, function,...)
void convert(const arguments &args)
#define ANIMA_RETRIEVE_NUMBER_OF_DIMENSIONS(imageIO, ComponentType, function,...)
std::string gradientFileName
void retrieveNbDimensions(itk::ImageIOBase::Pointer imageIO, const arguments &args)
#define ANIMA_CHECK_IF_COMPONENTS_ARE_VECTORS(imageIO, ComponentType, Dimension, function,...)
int main(int ac, const char **av)