I have a question about what to do when I read an index mode image in Python's image processing library PIL.
Read the png (index mode) image and change the pixel value as shown in the code below. Attempted to save in index mode again.
However, the output image was not colored and was black and white.
The color information is missing, but I don't know what's wrong.
Does anyone know?
I look forward to hearing from you.
Thank you for your cooperation.
from PIL import Image import numpy as np import sys origin=(0,1,4,4,5) to=(2,4,3,4,2) for ID in open(sys.argv): ID = ID.strip() im = Image.open (ID + '.png') imnp=np.array(im) for(i,j)in zip(origin,to): imnp[imnp==i] = j pil_img=Image.fromarray(np.uint8(imnp), mode="P") pil_img.save(ID+'_con.png', 'png')
Quote the answers to the similar question from an external site.
You will need to specify a palette to save in index color.
If you want to divert the palette of the original image, before saving it,
I think it would be good to add .
This post was posted as a similar question from an external site as community wiki.This post was posted as Community Wiki by quoting a similar question from an external site
371 Update Flask User Information
356 Unity Virtual Stick Does Not Return to Center When You Release Your Finger
356 I want to create an array of sequences from "1" to a specified number.
339 Scrap text information after the "View More" button when searching in the Yahoo! News search window
345 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2023 OneMinuteCode. All rights reserved.