matplotlib颜色表的直方图均衡 [英] Histogram Equalization of matplotlib color tables

查看:45
本文介绍了matplotlib颜色表的直方图均衡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python和matplotlib的新手,我想知道是否有人知道是否有任何实用程序可以进行等价的直方图均衡化,但是还可以对matplotlib颜色表进行建模?有一个名为matplotlib.colors.Normalize的函数,如果给定一个图像数组,则该函数将自动设置最低和最高级别,但是我想要比这更智能的功能.我总是可以只对数据本身应用直方图均衡化,但是我宁愿不触摸数据.有什么想法吗?

I'm new to python and matplotlib and I was wondering whether anyone knew if there were any utilities available to do the equavalent of histogram equalization but to a matplotlib color table? There is a function called matplotlib.colors.Normalize which, if given a image array, will automatically set the bottom and top levels but I want something more intelligent that this. I could always just apply histogram equalization to the data itself but I would rather not touch the data. Any thoughts?

推荐答案

您必须创建自己的特定于图像的颜色图,但这并不复杂:

You have to create your own image-specific colormap, but it's not too tricky:

import pylab
import matplotlib.colors
import numpy

im = pylab.imread('lena.png').sum(axis=2) # make grayscale
pylab.imshow(im, cmap=pylab.cm.gray)
pylab.title('orig')
imvals = numpy.sort(im.flatten())
lo = imvals[0]
hi = imvals[-1]
steps = (imvals[::len(imvals)/256] - lo) / (hi - lo)
num_steps = float(len(steps))
interps = [(s, idx/num_steps, idx/num_steps) for idx, s in enumerate(steps)]
interps.append((1, 1, 1))
cdict = {'red' : interps,
         'green' : interps,
         'blue' : interps}
histeq_cmap = matplotlib.colors.LinearSegmentedColormap('HistEq', cdict)
pylab.figure()
pylab.imshow(im, cmap=histeq_cmap)
pylab.title('histeq')
pylab.show()

这篇关于matplotlib颜色表的直方图均衡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆