[Insight-users] Reading bmp image with ITK

Luis Ibanez luis.ibanez at kitware.com
Mon Nov 1 08:31:46 EST 2004



Hi Jimmy,


Reading BMP, JPG, TIFF, PNG, Analyze, VTK,
         GIPL and MetaImages is trivial in ITK.


You simply use the default itk::ImageFileReader<> class.


Like the following code
========================================================
   typedef itk::Image< char, 2 >   ImageType;
   typedef itk::ImageFileReader< ImageType > ReaderType;
   ReaderType::Pointer reader = ReaderType::New();

   reader->SetFileName("myImage.bmp");

   try
      {
      reader->Update();
      }
   catch( itk::ExceptionObject & excp )
      {
      std::cerr << "error " << excp << std::endl;
      return;
      }

   ImageType::ConstPointer image = reader->GetOutput();

==========================================================


You will find indeed *many* examples of this code in the
ITK Software Guide

          http://www.itk.org/ItkSoftwareGuide.pdf


In particular in the "Reading and Writing" images chapter
and in the "Filtering" chapter.

Almost all the examples in


        Insight/Examples/
                   Registration/
                   Segmentation/
                   Filtering/


use similar code for reading the input images.

You will also find this described in detail in the
Tutorial sessions:


          http://www.itk.org/HTML/Tutorials.htm


In particular in the first session "Getting Started I"

http://www.itk.org/CourseWare/Training/GettingStartedI-WebPage/index.htm



For examples on how to display the images using ITK+VTK
please look at the code in the following files


      InsightApplications/Auxiliary/vtk/
                  itkReadITKImageShowVTK.cxx
                  itkReadITKImageSegmentShowVTK.cxx

The first one reads an image using the ImageFileReader code shown
above, converts the itk::Image to a vtkImageData and then use a
minimal VTK pipeline for rendering the image.

The second if similar to the first example, but in addition it
performs a segmentation on the input image uses VTK for displaying
the result of the segmentation as a contour ovelaid on top of the
input image.




BTW, note that BMP is a very poor format for storing medical images.
It doesn't have a precise mechanism for indicating the pixel spacing,
and the origin of the images. If you have the choice, you may want to
avoid using BMP files for storing real patient data.



Please let us know if you have further questions,


      Thanks


       Luis



===================
Jimmy Wong wrote:

> Dear ITK users,
> 
> I am doing segmentation, and would like to read gray level image such as 
> *.bmp, *.jpg, and so on.
> However, it seems there is not any good example for this type of operation.
> 
> Can anyone tell me how to read *.bmp image with ITK functions? If 
> possible, teach me how to display *.bmp image using VTK?
> 
> Thank you.
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 
> 






More information about the Insight-users mailing list