简体   繁体   English

如何从直方图均衡生成图像?

[英]How to generate the image from Histogram Equalization?

I'm trying to implement the Histogram Equalization by myself, I import the image by the following code: image = cv2.imread(img_path, 0) , then I generated a histogram by hist = cv2.calcHist([image], [0], None, [256], [0, 256]) plt.hist(image.ravel(), 256) .我正在尝试自己实现直方图均衡,我通过以下代码导入图像: image = cv2.imread(img_path, 0) ,然后我通过hist = cv2.calcHist([image], [0], None, [256], [0, 256]) plt.hist(image.ravel(), 256) What I want to do is to generate the image from the histogram and save the image to the disk.我想要做的是从直方图生成图像并将图像保存到磁盘。 How to deal with that?如何处理? Thanks!谢谢!

Your question is ambiguous.你的问题模棱两可。 what I understood you want generate histogram and Histogram for Equalization and save it on your disk, Am I right?我知道您想要生成直方图和直方图以进行均衡并将其保存在您的磁盘上,对吗?

for this purpose:以此目的:

import cv2
import numpy as np
from matplotlib import pyplot as plt
  
# reading the input image
img = cv2.imread('car.jpg')
  
# define colors to plot the histograms
colors = ('b','g','r')
  
# compute and plot the image histograms
for i,color in enumerate(colors):
    hist = cv2.calcHist([img],[i],None,[256],[0,256])
    plt.plot(hist,color = color)
plt.title('Image Histogram GFG')
plt.show()

在此处输入图像描述

for creating a Histograms Equalization:用于创建直方图均衡:

# read a image using imread
img = cv2.imread('car.jpg', 0)
  
# creating a Histograms Equalization
# of a image using cv2.equalizeHist()
equ = cv2.equalizeHist(img)
  
# stacking images side-by-side
res = np.hstack((img, equ))
  
# show image input vs output
plt.imshow( res)
plt.show()

在此处输入图像描述

for saving the output you just need to use this:为了保存 output 你只需要使用这个:

plt.savefig(file_path, dpi=300)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM