24 #include <itkImageFileReader.h>
25 #include <itksys/Directory.hxx>
26 #include <itksys/SystemTools.hxx>
28 #include <itkImageFileReader.h>
29 #include <itkImageIOFactory.h>
30 #include <itkImageIORegion.h>
31 #include <itkMetaDataObject.h>
44 const unsigned int MINDIM = 2;
45 const unsigned int MAXDIM = 4;
47 MITK_INFO(
"mitkItkImageFileReader") <<
"loading " <<
m_FileName <<
" via itk::ImageIOFactory... " << std::endl;
52 mitkThrow() <<
"Empty filename in mitk::ItkImageFileReader ";
57 itk::ImageIOFactory::CreateImageIO(
m_FileName.c_str(), itk::ImageIOFactory::ReadMode);
68 imageIO->ReadImageInformation();
70 unsigned int ndim = imageIO->GetNumberOfDimensions();
71 if (ndim < MINDIM || ndim > MAXDIM)
73 itkWarningMacro(<<
"Sorry, only dimensions 2, 3 and 4 are supported. The given file has " << ndim
74 <<
" dimensions! Reading as 4D.");
78 itk::ImageIORegion ioRegion(ndim);
79 itk::ImageIORegion::SizeType ioSize = ioRegion.GetSize();
80 itk::ImageIORegion::IndexType ioStart = ioRegion.GetIndex();
82 unsigned int dimensions[MAXDIM];
98 for (i = 0; i < ndim; ++i)
101 ioSize[i] = imageIO->GetDimensions(i);
104 dimensions[i] = imageIO->GetDimensions(i);
105 spacing[i] = imageIO->GetSpacing(i);
111 origin[i] = imageIO->GetOrigin(i);
115 ioRegion.SetSize(ioSize);
116 ioRegion.SetIndex(ioStart);
118 MITK_INFO(
"mitkItkImageFileReader") <<
"ioRegion: " << ioRegion << std::endl;
119 imageIO->SetIORegion(ioRegion);
120 void *buffer =
new unsigned char[imageIO->GetImageSizeInBytes()];
121 imageIO->Read(buffer);
128 matrix.SetIdentity();
129 unsigned int j, itkDimMax3 = (ndim >= 3 ? 3 : ndim);
130 for (i = 0; i < itkDimMax3; ++i)
131 for (j = 0; j < itkDimMax3; ++j)
132 matrix[i][j] = imageIO->GetDirection(j)[i];
149 timeGeometry->Initialize(slicedGeometry, image->GetDimension(3));
150 image->SetTimeGeometry(timeGeometry);
153 MITK_INFO(
"mitkItkImageFileReader") <<
"number of image components: " << image->GetPixelType().GetNumberOfComponents()
163 MITK_INFO(
"mitkItkImageFileReader") <<
"...finished!" << std::endl;
167 const std::string filePrefix,
168 const std::string filePattern)
175 if (filePattern !=
"" && filePrefix !=
"")
179 itk::ImageIOFactory::CreateImageIO(filename.c_str(), itk::ImageIOFactory::ReadMode);
180 if (imageIO.IsNull())
185 imageIO->SetFileName(filename.c_str());
186 imageIO->ReadImageInformation();
187 itk::MetaDataDictionary imgMetaDictionary = imageIO->GetMetaDataDictionary();
188 std::vector<std::string> imgMetaKeys = imgMetaDictionary.GetKeys();
189 std::vector<std::string>::const_iterator itKey = imgMetaKeys.begin();
190 std::string metaString;
192 for (; itKey != imgMetaKeys.end(); itKey++)
194 itk::ExposeMetaData<std::string>(imgMetaDictionary, *itKey, metaString);
195 if (itKey->find(
"modality") != std::string::npos)
197 if (metaString.find(
"DWMRI") != std::string::npos)
206 MITK_INFO(
"mitkItkImageFileReader") <<
"Could not read ImageInformation ";
itk::SmartPointer< Self > Pointer
void SetSpacing(const mitk::Vector3D &aSpacing, bool enforceSetSpacing=false)
Set the spacing (m_Spacing).
virtual void InitializeEvenlySpaced(mitk::PlaneGeometry *geometry2D, unsigned int slices)
Completely initialize this instance as evenly-spaced with slices parallel to the provided PlaneGeomet...
MITKCORE_EXPORT mitk::PixelType MakePixelType(vtkImageData *vtkimagedata)
deduct the PixelType for a given vtk image
Convenience class to temporarily change the current locale.
static const std::string filename
void SetOrigin(const Point3D &origin)
Set the origin, i.e. the upper-left corner of the plane.
Point3D GetCornerPoint(int id) const
Get the position of the corner number id (in world coordinates)
Describes the geometry of a data object consisting of slices.
OutputType * GetOutput()
Get the output data of this image source object.
Describes a two-dimensional, rectangular plane.
virtual void GenerateData() override
A version of GenerateData() specific for image processing filters.
static bool CanReadFile(const std::string filename, const std::string filePrefix, const std::string filePattern)
mitk::AffineTransform3D * GetIndexToWorldTransform()
Get the transformation used to convert from index to world coordinates.