tengo un error que no sé como solucionar:
TypeError: 'Image' object does not support item assignment.
Lo que hago es convertir un punto rgb a cmyk -> punto a un cuadrícula de 3*3 (la imagen resultante será más grande), estos puntos de la cuadrícula serán magenta, cyan, yellow, black en proporción a la cantidad de color que haya dado la conversión. No soy programador profesional, solo un gran aficionado interesado en la programación. Así que posiblemente este programa se podría mejorar totalmente, cualquier sugerencia se agradece.
from PIL import Image
from PIL import ImageColor
import cv2
import numpy as np
imagen = Image.open("tintin.jpg")#primero pasamos a RGB
rgb_imagen = imagen.convert('RGB')
width, height = rgb_imagen.size
imagen2 = Image.new("RGB", (width*3, height*3), (255,255,255,255))
matriz = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]
m = np.array(matriz)
y=1
while ( y<(height-1) ):
x=1
while ( x<(width-2)):
r, g, b = rgb_imagen.getpixel((x, y))
k = 1.0000001-(max(r,g,b)/255)
cyan = (1-r/255-k)/(1-k)
magenta = (1-g/255-k)/(1-k)
yellow = (1-b/255-k)/(1-k)
k1=100*round(k, 2)
cyan1=100*round(cyan, 2)
magenta1=100*round(magenta,2)
yellow1=100*round(yellow,2)
total= (k1+cyan1+magenta1+yellow1)+0.0000001
k2= (k1/total)*100
cyan2= (cyan1/total)*100
magenta2= (magenta1/total)*100
yellow2= (yellow1/total)*100
k3=round(k2,0)
cyan3=round(cyan2,0)
magenta3=round(magenta2,0)
yellow3=round(yellow2,0)
k4=(int)(round((k3*9/100),0))
cyan4=(int)(round((cyan3*9/100),0))
magenta4=(int)(round((magenta3*9/100),0))
yellow4=(int)(round((yellow3*9/100),0))
print("cyan%=",cyan4,"magenta%=",magenta4,"yellow%=",yellow4,"negro=%",k4)
i=0
while (i!=9):
if (cyan4!=0):
m[i]= [0,255,255]; cyan4=cyan4-1; i=i+1
if (magenta4!=0):
m[i]= [255,0,255]; magenta4=magenta4-1; i=i+1
if (yellow4!=0):
m[i]= [255,255,0]; yellow4=yellow4-1; i=i+1
if (k4!=0):
m[i]= [0,0,0]; k4=k4-1; i=i+1
print (m)
imagen2[x-1, y-1]= m[1]
imagen2[x, y-1]= m[2]
imagen2[x+1, y-1]= m[3]
imagen2[x-1, y]= m[4]
imagen2[x+1,y]= m[5]
imagen2[x, y]= m[6]
imagen2[x-1, y+1]= m[7]
imagen2[x, y+1]= m[8]
imagen2[x+1, y+1]= m[9]
x=x+1
y=y+1
imagen2.save("cmyk_aprox.gif") ````