Python 3.x 图像直方图不显示-如何修复?
我是Python新手,我正在尝试创建一个计算图像直方图的函数。当我运行函数时,它不会显示任何错误,但输出不是直方图,而是一个数组和输入图像 我尝试为绘图单独运行命令。当我这样做的时候,它会显示出来,但我仍然没有得到直方图 def image_hist():Python 3.x 图像直方图不显示-如何修复?,python-3.x,image-processing,Python 3.x,Image Processing,我是Python新手,我正在尝试创建一个计算图像直方图的函数。当我运行函数时,它不会显示任何错误,但输出不是直方图,而是一个数组和输入图像 我尝试为绘图单独运行命令。当我这样做的时候,它会显示出来,但我仍然没有得到直方图 def image_hist(): 尝试按以下方式使用库PIL和numpy: import PIL import numpy as np im=Image.open('lena.png') a = np.array(im.getdata()) # Convert t
尝试按以下方式使用库PIL和numpy:
import PIL
import numpy as np
im=Image.open('lena.png')
a = np.array(im.getdata()) # Convert the image into a 2D-Array
bins_hist = list(range(0,257)) # Number of greyvalues
histogram = np.histogram(a, bins=bins_hist)
counts = histogram[0]
fig, ax1 = plt.subplots()
color = 'tab:red'
ax1.bar(np.arange(256), counts, color=color)
import PIL
import numpy as np
im=Image.open('lena.png')
a = np.array(im.getdata()) # Convert the image into a 2D-Array
bins_hist = list(range(0,257)) # Number of greyvalues
histogram = np.histogram(a, bins=bins_hist)
counts = histogram[0]
fig, ax1 = plt.subplots()
color = 'tab:red'
ax1.bar(np.arange(256), counts, color=color)