def distance(color1,color2):
result=0
for i in range(len(color1)):
result=result+(color1[i]-color2[i])**2
return result
def dist1(color1,color2):
result=0
for i in range(len(color1)):
result=result+(color1[i]-color2[i])**2
return result
def dist2(color1,color2):
result=0
for i in range(len(color1)):
result=max(result,abs(color1[i]-color2[i]))
return result
def dist3(color1,color2):
result=0
cofs=[2,4,3]
for i in range(len(color1)):
result=result+cofs[i]*(color1[i]-color2[i])**2
return result
def muestra(img,k,l):
width,heigth=img.size
result=[]
for x in range(0,width,width//k):
for y in range(0,heigth,heigth//l):
result.append(img.getpixel((x,y)))
return result
def proximo(color,color_list,distance):
min=distance(color,color_list[0])
index_min=0
for i in range(1,len(color_list)):
d=distance(color,color_list[i])
if d<min:
min=d
index_min=i
return index_min
def prox_subst_inic(img,color_list,distance):
width,heigth=img.size
result=Image.new("RGB",(width,heigth),(0,0,0))
for x in range(width):
for y in range(heigth):
color=img.getpixel((x,y))
index=proximo(color,color_list,distance)
result.putpixel((x,y),color_list[index])
return result
def divide_color(color,n): return (round(color[0])/n),round(color[1]/n),round(color[2]/n) hist= [int]
def divide_color(color,n):
return (round(color[0])/n),round(color[1]/n),round(color[2]/n)
hist= [int]
def prox_subst(img,color_list,distance):
width,height=img.size
new_color_list=[(0,0,0)*len(color_list)]
for x in range(width):
for y in range(height):
color=img.getpixel((x,y))
index=proximo(color,color_list,distance)
new_color_list[index]=tuple(new_color_list[index(i)+colornew_color_list[index]+color(i) for i in range(l3)])
return (divide_color(divide_color[(new_color_list[i], hist[i]) for i in range(len(hist)))) ]
new_color_list[index]=tuple(new_color_list[index(i)+color(i)new_color_list[index]+color[i] for i in range(l3)])