[Insight-users] Reading an mhd file with unknown pixel type

Sergio Vera sergio.vera at alma3d.com
Wed Dec 1 09:20:29 EST 2010


>
> David
> Based on some message on this mailing list that now I'm unable to find, we
> use something like this.
> I suppose it can be improved, but the code accomplishes the task of
> determining the type of data before actually reading the data.
>
> HTH
>
> ...
> typedef itk::ImageIOBase::IOComponentType ScalarPixelType;
>
>  itk::ImageIOBase::Pointer imageIO =
> itk::ImageIOFactory::CreateImageIO(
> params::filenameIn, itk::ImageIOFactory::ReadMode);
>
> if (!imageIO) {
> std::cerr << "Unable to create a valid ImageIO for image " <<
> params::filenameIn << ". Exiting." << std::endl;
> return -1;
> }
>
> // Now that we found the appropriate ImageIO class, ask it to
> // read the meta data from the image file.
> //
>   imageIO->SetFileName(params::filenameIn);
>   imageIO->ReadImageInformation();
> const ScalarPixelType pixelType = imageIO->GetComponentType();
> if (params::verbose)
> std::cout << "Pixel Type is " <<
> imageIO->GetComponentTypeAsString(pixelType)
> << std::endl;
> const size_t numDimensions =  imageIO->GetNumberOfDimensions();
> if (numDimensions != 3) {
> std::cerr << "This soft only soports 3D volumes. Exiting"
> << std::endl;
> return -1;
> }
>
>   switch (pixelType) {
> case itk::ImageIOBase::UCHAR:  DoTheRealThing<UC1d3ITKImgType>(); break; //UC1d3ITKImgType
> = unsigned char image of 1 channel, 3 dimensions
> case itk::ImageIOBase::SHORT:  DoTheRealThing<S1d3ITKImgType>();  break;
> //S1d3 = Short, one chanel, 3dimensions
> case itk::ImageIOBase::USHORT: DoTheRealThing<US1d3ITKImgType>(); break;
> case itk::ImageIOBase::FLOAT:  DoTheRealThing<F1d3ITKImgType>();  break;
> default:
> std::cerr << "Pixel Type ("
> << imageIO->GetComponentTypeAsString(pixelType)
> << ") not supported. Exiting." << std::endl;
> return -1;
>   }
> return 0;
>
> template<typename TITKImgType>
> void
> DoTheRealThing()
> {
>   // Read image with standard itkReadImageFilter as now, we know the type
> of image via template TITKImgType
> }
>
> On Wed, Dec 1, 2010 at 2:37 PM, David Doria <daviddoria at gmail.com> wrote:
>
>> Recently mhd has been my goto file format for writing non-standard-RGB
>> type images. For example, I may write a
>>
>> itk::Image<float, 4>
>>
>> or a
>>
>> itk::Image<float, 5>
>>
>> To successfully read these files, I need to know ahead of time what
>> type of pixel they contain so I can do:
>>
>> typedef itk::ImageFileReader<itk::Image<float, 5> > ReaderType;
>>
>> Is there a better way to read these files where the reader will adapt
>> and give me back an image of the correct type without me having to
>> specify the type before hand?
>>
>> Thanks,
>>
>> David
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.html
>>
>> Please keep messages on-topic and check the ITK FAQ at:
>> http://www.itk.org/Wiki/ITK_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.itk.org/mailman/listinfo/insight-users
>>
>
>
>
> --
> Sergio Vera
>
>  Alma IT Systems
>  C/ Vilana, 4B, 4º 1ª
>  08022 Barcelona
>  T. (+34) 932 380 592
>  www.alma3d.com
>



-- 
Sergio Vera

 Alma IT Systems
 C/ Vilana, 4B, 4º 1ª
 08022 Barcelona
 T. (+34) 932 380 592
 www.alma3d.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20101201/27bbb9d2/attachment.htm>


More information about the Insight-users mailing list