I have an image on which the quantize() function (PIL) was used.
def dither(im):
colorPalette =((255, 255, 255),
(193, 193, 193),
(239, 19, 11),
(255, 113, 0),
(255, 228, 0),
(0, 204, 0),
(0, 178, 255),
(35, 31, 211),
(163, 0, 186),
(211, 124, 170),
(160, 82, 45),
(0, 0, 0),
(76, 76, 76),
(116, 11, 7),
(194, 56, 0),
(232, 162, 0),
(0, 85, 16),
(0, 86, 158),
(14, 8, 101),
(85, 0, 105),
(167, 85, 116),
(99, 48, 13))
im = im.convert('RGB')
colorPalette = list(sum(colorPalette, ()))*12
colorPalette = colorPalette[:768]
palimage = Image.new('P', (im.width, im.height))
palimage.putpalette(colorPalette)
ditheredim = im.quantize(palette=palimage)
return ditheredim
I now want to change the values to 0, 1, 2 ... 21 so it's easier to work with. Tried this:
width, height = im.size
im = np.array(im)
for x in range(width):
for y in range(height):
for i in range(len(colorPalette)):
if im[x][y] == all(colorPalette[i]):
im[x][y] = i
.. but it doesn't work.