How to save/convert and read image in python with defined values for colors -
i'm saving, converting grayscale, , opening image in python pil this
image.open(imgname).convert('l').save(imgname) and matrix 1 number per pixel. image has 3 colors. 255 white, 0 black , 128 gray.
is there anyway when convert image grayscale can have 0 white, 1 gray , 2 black when read image?
you make custom lut (lookup table) , apply grayscale image point() method before saving it. gray levels in image besides 0, 128, , 255 remain unchanged. could, of course, change initializing table differently.
lut = range(256) # initialize identity lut lut[0] = 2 lut[128] = 1 lut[255] = 0 image.open(imgname).convert('l').point(lut).save(imgname)
Comments
Post a Comment