Hi all,
I’m attempting to convert an RGB pixel type image to a RGBA pixel type image, as I would like to be able to overlay it on another image and therefore need it to be slightly transparent. I tried to cast using itk::CastImageFilter<RGBImageType, RGBAImageType>, but I received an ITK error: “Cannot set the size of a RGBAPixel to anything other than 4”. I also receive an error in my IDE from itkCastImageFilter.hxx that “Vector dimensions are required to match!”.
I searched around and found this post, but it pertains to a simpleITK treatment of the problem. Is there a similar way to do this using regular ITK?
Edit: I also found this example code which seems to be ideal for my purpose, but I don’t understand how to adapt it to convert from RGB to RGBA while keeping the RGB values from the original image.
It looks like you have to make a copy of your RGB image and convert that copy.
Mr. Chen,
Yes I agree, that does sound like what needs to be done. However, my issue is stemming from the conversion from RGB to RGBA. That converter is what is throwing the error. Do you know how to set up the converter to take an RGB image and return it as RGBA?
The best way to do this in ITK would be to create an RGBtoRGBAAdaptor
and use it in an ImageAdaptor.
Please refer to the ITK Software Guide’s Image Adaptor chapter for details.
Mr. Lowekamp,
Thanks! I’ll take a look at The Guide