直方图均衡

xiaoxiao2021-02-28  102

1、直方图绘制

可用函数imhist, 其语法如下:

h = imhist(f, b)

其中,f是输入图像,h是其直方图,b是用来形容直方图的“容器”的数目。如果处理uint8的图像,且令b=2,则灰度范围被分成两部分:0至127和128至255。所得的直方图将有两个值:h(1)和h(2)。

使用如下,可以得到归一化的直方图:

p = imhist(f, b)/numel(f)

其中numel(f)给出了数组f中的元素数(即图像中像素数)

2、直方图均衡

直方图均衡由工具箱中函数histeq实现,其语法是  

g = histeq(f, nlev)

其中,f为输入图像,nlev是为输出图像设定的灰度级数。

function f = Histogram_Equalization() close all; f = imread('Fig0208(a).tif'); subplot(2,2,1); imshow(f); %画出直方图 subplot(2,2,2); imhist(f, 256); ylim('auto'); %直方图均衡 g = histeq(f, 256); subplot(2,2,3); imshow(g); subplot(2,2,4); imhist(g, 256); ylim('auto'); %归一化直方图 hnorm = imhist(f)./numel(f); cdf = cumsum(hnorm); %绘制cdf x = linspace(0, 1, 256); figure; subplot(1,2,1); plot(x, cdf); subplot(1,2,2); plot(x, cdf); axis([0 1 0 1]); set(gca, 'xtick', 0:.2:1) set(gca, 'ytick', 0:.2:1) xlabel('Input intensity values', 'fontsize', 9) ylabel('Output intensity values', 'fontsize', 9)

转载请注明原文地址: https://www.6miu.com/read-37004.html

最新回复(0)