Reputation: 2310
Suppose I want to read an indexed image as it is( not the 3 channel 24 bit images) I wish to read and modify the color palette of an indexed image. In opencv I haven't come across any such functions which extract the color palette of an image! Also I would like to know the datatype of the palette. i am coding in c using opencv Any help?
Upvotes: 3
Views: 3117
Reputation: 7545
Thanks for the image link. First, OpenCV doesn't support GIF (as Ameya005 linked). However there are other indexed palette image formats. It couldn't get an indexed palette image in OpenCV so unless I have missed something, I don't think you are going to be able to work with indexed palettes directly in OpenCV. It sounds like you need an alternative solution. Why do you need to work directly with the indexed palettes?
The second option below though would probably let you have the indexes in OpenCV (the palette would be lost) if that's all you need.
Here is what I've tried:
Load a paletted PNG (gets converted to 3-channel color)
import cv2
im = cv2.imread("mandril_color.png")
im.shape # returns (512, 512, 3) so it's been converted to 3-channel color
Load a paletted GIF (gets converted to grayscale)
I guess this is converting to grayscale with the index used as intensity, but I haven't verified it.
import cv2
import Image
import numpy as np
im_pil = Image.open("mandril_color.gif")
im_cv = np.asarray(im_pil)
im_cv.shape # returns (512, 512) so it's become grayscale
Create a paletted image from scratch in OpenCV
I haven't found any way to do this.
Upvotes: 2
Reputation: 31
Well, I don't think OpenCV has any function to do this. The cvLoadImage() or imread() functions use libpng for codecs to directly read images.
Check the documentation for further information
Upvotes: 1