I would like to convert indexed color image array to RGB color-space. I know I can achieve that if I have PIL read image like following.
with Image.open(png_image_path) as img:
rgb_image = np.asarray(img.convert('RGB'))
I wanna do the same thing from numpy array rather than the image object read by PIL like following.
image = Image.fromarray(indexed_image).convert('RGB')
But it doesn't simply work the way I want. Any suggestion will be helpful to me! Thank you for taking your time.
You can do this:
scr = numpy.frombuffer(screen_buffer, dtype=numpy.uint8)
pal = numpy.frombuffer(palette_buffer, dtype=numpy.uint8).reshape((256, 3))
# Convert indexed color to RGB
arr = pal[scr]
data = arr.astype(numpy.uint8).tobytes()
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.