[Insight-users] Reading bmp image with ITK

Luis Ibanez luis.ibanez at kitware.com
Mon Nov 1 10:33:20 EST 2004


Hi Jimmy,

If you want to rank these three file formats by
they suitability for storing Medical Images,
here is a tentative list:

       BMP  is poor
       JPEG is poorer
       RAW  is the poorest

All of them lack fields for patient information,
spacing (BMP has a bit of spacing in the form of
#pixels per centimeter), origin, orientation.

JPEG is poorer because it uses lossy compression.
The JPEG compression algorithm was not designed
for medical images but for picture scenes, for
example the photos of a Birthday party or the
picture of a dog sitting in the backyard.  :-)

JPEG is not what you want to use if your image
actually contain a tumor. It is particularly bad
for segmentation because the compression is done
in blocks of 8x8 pixels, therefore the consistency
of intensities across those blocks is compromised.

RAW is plain *dangerous* it doesn't contain any
information about the pixel type being used, the
image dimensions, the endianess, the pixel spacing,
the origin.  In practice, RAW is useless if you don't
have an accompanying header that tells you the
characteristics of the image.


If you are storing real patient data you may want
to use Analyze, GIPL or MetaImage, or to stick to
the original DICOM files that are produced from
CT and MRI scanners.


-------------------

About your code:

It seems to be fine for reading a BMP image
and writing it down.

Did you find any problem while running this code ?



    Regards,


       Luis



PS: Note that a bug was recently fixed in the BMP
reader/writer. This bug manifested in problems when
reading or writing images whose row size was not a
multiple of 4.  If you are using BMP images you may
want to use a recent CVS checkout of the toolkit.


--------------------
Jimmy Wong wrote:

> Thank you for your reply.
> 
> If bmp is poor, which one is better? raw or jpg?
> 
> I've read the manual, but very confuse of it.
> 
> Here is my main function
> 
> **********************************************
> void main()
> {
>     // Definition of stuctures
>     typedef unsigned char    PixelType;
>     const    unsigned int    Dimension = 2;
>     typedef itk::Image< PixelType, Dimension >    ImageType;
> 
>     typedef itk::ImageFileReader< ImageType >    ReaderType;
>     typedef itk::ImageFileWriter< ImageType >    WriterType;
> 
>     // Create a object of reader and read the image
>     ReaderType::Pointer reader = ReaderType::New();
>     WriterType::Pointer writer = WriterType::New();
> 
>     const char pInputfileName[] = "Input.bmp";
>     const char pOutputfileName[] = "Output.bmp";
> 
>     reader->SetFileName( pInputfileName );
>     reader->Update();
> 
>     ImageType::Pointer image = reader->GetOutput();
> 
> 
>     writer->SetFileName( pOutputfileName );
> 
>     writer->SetInput( reader->GetOutput() );
> 
>     try
>    {
>         writer->Update();
>    }
> 
>     catch( itk::ExceptionObject & err )
>    {
>         std::cout << "ExceptionObject caught !" << std::endl;
>         std::cout << err << std::endl;
>         exit(-1);
>    }
> }
> ******************************************************
> 
> Is it correct for reading image?
> 
> Thank you again.
> 
> Zhimin
> 
> 
> 
> 






More information about the Insight-users mailing list