[Insight-users] Getting RGBPixel value with ImageRegionIteratorWithIndex

Luis Ibanez luis.ibanez at kitware.com
Wed Dec 21 21:22:56 EST 2005


HI Olivier,

Please read the ITK Software Guide


     http://www.itk.orgl/ItkSoftwareGuide.pdf


In particular,

      Section 4.1.5, "RGB Images", in pdf-page 75,

and

      Section 11.3 "Image Iterators", in pdf-page 738.


When you iterate over the pixel you can simply do:


     RGBPixelType p = itr.Get();
     double r = p.GetRed();
     double g = p.GetGreen();
     double b = p.GetBlue();



Note that you can also use ImageAdaptors in order
to extract one of the components of the RGB image.

Please see Section 12.2 "Adapting RGB images", in
pdf-page 780.


In order to change the values you could do something
like:



   while( !inputIterator.IsAtEnd() )
     {
     RGBPixelType v = inputIterator.Get();

     v.SetRed(   v.GetRed()     + 5 );
     v.SetGreen( v.GetGreen()   + 5 );
     v.SetBlue(  v.GetBlue()    + 5 );

     outputIterator.Set( v );

     ++intputIterator;
     ++outputIterator;
     }




    Regards,


       Luis



-----------------------
Olivier Rousseau wrote:
> Hi,
> 
> I have a simple question, but I couldn't find the answer. I have a
> ImageRegionIteratorWithIndex that iterates over a RGB Image.
> How can I extract (and change) the Red values (or Green, or Blue)
> of the Pixel?
> 
> Thanks!
> Olivier
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> 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