MATLAB实现图像灰度归一化

在许多图像处理系统中,对图像进行归一化都是必备的预处理过程。一般而言,对于灰度图像(或彩色通道的每个颜色分量)进行灰度归一化就是:使其像素的灰度值分布在0~255之间,避免图像对比度不足(图像像素亮度分布不平衡)从而对后续处理带来干扰。

一种常见的图像归一化原理1是y=(x-MinValue)/(MaxValue-MinValue)
其中x、y分别为归一化前、归一化后的值,MaxValue、MinValue分别为原始图像灰度的最大值和最小值。

源码示例(这里包含了三种方法:前两种是编程实现2,最后一种直接调用MATLAB函数来实现3,大家可以参考):

oriImage = imread('XXXX.jpg');
grayImage = rgb2gray(oriImage);
figure;
imshow(grayImage);

originalMinValue = double(min(min(grayImage)));
originalMaxValue = double(max(max(grayImage)));
originalRange = originalMaxValue - originalMinValue;

% Get a double image in the range 0 to +255
desiredMin = 0;
desiredMax = 255;
desiredRange = desiredMax - desiredMin;
dblImageS255 = desiredRange * (double(grayImage) - originalMinValue) / originalRange + desiredMin;

figure;
imshow(uint8(dblImageS255));

% Get a double image in the range 0 to +1
desiredMin = 0;
desiredMax = 1;
desiredRange = desiredMax - desiredMin;
dblImageS1 = desiredRange * (double(grayImage) - originalMinValue) / originalRange + desiredMin;

figure;
imshow(dblImageS1);

% Another way to normalazation, which only calls MATLAB function
img3 = mat2gray(oriImage);
figure;
imshow(img3);

上述源码已在MATLAB 2014和MATLAB 2016上通过测试。

原始图片:
这里写图片描述

运行后的效果:
这里写图片描述

注意:如果在自己的图片上希望看到直观的效果,请模仿示例预先将测试图片的对比度调低一些,让图像中各个像素点的灰度分布范围不足 0-255。

参考资料:
https://cn.mathworks.com/matlabcentral/newsreader/view_thread/297402
http://blog.csdn.net/zengjiqin/article/details/50032893
http://blog.csdn.net/fx677588/article/details/53301740#comments

猜你喜欢

转载自blog.csdn.net/discoverer100/article/details/61426650
今日推荐