15 #pragma warning ( disable : 4786 ) 19 #define ITK_LEAN_AND_MEAN 31 #include "itkImageFileReader.h" 32 #include "itkMetaDataDictionary.h" 33 #include "itkMetaDataObject.h" 34 #include <ImageInfoCLP.h> 66 std::cerr <<
"Only one operation allowed!" << std::endl;
74 if (x < LowerLimit || x > UpperLimit)
76 std::cerr <<
"Parameter out of range!" << std::endl;
85 std::ifstream myfile (file);
88 while ( getline (myfile,line) )
90 std::cout << line <<
'\n';
98 main(
int argc,
char *argv[])
109 if (_ImageDimensionArg.isSet())
115 if (_ImageSpacingArg.isSet())
120 if (_ComponentTypeArg.isSet())
122 if (_PixelTypeArg.isSet())
124 if (_NumberOfComponentsPerVoxelArg.isSet())
126 if (_ImageSizeInBytesArg.isSet())
128 if (_ImageSizeInComponentsArg.isSet())
130 if (_ImageSizeInPixelsArg.isSet())
132 if (_OriginArg.isSet())
134 if (_MetaDataArg.isSet())
136 if (_GradientsArg.isSet())
138 if (_DiffusionWeightingArg.isSet())
140 if (_DiffusionWeightingsArg.isSet())
144 typedef float PixelType;
145 static const unsigned int ImageDimension = 4;
146 typedef itk::VectorImage<PixelType, ImageDimension> MultiVolumeVectorImageType;
147 typedef itk::ImageFileReader<MultiVolumeVectorImageType> ReaderType;
149 MultiVolumeVectorImageType::Pointer inputImage;
150 ReaderType::Pointer reader = ReaderType::New();
153 reader->SetFileName(_InputFile);
154 reader->UpdateOutputInformation();
155 inputImage = reader->GetOutput();
156 itk::ImageIOBase::Pointer inputImageIOBase = reader->GetImageIO();
157 inputImageIOBase->ReadImageInformation();
159 itk::ImageIOBase::IOPixelType inputPixelType = inputImageIOBase->GetPixelType();
160 itk::ImageIOBase::IOComponentType inputComponentType =
161 inputImageIOBase->GetComponentType();
162 itk::ImageIOBase::SizeType inputImageSizeInBytes =
163 inputImageIOBase->GetImageSizeInBytes();
164 itk::ImageIOBase::SizeType inputImageSizeInComponents =
165 inputImageIOBase->GetImageSizeInComponents();
166 itk::ImageIOBase::SizeType inputImageSizeInPixels =
167 inputImageIOBase->GetImageSizeInPixels();
169 itk::ImageIOBase::ByteOrder inputByteOrder = inputImageIOBase->GetByteOrder();
172 std::string inputPixelTypeAsString(
173 inputImageIOBase->GetPixelTypeAsString(inputPixelType));
174 std::string inputComponentTypeAsString(
175 inputImageIOBase->GetComponentTypeAsString(inputComponentType));
176 std::string inputByteOrderAsString(inputImageIOBase->GetByteOrderAsString(inputByteOrder));
178 unsigned int inputNumberOfComponentsPerPixel =
179 inputImage->GetNumberOfComponentsPerPixel();
181 MultiVolumeVectorImageType::RegionType inputRegion =
182 inputImage->GetLargestPossibleRegion();
183 MultiVolumeVectorImageType::SizeType inputSize = inputRegion.GetSize();
184 MultiVolumeVectorImageType::SpacingType inputSpacing = inputImage->GetSpacing();
185 MultiVolumeVectorImageType::PointType inputOrigin = inputImage->GetOrigin();
186 MultiVolumeVectorImageType::DirectionType inputDirection = inputImage->GetDirection();
189 itk::MetaDataDictionary MetaDictionary = inputImage->GetMetaDataDictionary();
190 std::vector < std::string > MetaKeys = MetaDictionary.GetKeys();
191 std::vector<std::string>::const_iterator itKey;
192 std::string metaString;
197 std::cout.precision(10);
201 std::cout <<
"Dimension =" << std::flush;
202 for (
unsigned int k=0; k<ImageDimension; k++)
204 std::cout <<
" " << inputSize[k] << std::flush;
206 std::cout << std::endl;
208 std::cout <<
"Spacing =" << std::flush;
209 for (
unsigned int k=0; k<ImageDimension; k++)
211 std::cout <<
" " << inputSpacing[k] << std::flush;
213 std::cout << std::endl;
215 std::cout <<
"Origin =" << std::flush;
216 for (
unsigned int k=0; k<ImageDimension; k++)
218 std::cout <<
" " << inputOrigin[k] << std::flush;
220 std::cout << std::endl;
222 std::cout <<
"ComponentType = " << inputComponentTypeAsString
224 std::cout <<
"PixelType = " << inputPixelTypeAsString << std::endl;
225 std::cout <<
"NumberOfComponents = " << inputNumberOfComponentsPerPixel
227 std::cout <<
"ImageSizeInBytes = " << inputImageSizeInBytes << std::endl;
228 std::cout <<
"ImageSizeInComponents = " << inputImageSizeInComponents
230 std::cout <<
"ImageSizeInPixels = " << inputImageSizeInPixels << std::endl;
233 std::cout <<
"DirectionType = [" << std::flush;
234 for (
unsigned int r=0; r<ImageDimension; r++)
236 for (
unsigned int c=0; c<ImageDimension; c++)
238 std::cout << inputDirection(r,c) << std::flush;
239 if (c < ImageDimension - 1)
241 std::cout <<
" " << std::flush;
244 if (r < ImageDimension - 1)
246 std::cout <<
"; " << std::flush;
249 std::cout <<
"]" << std::endl;
253 std::cout << inputSize[_ImageDimension] << std::flush;
258 std::cout << inputSpacing[_ImageSpacing] << std::flush;
262 std::cout << inputComponentTypeAsString;
266 std::cout << inputPixelTypeAsString;
270 std::cout << inputNumberOfComponentsPerPixel;
274 std::cout << inputImageSizeInBytes;
278 std::cout << inputImageSizeInComponents;
282 std::cout << inputImageSizeInPixels;
286 std::cout << inputOrigin;
290 for (itKey = MetaKeys.begin(); itKey != MetaKeys.end(); ++itKey)
292 itk::ExposeMetaData < std::string
293 > (MetaDictionary, *itKey, metaString);
294 std::cout << *itKey <<
" ---> " << metaString << std::endl;
299 for (itKey = MetaKeys.begin(); itKey != MetaKeys.end(); ++itKey)
301 itk::ExposeMetaData < std::string> (MetaDictionary, *itKey, metaString);
302 if (itKey->find(
"DWMRI_gradient") != std::string::npos)
304 sscanf(metaString.c_str(),
"%lf %lf %lf\n", &x, &y, &z);
306 printf(
"%lf %lf %lf\n",x,y,z);
312 for (itKey = MetaKeys.begin(); itKey != MetaKeys.end(); ++itKey)
314 itk::ExposeMetaData < std::string
315 > (MetaDictionary, *itKey, metaString);
316 if (itKey->find(
"DWMRI_b-value") != std::string::npos)
318 b0 = atof(metaString.c_str());
326 for (itKey = MetaKeys.begin(); itKey != MetaKeys.end(); ++itKey)
328 itk::ExposeMetaData < std::string
329 > (MetaDictionary, *itKey, metaString);
330 if (itKey->find(
"DWMRI_b-value") != std::string::npos)
332 b0 = atof(metaString.c_str());
336 for (itKey = MetaKeys.begin(); itKey != MetaKeys.end(); ++itKey)
338 itk::ExposeMetaData < std::string
339 > (MetaDictionary, *itKey, metaString);
340 if (itKey->find(
"DWMRI_gradient") != std::string::npos)
342 sscanf(metaString.c_str(),
"%lf %lf %lf\n", &x, &y, &z);
344 printf(
"%lf\n", (x*x+y*y+z*z)*b0);
int GetImageType(const std::string &filename)
void IntRangeCheck(int x, int LowerLimit, int UpperLimit)
void SetOperationWithChecking(int &operation, int value)
int show_file(const std::string &file)
int main(int argc, char *argv[])