I have an integer numpy array representing image with few values (about 2-5). And I would like to save it to png file with custom color for every value. I was trying it like this:
import numpy as np
from PIL import Image
array = np.zeros([100, 200, 4], dtype=np.uint8)
array[:,:100] = [255, 128, 0, 255] #Orange left side
array[:,100:] = [0, 0, 255, 255] #Blue right side
img = Image.fromarray(array)
img.save(r'D:\test.png')
The result is ok, but it has 4 channels. I need the result to be single channel with custom colors.
I was trying it this way:
array = np.zeros([100, 200], dtype=np.uint8)
array[:,:100] = 1
array[:,100:] = 0
the result is single channel, but it is of course graysale. I can't figure out how to assign color to values 1 and 0 and save it as single channel. Was trying play around with matplotlib colormaps, but with no success.
Any help will be very appreciated