直方图x轴表示:“像素值的范围0~L-1”,y轴表示“像素值的分布概率0~1”;
如果直方图分布不均衡,那么图像的质量和视觉效果必然受损;
读取图像和获取图像的直方图Matlab代码:
function [ output_args ] = histogramblanced(graph)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
I = imread(graph);
figure;
imshow(I); title('source');
figure;
imhist(I); title('Histogramblanced');
end
控制台调用函数即可;
一、直方图的均衡化
直方图的均衡化是指直方图灰度的均衡化,通过某种灰度映射使得输入图像转换为在每一灰度级上都有近似相同的像素点数的输出图像,即输出的直方图是均匀的。
用matlab直接调用直方图均衡化的函数[J, T] = histeq(' '), J是变换后的图像, T是变换矩阵
二、直方图的匹配(规定化处理)
就是说我有一个直方图的标准,然后把源图像也采用该标准进行变换;
源代码如下:
%将图像graph匹配成matchgraph
function [ output_args ] = histomatch(graph, matchgraph)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
src = imread(graph);
dst = imread(matchgraph);
%获取matchGrapgh的直方图
hgram1 = imhist(src);
hgram2 = imhist(dst);
%规定化处理
[J, T] = histeq(src, hgram1);
figure;
subplot(2,2,1);
imshow(src);
title('原图');
subplot(2,2,2);
imhist(src);
title('原图的直方图');
subplot(2,2,3);
imshow(J);
title('规定化图像');
subplot(2,2,4);
imhist(dst);
title('规定的直方图');
end