向图像添加白色圆圈

Adding a white circle to an image

我正在使用 python 3.7.4,我正在尝试向图像添加白色圆圈,但我无法添加白色。 到目前为止,这是我的代码:(我已经制作了特定图像)

from PIL import Image
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
def ima(n,m):
    what=Image.new(mode='L', size=(n,n), color=m)
    mat=what.load()
    for x in range(n):
        for y in range(n):
            mat[x,y]=x%256
    return what
image=surprise(200,255) #my random image
from PIL import Image, ImageDraw
image=ima(200,255)
draw=ImageDraw.Draw(image)
draw.ellipse([(50,50),(190,245)],fill='white',outline='white') #i want the fill to be white,i tried writing None, it did not give me a white circle.(a circle of a differnet color)
plt.show(block=image)
imageplot=plt.imshow(image)

此版本有效:

#!/usr/bin/env python3
from PIL import Image, ImageDraw
import matplotlib.pyplot as plt

def ima(n,m):
    """Create and return an nxn gradient image"""
    what=Image.new(mode='L', size=(n,n), color=m)
    mat=what.load()
    for x in range(n):
        for y in range(n):
            mat[x,y]=x%256
    return what

# Create image 200x200
image=ima(200,255)

# Get drawing handle
draw=ImageDraw.Draw(image)
draw.ellipse([(50,50),(190,245)],fill='white',outline='white')

# Display result
image.show() 

当您使用 matplotlib 的 imshow 时,您可以指定颜色图 (cmap) 参数,否则 matplotlib 将使用默认颜色图,这可能不是您所期望的。您可以使用 plt.colorbar() 查看正在使用的颜色图。有关示例,请参阅我修改后的代码。另见 matplotlib colormap documentation.

import matplotlib.pyplot as plt
from PIL import Image, ImageDraw

def ima(n,m):
    what=Image.new(mode='L', size=(n,n), color=m)
    mat=what.load()
    for x in range(n):
        for y in range(n):
            mat[x,y]=x%256
    return what

image=ima(200,255)
draw=ImageDraw.Draw(image)

draw.ellipse([(50,50),(190,245)], fill='white', outline='white') 

plt.close('all')

plt.figure()
plt.imshow(image) # <-- matplotlib using it's default color translation
plt.colorbar()

plt.figure()
plt.imshow(image, cmap='Greys')
plt.colorbar()

plt.figure()
plt.imshow(image, cmap='gray')
plt.colorbar()

plt.show()