미리 정의 된 목록에없는 이미지에서 일부 픽셀의 색상 만 변경하는 방법은 무엇입니까? 나는이 같은 시도 : 난 그냥 일부 픽셀이 검은 만들고 싶어Python에서 픽셀 색상을 변경하는 방법
from PIL import Image
picture = Image.open("// location")
imshow (picture)
_colors = [[0, 128, 0], [128, 128, 0], [128, 128, 128], [192, 128, 0], [128, 64, 0], [0, 192, 0], [128, 64, 128], [0, 0, 0]]
width, height = picture.size
for x in range(0, width-1):
for y in range(0, height-1):
current_color = picture.getpixel((x,y))
if current_color!= _colors[0] and current_color!= _colors[1] and current_color!= _colors[2] and current_color!= _colors[3] and current_color!= _colors[4] and current_color!= _colors[5] and current_color!= _colors[6] and current_color!= _colors[7]:
picture.putpixel((x,y), (0, 0, 0))
imshow (picture)
을하지만, 어떻게 든이 검은 색 이미지를 반환 모두
"IN"으로 문이'picture.putpixel 경우 ((x, y)는 (0, 0, 0))' 안에 있으면? 들여 쓰기가 꺼져 있습니다. – WeaselFox
들여 쓰기가있는 질문을 편집했습니다. – valentin