[Insight-users] How to combine three color component data into a RGB image

Luis Ibanez luis.ibanez@kitware.com
Sun, 23 Feb 2003 04:28:37 -0500


Hi Fucang,

The functionality you need here will be a quite
common requirement when processing color images,
so we just added a new filter for providing an
easy way to combine scalar images into a single
RGB image.

You will find it under: Insight/Code/BasicFilters

           itkComposeRGBImageFilter

This filter accepts as input three scalar images,
each one containing one of the Red, Green and Blue
channels. The filter acts pixel-wise by combining
the input R,G,B values into a single RGBPixel data
type. The output is an image of RGBPixels whose
components have the same type as the pixel type of
he input scalar images.

The filter is implemented using the

         itk::TernaryFunctorImageFilter

Here is one of the multiple cases in which the effort
invested in Generic Programming pays off.  You will
notice that the filter only requires you to implement
the Functor object that defines the operation to be
performed pixel-by-pixel.  All the rest is managed
by the base templated class. The filter gets even
multithreading for free.

The full filter is implemented in a header file, you
can have access to it through

http://www.itk.org/cgi-bin/cvsweb.cgi/Insight/Code/BasicFilters/itkComposeRGBImageFilter.h?cvsroot=Insight&sortby=date

or simply by updating your cvs checkout.

An example on the use of the filter is available
under:

     Insight/Testing/Code/BasicFilters


              itkComposeRGBImageFilterTest.cxx


You can now take the outputs of your filter1, filter2 and filter3
objects and plug them as inputs of the CombineRGBImageFilter.
The output will be a RGB image.


Please let us know if you find any problems,


   Thanks


      Luis


-------------------------------------
Fucang Jia wrote:
> Hi everyone, hi Luis,
> 
> I use iterator to extract red, green, blue component from a color image, 
> after some operation on each component data, finally I want to combine 
> these three component data into a RGB color image again. But I do not 
> know how to do that? Could you help me? Thanks!
> 
> Here is the former code:
> 
> RGBImageType::Pointer image = reader->GetOutput();
> 
> // extract red channel component  
> itk::AdaptImageFilter<RGBImageType,GrayImageType,RedAccessorType>::Pointer 
> adaptImageToRed = 
> itk::AdaptImageFilter<RGBImageType,GrayImageType,RedAccessorType>::New();
> 
> adaptImageToRed->SetInput(image);
> adaptImageToRed->UpdateLargestPossibleRegion();
> myIteratorType 
> it1(adaptImageToRed->GetOutput(),adaptImageToRed->GetOutput()->GetRequestedRegion()); 
> 
> 
> 
> // extract green channel component
> itk::AdaptImageFilter<RGBImageType,GrayImageType,GreenAccessorType>::Pointer 
> adaptImageToGreen = 
> itk::AdaptImageFilter<RGBImageType,GrayImageType,GreenAccessorType>::New();
> 
> adaptImageToGreen->SetInput(image);
> adaptImageToGreen->UpdateLargestPossibleRegion();
> myIteratorType 
> it2(adaptImageToGreen->GetOutput(),adaptImageToGreen->GetOutput()->GetRequestedRegion()); 
> 
> 
> 
> // extract blue channel component
> itk::AdaptImageFilter<RGBImageType,GrayImageType,BlueAccessorType>::Pointer 
> adaptImageToBlue = 
> itk::AdaptImageFilter<RGBImageType,GrayImageType,BlueAccessorType>::New();
> 
> adaptImageToBlue->SetInput(image);
> adaptImageToBlue->UpdateLargestPossibleRegion();
> 
> myIteratorType 
> it3(adaptImageToBlue->GetOutput(),adaptImageToBlue->GetOutput()->GetRequestedRegion()); 
> 
> 
> // execute some operation on each color component
> filter1->SetInput(adaptImageToRed->GetOutput());
> filter2->SetInput(adaptImageToGreen->GetOutput());
> filter3->SetInptu(adaptImageToBlue->GetOutput());
> 
> // Some code needed to combine filter1->GetOutput(), 
> filter2->GetOutput(), filter3->GetOutput()  into one itk::Image data 
> colorimage, so that writer->SetInput(colorimage)
> 
> ???
> 
> Fucang
> 
> _________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE* 
> http://join.msn.com/?page=features/junkmail
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>