[Insight-users] Determine if BMP is color or grayscale

Sébastien Fricker sebastien.fricker at phaseview.net
Thu Oct 25 03:34:22 EDT 2007


Dear ITK users,

Since I didn’t get any answer, let me try to explain my problem differently:

In my project, I open 2 types of BMP images:

-          8 bits grayscale images

-          24 bits RGB images

 

When I use an imageIO to read the file headers, I obtain the following (for
both types of images):

 

imageIO->GetPixelType() returns SCALAR

imageIO->GetComponentType returns UCHAR

imageIO-GetNumberOfComponents returns 3

 

Instead, I would expect:

 

For 8 bits grayscale:

Pixel type = SCALAR

Component type = UCHAR

Number of components = 1

 

For 24 bits RGB:

Pixel type = RGB

Component type = UCHAR

Number of components = 3

 

Is this a bug or am I missing something? For example the user manual says
that if pixel type is SCALAR, then number of components should always be 1,
which is not the case here


 

Thank you,

 

Sebastien Fricker

  _____  

From: insight-users-bounces+sebastien.fricker=phaseview.net at itk.org
[mailto:insight-users-bounces+sebastien.fricker=phaseview.net at itk.org] On
Behalf Of Sébastien Fricker
Sent: mardi 23 octobre 2007 08:54
To: 'insight-users'
Subject: [Insight-users] Determine if BMP is color or grayscale

 

Dear ITK users,

 

How can I determine if a BMP image is 8 bits grayscale or 24 bits RGB?

I was able to use an ImageIO to read image information, but I can’t seem to
access the bit depth information (m_Depth being private).

 

I would like to write an application that can open and process grayscale or
color images, then save the output as grayscale or color.

Color images are processed differently (they are treated as vector images)
so I need to differentiate them.

 

Here is a sample of my code:

 

itk::ImageIOBase::Pointer imageIO = itk::ImageIOFactory::CreateImageIO(
fileName.c_str(), itk::ImageIOFactory::ReadMode );

imageIO->SetFileName( fileName );

imageIO->ReadImageInformation();

 

 

 

imageIO->GetComponentType() returns UCHAR in both cases.

imageIO->GetNumberOfComponents() returns 3 in both cases.

 

Thanks for your help,

Sébastien Fricker

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20071025/c47b7b86/attachment.html


More information about the Insight-users mailing list