Python 基于HSI模型的直方图均衡化
我在DebianLinux上使用Python2.7以及matplotlib、Numpy、Scipy和PIL。 我能够使用上面提到的代码为图像的H S和I参数生成直方图。我打算在H S和I直方图上应用直方图均衡化,然后将其转换回结果图像,以便比较变化。谁能帮我写一些必要的直方图均衡化代码,并把均衡后的直方图转换成图像Python 基于HSI模型的直方图均衡化,python,numpy,matplotlib,scipy,Python,Numpy,Matplotlib,Scipy,我在DebianLinux上使用Python2.7以及matplotlib、Numpy、Scipy和PIL。 我能够使用上面提到的代码为图像的H S和I参数生成直方图。我打算在H S和I直方图上应用直方图均衡化,然后将其转换回结果图像,以便比较变化。谁能帮我写一些必要的直方图均衡化代码,并把均衡后的直方图转换成图像 import scipy from scipy import ndimage import matplotlib.pyplot as plt import matplotlib.co
import scipy
from scipy import ndimage
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np
from scipy import misc
import scipy.misc
img = scipy.misc.imread("/home/subhradeep/Desktop/testc.jpg")
array=np.asarray(img)
arr=(array.astype(float))/255.0
img_hsv = colors.rgb_to_hsv(arr[...,:3])
lu1=img_hsv[...,0].flatten()
plt.subplot(1,3,1)
plt.hist(lu1*360,bins=360,range=(0.0,360.0),histtype='stepfilled', color='r', label='Hue')
plt.title("Hue")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.legend()
lu2=img_hsv[...,1].flatten()
plt.subplot(1,3,2)
plt.hist(lu2,bins=100,range=(0.0,1.0),histtype='stepfilled', color='g', label='Saturation')
plt.title("Saturation")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.legend()
lu3=img_hsv[...,2].flatten()
plt.subplot(1,3,3)
plt.hist(lu3*255,bins=256,range=(0.0,255.0),histtype='stepfilled', color='b', label='Intesity')
plt.title("Intensity")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.legend()
plt.show()
我需要用python实现eq(4)
据我所知,您只需对HSV变换的值分量应用直方图均衡,即可均衡图像:
def histeq(im,nbr_bins=256):
""" Histogram equalization of a grayscale image.
From http://programmingcomputervision.com/"""
# get image histogram
imhist,bins = np.histogram(im.flatten(),nbr_bins,normed=True)
cdf = imhist.cumsum() # cumulative distribution function
cdf = 1 * cdf / cdf[-1] # normalize (value component max is 1.0)
# use linear interpolation of cdf to find new pixel values
im2 = np.interp(im.flatten(),bins[:-1],cdf)
return im2.reshape(im.shape), cdf
#equalise the intensity component
img_hsv[:,:,2], cdf = histeq(img_hsv[:,:,2])
#then convert back to RGB space
img_eq = colors.hsv_to_rgb(img_hsv)
曝光不足的输入图像:
直方图均衡输出图像:
当然,如果您希望看到输出的样子,您可以将上述内容应用于HSV变换的每个通道。我不确定你这样做能达到什么效果。嘿,我只是按照你描述的那样做了,但我想对饱和度参数使用相同的技术,并计算直方图的平均值。我该怎么做呢?实际上,我正在对彩色图像执行一种特殊类型的直方图均衡化,称为HE-VED或具有可变增强度的直方图均衡化,其中u具有参数a(α)对于alpha=1的饱和参数,结果是正常的,对于alpha=0,结果是原始图像,因此我应该通过拍摄参考图像来改变alpha的值。同样,在intesity的情况下,还有一个beta参数也可以这样做。