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

David Doria daviddoria at gmail.com
Mon Dec 3 12:49:03 EST 2012


On Mon, Dec 3, 2012 at 12:24 PM, Bill Lorensen <bill.lorensen at gmail.com>
wrote:
>
> David,
>
> Is this using itkv4. Looks like it was fixed tor itkv4  but I have not
> tested it yet.
>
> Bill

Ok, I guess it is not the exact same problem, but it seems very similar. If
I read a 4 channel (RGBA) png into an Image<unsigned char, 2> and write it
out again, I get a 1 channel image that looks just like the original image
(the original image was binary (only had values (255 0 0 0) and (0 0 0 0))).

However, I read a 2 channel png (gray, alpha) into an Image<unsigned char,
2> and write it out again, the result is a black image.

Using the attached GrayAlpha.png as input and running the following will
produce the all black GrayAlphaOutput.png (also attached).

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"

int main(int argc, char *argv[])
{
  if(argc < 3)
  {
    std::cerr << "Required: input output" << std::endl;

    return EXIT_FAILURE;
  }

  std::string inputFilename = argv[1];
  std::string outputFilename = argv[2];

  typedef itk::Image< unsigned char, 2 >  ImageType;

  typedef itk::ImageFileReader<ImageType> ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(inputFilename);
  reader->Update();

  typedef itk::ImageFileWriter<ImageType> WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFilename);
  writer->SetInput(reader->GetOutput());
  writer->Update();
}


David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20121203/91589c70/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GrayAlpha.png
Type: image/png
Size: 2001 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20121203/91589c70/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GrayAlphaOutput.png
Type: image/png
Size: 2303 bytes
Desc: not available
URL: <http://www.itk.org/pipermail/insight-users/attachments/20121203/91589c70/attachment-0001.png>


More information about the Insight-users mailing list