简体   繁体   中英

Access the color palette of an indexed image in C

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?

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

http://opencv.itseez.com/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=imread#imread

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM