[Insight-developers] GDCM: How to find out the correct pixel type
Mathieu Malaterre
mathieu.malaterre at gmail.com
Thu Nov 22 10:00:21 EST 2007
Thanks Bill !
Exactly what I was looking for...unfortunately human is still better
at this game.
There is an issue in the itk::GDCMImageIO::IntervalCalculator class
when dealing with 12 Bits Stored Pixel. Technically we would need a
NumericTraits<12Bits>::max() + NumericTraits<12Bits>::min() to
actually compute that real world value can be loaded on signed short.
This is not really an issue since signed int will be plenty (as return
by the actual code), but it becomes nasty when you try to save that
image back as DICOM file...32bits are still not allowed in most
modality.
Anyone feeling like implementing traits for 12bits pixels :)
-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