[Insight-users] Cannot read a RGBA png file into itk::Image<unsigned char, 2> properly

Aurelien Bricier aurelien.bricier at c-s.fr
Tue Jun 22 07:39:31 EDT 2010


Hello ITK users,

I tried to read a 4 channels (RGBA) png image file into an
itk:Image<unsigned char, 2> and the output image makes no sense. It
appears that it works fine with RGB png images. In fact, I located the
issue in ConvertPixelBuffer::ConvertRGBAToGray() that computes the
grayscale pixel value by applying the following formula:

((2125.0 * static_cast<double>RedPixelValue +
   7154.0 * static_cast<double>GreenPixelValue +
   0721.0 * static_cast<double>BluePixelValue)/1000.0)        //OK
      * static_cast<double>AlphaPixelValue
//Here is the issue

In a RGBA png image, the range of AlphaPixelValue is [0,255]. The
resulting grayscale value is no longer reasonably allowed to be casted
into an unsigned char. That's why the reader output doesn't make any
sense. I isolated this behavior in the attachment. Is there another
place where I should report this bug?

Regards,
Aurelien.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: PngReadWriteBug.tar.gz
Type: application/gzip
Size: 43437 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20100622/45d4fb2a/attachment-0001.bin>


More information about the Insight-users mailing list