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

Bill Lorensen bill.lorensen at gmail.com
Mon Dec 3 12:57:17 EST 2012


The original poster's issue is fixed in itkv4. I just tried it.

Yours is a different problem that probably needs a similar fix. I'll
take a quick look if you make sure the jira issue addresses your
problem and not his.


On Mon, Dec 3, 2012 at 12:49 PM, David Doria <daviddoria at gmail.com> wrote:
> 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



-- 
Unpaid intern in BillsBasement at noware dot com


More information about the Insight-users mailing list