介绍一些基本的绘图方法和灰度变换函数,对imadjust()和strtchlim()函数进行说明:
g = imadjust(f, [ low_in hight_in] , [ low_out high_out ] , gamma );
该函数将 f 中的灰度值映射为g中的新值,即将[ low_in hight_in] 映射到[ low_out high_out ] ,low_in 以下和high_in以上的值。输入图像可以是uint8、uint16、single和double类。输出图像为同一类。gamma指定从f到g中曲线的形状。值大于1,则映射被加权至较高(较亮)的输出值、值小于1,则映射被加权至较低(较暗)的输出值。
一般图像像素值的通过mat2gray限定在 [0 , 1 ] 范围内,im2uint8会将值限定在[ 0 , 255 ] 范围内。
Low_High = stretchlim(f);
Low_High 是一个两元素的向量,该向量由一个低限和一个高限组成,用于实现对比度拉伸。
给出MATLAB源码及结果:
clc;f = imread('./face_2.jpg');
f = rgb2gray(f);
g = imadjust(f,[0 1],[1 0]);%得到明暗反转图像(负片图像)
g2 = imadjust(f,[0.5 0.75],[0 1]);%将[0.5 0.75]扩展到[0 1],用于强调感兴趣区域
g3 = imadjust(f,[ ],[ ],2);%压缩灰度级,低端并扩展到高端
subplot(2,3,1); imshow(f);
title('原图灰度图像');
subplot(2,3,2); imshow(g);
title('imadjust反转负片图像');
subplot(2,3,3); imshow(g2);
title('imadjust凸出ROI区域');
subplot(2,3,4); imshow(g3);
title('imadjust压缩灰度级');
% 利用stretchlim实现对比度拉伸
g4 = imadjust(f,stretchlim(f),[]);
g5 = imadjust(f,stretchlim(f),[1 0]);%得到负片的对比度拉伸
subplot(2,3,5); imshow(g4);
title('stretchlim对比度拉伸');
subplot(2,3,6); imshow(g5);
title('stretchlim负片对比度拉伸');