[Insight-users] Tif RGB wrong way around?

Julien Jomier jjomier at cs.unc.edu
Thu Jul 22 11:52:52 EDT 2004


Bill, John,

I just checked in a fix for itkBMPImageIO. As Bill said, reading and writing
RGB images were done in the wrong order.

Julien

> -----Original Message-----
> From: insight-users-bounces at itk.org 
> [mailto:insight-users-bounces at itk.org] On Behalf Of Lorensen, 
> William E (Research)
> Sent: Wednesday, July 21, 2004 10:18 AM
> To: 'John Biddiscombe'; Julien Jomier; insight-users at itk.org
> Subject: RE: [Insight-users] Tif RGB wrong way around?
> 
> 
> BMP is definitely writing the bytes out in the incorrect 
> order. I'm fixing
> it now...
> 
> -----Original Message-----
> From: John Biddiscombe [mailto:jbiddiscombe at skippingmouse.co.uk]
> Sent: Wednesday, July 21, 2004 8:43 AM
> To: Lorensen, William E (Research); Julien Jomier; 
> insight-users at itk.org
> Subject: Re: [Insight-users] Tif RGB wrong way around?
> 
> 
> The tiff import is much improved, however the attached images are the
> original and the result of
> tiffimageio->bmpWriter
> 
> The RGB at least coming through OK, but the RGB are again 
> BGR. This can
> easily be rectified in itkTIFFImageIO by changing
>     red = *(source);
>     green = *(source+1);
>     blue = *(source+2);
> to
>     red = *(source+2);
>     green = *(source+1);
>     blue = *(source+0);
> though this may not be the correct fix and perhaps the 
> convertRGBAtoRGB
> should have a new one like convertABGRtoRGB since it seems 
> the RGBA are
> stored the other way around in the tiff stream (?)
> 
> anyway, the attached images could be made into a unit test 
> for RGB Import
> Export. The test image contains the characters R,G,B written 
> on the image
> colour planes and so its easy to see when they are messed up.
> 
> Test code
> 
> typedef itk::RGBPixel<unsigned char> RGBPixelType2D;
> typedef itk::Image< RGBPixelType2D, 2 > ImageRGB2DType;
> typedef itk::ImageFileReader< ImageRGB2DType > ReaderType;
> ReaderType::Pointer reader = ReaderType::New();
> //
> reader->SetFileName( filename );
> //
> try
> {
>   reader->Update();
> }
> catch( itk::ExceptionObject & err )
> {
>   std::cout << "ExceptionObject caught !" << std::endl;
>   std::cout << err << std::endl;
>   return NULL;
> }
> typedef itk::ImageFileWriter< ImageRGB2DType > WriterType;
> WriterType::Pointer writer = WriterType::New();
> //
> writer->SetFileName("D:/Test.bmp");
> writer->SetInput(reader->GetOutput());
> writer->Update();
> 
> JB
> 
> 
> ----- Original Message ----- 
> From: "Lorensen, William E (Research)" <lorensen at crd.ge.com>
> To: "'John Biddiscombe'" <jbiddiscombe at skippingmouse.co.uk>; 
> "Julien Jomier"
> <jjomier at cs.unc.edu>; <insight-users at itk.org>
> Sent: Monday, July 19, 2004 9:51 PM
> Subject: RE: [Insight-users] Tif RGB wrong way around?
> 
> 
> > We have found the problem. Nothing in the tiff stuff. It 
> was a problem (a
> > couple actually) in the ConvertBuffer code. There still are 
> some issues
> > regarding the handling of alpha channels, but I've checked 
> in the changes
> to
> > fix the color problems.
> >
> > Bill
> >
> > -----Original Message-----
> > From: John Biddiscombe [mailto:jbiddiscombe at skippingmouse.co.uk]
> > Sent: Friday, July 09, 2004 11:03 AM
> > To: John Biddiscombe; Julien Jomier; insight-users at itk.org
> > Subject: Re: [Insight-users] Tif RGB wrong way around?
> >
> >
> > After doing some digging I became convinced that there is 
> nothing wrong
> with
> > the itk->vtk RGB pixels and so I tried exporting my TIFF as 
> bmp using the
> > following code. The exported Bitmap has RGB components the wrong way
> around.
> >
> > I'm therefore reasonably confident that the TIFF reader is 
> messing about.
> >
> > I'll modify my local version to give what I hope will be the correct
> images
> > and post a patch should anyone else have trouble.
> >
> > JB
> >
> >
> > typedef itk::ImageFileReader< ImageTypeRGB2D > ReaderType;
> > ReaderType::Pointer reader = ReaderType::New();
> > //
> > reader->SetFileName( filename );
> > //
> > try
> > {
> > reader->Update();
> > }
> > catch( itk::ExceptionObject & err )
> > {
> > std::cout << "ExceptionObject caught !" << std::endl;
> > std::cout << err << std::endl;
> > return NULL;
> > }
> > typedef itk::ImageFileWriter< ImageTypeRGB2D > WriterType;
> > WriterType::Pointer writer = WriterType::New();
> > //
> > writer->SetFileName("D:/Test.bmp");
> > writer->SetInput(reader->GetOutput());
> > writer->Update();
> > return reader->GetOutput();
> >
> >
> > ----- Original Message ----- 
> > From: "John Biddiscombe" <jbiddiscombe at skippingmouse.co.uk>
> > To: "Julien Jomier" <jjomier at cs.unc.edu>; <insight-users at itk.org>
> > Sent: Thursday, July 08, 2004 6:59 PM
> > Subject: Re: [Insight-users] Tif RGB wrong way around?
> >
> >
> > > Thanks. I should have thought of trying that! I'll look 
> for a mistake in
> > my
> > > code somewhere.
> > >
> > > JB
> > >
> > > ----- Original Message ----- 
> > > From: "Julien Jomier" <jjomier at cs.unc.edu>
> > > To: "'John Biddiscombe'" <jbiddiscombe at skippingmouse.co.uk>;
> > > <insight-users at itk.org>
> > > Sent: Thursday, July 08, 2004 6:47 PM
> > > Subject: RE: [Insight-users] Tif RGB wrong way around?
> > >
> > >
> > > Hi John,
> > >
> > > I just tried to read a RGB tiff image and write it as 
> JPEG and BMP using
> > ITK
> > > and the resulting image appears to be valid so I guess 
> the channels are
> in
> > > the correct order when reading the file.
> > >
> > > Hope this helps,
> > >
> > > Julien
> > >
> > > > -----Original Message-----
> > > > From: insight-users-bounces at itk.org
> > > > [mailto:insight-users-bounces at itk.org] On Behalf Of 
> John Biddiscombe
> > > > Sent: Thursday, July 08, 2004 12:56 PM
> > > > To: insight-users at itk.org
> > > > Subject: [Insight-users] Tif RGB wrong way around?
> > > >
> > > >
> > > > I've connected itk::TiffImageIO to a vtk pipeline and 
> found that when
> > > > reading RGB colour images the data looks as though its GBR
> > > > instead of RGB.
> > > > Red and blue channels swapped. I notice that the Tif test in
> > > > testing/code/io
> > > > uses a black and white image with R=G=B channels so 
> this wouldn't be
> > > > spotted.
> > > >
> > > > Can anyone else easily check if TiffImageIO is getting R and
> > > > B the wrong way
> > > > around? It might be me passing the data into vtk, but 
> since I'm using
> > > > SetImportVoidPointer directly and not modifying the actual
> > > > pixels, it should
> > > > be the same as when it was read.
> > > >
> > > > thanks
> > > >
> > > > JB
> > > >
> > > > _______________________________________________
> > > > Insight-users mailing list
> > > > Insight-users at itk.org
> > > > http://www.itk.org/mailman/listinfo/insight-users
> > > >
> > >
> > > _______________________________________________
> > > Insight-users mailing list
> > > Insight-users at itk.org
> > > http://www.itk.org/mailman/listinfo/insight-users
> > >
> > > _______________________________________________
> > > Insight-users mailing list
> > > Insight-users at itk.org
> > > http://www.itk.org/mailman/listinfo/insight-users
> >
> > _______________________________________________
> > Insight-users mailing list
> > Insight-users at itk.org
> > http://www.itk.org/mailman/listinfo/insight-users
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 



More information about the Insight-users mailing list