[Insight-users] Problem in setting pixel values for RGB Image

C.Cagatay Bilgin bilgic at cs.rpi.edu
Wed Nov 18 20:19:37 EST 2009


Hi Harish,
you want something like:

RGBImageType::PixelType pixelValue;
pixelValue[0] = 255;
pixelValue[1] = 0;
pixelValue[2] = 0;
it3.Set(pixelValue);

Regards,
C.Cagatay Bilgin

>
>
> Hi all,
>
> I have created a RGBImage and copied a gray scale image to it. Now I  
> would like to set some pixel values in RGBImage to some colors lets  
> say red, green, etc.
>
> My code is like this
>
>   /* For RGB Pixels */
>   RGBImageType::Pointer rgbImage = RGBImageType::New();
>   rgbImage->SetRegions( image1->GetRequestedRegion() );
>   rgbImage->CopyInformation( image1 );
>   rgbImage->Allocate();
>   /* Iterate through the images */
>   /* Here image1 and image2 are gray scale MRI images */
>   IteratorType it1( image1, image1->GetRequestedRegion());
>   IteratorType it2( image2, image2->GetRequestedRegion());
>   RGBIteratorType it3( rgbImage, rgbImage->GetRequestedRegion());
>
>   for ( it1.GoToBegin(), it2.GoToBegin(), it3.GoToBegin(); ! 
> it1.IsAtEnd() && !it2.IsAtEnd();
>     ++it1, ++it2, ++it3)
>   {
>    /* Find x and y */
>    float x,y;
>    x = it1.Get();
>    y = it2.Get();
>    int val = func(x,y);
>    if(val == 0)
>       it3.Set(RED_COLOR);
>    else
>       it3.Set(GREEN_COLOR);
>   }
>
>
> What should RED_COLOR and GREEN_COLOR be replaced with??
>
> Thanks,
> Harish
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.html
>
> Please keep messages on-topic and check the ITK FAQ at:
> http://www.itk.org/Wiki/ITK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20091118/41fb37e6/attachment-0001.htm>


More information about the Insight-users mailing list