def channel_hist(image): color = ('b', 'g', 'r') for i, color in enumerate(color): hist = cv2.calcHist([image], [i], None, [256], [0, 256]) plt.plot(hist, color) plt.xlim([0, 256]) fig = plt.gcf() canvas = FigureCanvasTkAgg(fig,master=root2) canvas.draw() #将Matplotlib绘图对象输出为二进制流 buf = canvas.buffer_rgba() img = Image.frombytes('RGBA',canvas.get_width_height(),bytes(buf)) tk_img = ImageTk.PhotoImage(img) #plt.show() return tk_img如何禁止直方图叠加
时间: 2024-01-24 08:02:47 浏览: 196
hist-shrink.zip_hist image
要禁止直方图叠加,需要为每个颜色通道创建一个新的子图。您可以修改代码如下:
```
def channel_hist(image):
color = ('b', 'g', 'r')
fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(8,3)) # 创建一行三列的子图
for i, color in enumerate(color):
hist = cv2.calcHist([image], [i], None, [256], [0, 256])
axs[i].plot(hist, color)
axs[i].set_xlim([0, 256])
# plt.show()
canvas = FigureCanvasTkAgg(fig,master=root2)
canvas.draw()
# 将Matplotlib绘图对象输出为二进制流
buf = canvas.buffer_rgba()
img = Image.frombytes('RGBA',canvas.get_width_height(),bytes(buf))
tk_img = ImageTk.PhotoImage(img)
return tk_img
```
这样,每个颜色通道的直方图将显示在不同的子图中,而不是在同一个图中叠加。
阅读全文