[Insight-developers] GDCM: How to find out the correct pixel type
Mathieu Malaterre
mathieu.malaterre at gmail.com
Mon Dec 10 08:24:04 EST 2007
Hi everyone,
I have finally implemented a fix for the issue with the slicer
plugin that would instanciate a INT or UINT itk::ImageFileReader where
a SHORT or USHORT would suffice. The fix was rather trivial
$ cvs ci -m"ENH: Fix feature request: 0006138: Finding proper pixel
type for DICOM is cumbersome" itkGDCMImageIO.cxx
/cvsroot/Insight/Insight/Code/IO/itkGDCMImageIO.cxx,v <-- itkGDCMImageIO.cxx
new revision: 1.128; previous revision: 1.127
At the same time I added a small example that would dump the
component type / pixel type needed to properly instanciate the
itk::ImageFileReader so that also ITK user can take advantage of it.
This should hopefully solve the issue where a user would not be aware
of the DICOM specification for storing pixel data:
$ cvs ci -m"ENH: Adding a piece of code to dump the correct pixel type
to instanciate the itk::ImageFileReader" DicomImageReadPrintTags.cxx
/cvsroot/Insight/Insight/Examples/IO/DicomImageReadPrintTags.cxx,v
<-- DicomImageReadPrintTags.cxx
new revision: 1.18; previous revision: 1.17
So the problem here is that a piece code and a particular dataset in
Slicer would instanciated a INT itk::ImageFileReader, whereas now it
will instanciate a SHORT itk::ImageFileReader. Does this violate the
backwarc compatible policy ?
Thanks,
-Mathieu
On Nov 22, 2007 3:49 PM, Bill Lorensen <bill.lorensen at gmail.com> wrote:
> Mathieu,
>
> Here is some code we use in Slicer3 plugins to determine pixel and component
> type at run-time:
>
> namespace itk
> {
> // Description:
> // Get the PixelType and ComponentType from fileName
> void GetImageType (std::string fileName,
> ImageIOBase::IOPixelType &pixelType,
> ImageIOBase::IOComponentType &componentType)
> {
> typedef itk::Image<unsigned char, 3> ImageType;
> itk::ImageFileReader<ImageType>::Pointer imageReader =
> itk::ImageFileReader<ImageType>::New();
> imageReader->SetFileName(fileName.c_str());
> imageReader->UpdateOutputInformation();
>
> pixelType = imageReader->GetImageIO()->GetPixelType();
> componentType = imageReader->GetImageIO()->GetComponentType();
> }
>
> // Description:
> // Get the PixelTypes and ComponentTypes from fileNames
> void GetImageTypes (std::vector<std::string> fileNames,
> std::vector<ImageIOBase::IOPixelType> &pixelTypes,
> std::vector<ImageIOBase::IOComponentType>
> &componentTypes)
> {
> pixelTypes.clear();
> componentTypes.clear();
>
> // For each file, find the pixel and component type
> for (std::vector<std::string>::size_type i = 0; i < fileNames.size();
> i++)
> {
> ImageIOBase::IOPixelType pixelType;
> ImageIOBase::IOComponentType componentType;
>
> GetImageType (fileNames[i],
> pixelType,
> componentType);
> pixelTypes.push_back(pixelType);
> componentTypes.push_back(componentType);
> }
> }
> }
>
> Bill
>
--
Mathieu
More information about the Insight-developers
mailing list