Skip to main content
se añadieron 265 caracteres en el cuerpo
Origen Enlace
    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)])

  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 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)+color(i) for i in range(l)])
    return (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) for i in range(l)])

    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 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]+color(i) for i in range(3))
        return (divide_color[(new_color_list[i], hist[i]) for i in range(len(hist)))]

new_color_list[index]=tuple(new_color_list[index]+color[i] for i in range(3))

se añadieron 188 caracteres en el cuerpo
Origen Enlace
Diego Avila
  • 5.5k
  • 6
  • 21
  • 48
    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
   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] result
    

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)+color(i) for i in range(l)])**Aquí 
 aparece el error**
 return (divide_color((new_color_list[i], hist[i]) for i in range(len(hist)))) 
    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 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)+color(i) for i in range(l)])**Aquí aparece el error**
return (divide_color((new_color_list[i], hist[i]) for i in range(len(hist)))) 
  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 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)+color(i) for i in range(l)]) 
    return (divide_color((new_color_list[i], hist[i]) for i in range(len(hist)))) 

estoy realizando una práctica de infórmatica para la universidad y sólo me falta este último apartado.Se trataTrato de obtener imágenes en las que los colores más cercanos entre sí por decirlo de alguna forma se vayan sustituyendo para crear una imágenimagen más homogénea. El problema es que no entiendo qué tengo que cambiar para que se arregle mi error, adjunto el código completo con el error en negrita y espero que me puedan ayudar.Muchas gracias, la verdad es que no se que hacer xd.

    `defdef 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 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)+color(i) for i in range(l)])**Aquí aparece el error**
return (divide_color((new_color_list[i], hist[i]) for i in range(len(hist)))) 

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)En la penúltima linea aparece el error: color=img.getpixel((x,y)) index=proximo(color,color_list,distance) new_color_list[index]=tuple(new_color_list[index(i)+color(i) for i in range(l)])Aquí aparece el error return (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) for i in range(l)])

estoy realizando una práctica de infórmatica para la universidad y sólo me falta este último apartado.Se trata de obtener imágenes en las que los colores más cercanos entre sí por decirlo de alguna forma se vayan sustituyendo para crear una imágen más homogénea. El problema es que no entiendo qué tengo que cambiar para que se arregle mi error, adjunto el código completo con el error en negrita y espero que me puedan ayudar.Muchas gracias, la verdad es que no se que hacer xd.

    `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 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)+color(i) for i in range(l)])Aquí aparece el error return (divide_color((new_color_list[i], hist[i]) for i in range(len(hist))))

Trato de obtener imágenes en las que los colores más cercanos entre sí por decirlo de alguna forma se vayan sustituyendo para crear una imagen más homogénea. El problema es que no entiendo qué tengo que cambiar para que se arregle mi error, adjunto el código completo con el error en negrita y espero que me puedan ayudar.

    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 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)+color(i) for i in range(l)])**Aquí aparece el error**
return (divide_color((new_color_list[i], hist[i]) for i in range(len(hist)))) 

En la penúltima linea aparece el error:

new_color_list[index]=tuple(new_color_list[index(i)+color(i) for i in range(l)])

Origen Enlace
Loading