回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>如何仅更改不在预定义列表中的图像中的某些像素的颜色?
我试过这样的方法:</p>
<pre><code>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)
</code></pre>
<p>我只想让一些像素变黑,但不知怎么的,这会返回一个黑色的图像</p>