【问题标题】:Histogram equalization for pythonpython的直方图均衡化
【发布时间】:2013-01-25 22:50:15
【问题描述】:

我有这个例程来对照片进行直方图均衡:

def histeq(im,nbr_bins=256):

   #get image histogram
   imhist,bins = histogram(im.flatten(),nbr_bins,normed=True)
   cdf = imhist.cumsum() #cumulative distribution function
   cdf = 255 * cdf / cdf[-1] #normalize

   #use linear interpolation of cdf to find new pixel values
   im2 = interp(im.flatten(),bins[:-1],cdf)

   return im2.reshape(im.shape), cdf

#im = array(Image.open('AquaTermi_lowcontrast.jpg').convert('L'))
im = array(Image.open('Unequalized.jpg').convert('L'))
#Image.open('plant4.jpg').convert('L').save('inverted.jpg')

im2,cdf = histeq(im)

plt.imshow(im2)
plt.savefig("outputhisto.jpg")

当我使用histogram equalization wiki 页面中的picture 运行此程序时,结果如下:

而不是像this 那样正确调整图像的对比度。我做错了什么?

【问题讨论】:

  • 不知道。不过,当有六个赞成票时,这并不重要:)

标签: python image-processing histogram histogram-equalization


【解决方案1】:

您确定您只是没有使用错误的颜色图进行渲染吗?试试

plt.imshow(im2, cmap=plt.cm.gray)

或者

plt.imshow(im2, cmap=plt.get_cmap('gray'))

【讨论】:

  • 天才!哈哈,这很容易。确切的语法是cmap=plt.cm.gray 而不是灰色。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-08
  • 1970-01-01
  • 2020-01-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多