所用matlab版本为2015b
1 灰度图线性变换
i=imread('songshu.jpg');
i=im2double(rgb2gray(i));
[m,n]=size(i);
%增加对比度
Fa=1.25;Fb=0;
s=Fa.*i+Fb/255;
figure(1),subplot(221),imshow(s);
title('k=1.25.b=0');
figure(2),subplot(221),[H,x]=imhist(s,64);
stem(x,(H/m/n),'.');
title('k=1.25,b=0');
%减小对比度
Fa=0.5;Fb=0;
s=Fa.*i+Fb/255;
figure(1),subplot(222),imshow(s);
title('k=0.5.b=0');
figure(2),subplot(222),[H,x]=imhist(s,64);
stem(x,(H/m/n),'.');
title('k=0.5,b=0');
%线性亮度增加
Fa=1.25;Fb=50;
s=Fa.*i+Fb/255;
figure(1),subplot(223),imshow(s);
title('k=1.25.b=50');
figure(2),subplot(223),[H,x]=imhist(s,64);
stem(x,(H/m/n),'.');
title('k=1.25,b=50');
%底片显示
Fa=-1;Fb=255;
s=Fa.*i+Fb/255;
figure(1),subplot(224),imshow(s);
title('k=-1.b=255');
figure(2),subplot(224),[H,x]=imhist(s,64);
stem(x,(H/m/n),'.');
title('k=-1,b=255');
2灰度拉伸
用最黑和最白亮度的相除值,白色越亮,黑色越暗
i=imread('songshu.jpg');
i=rgb2gray(i);
L=imadjust(i,[],[50/255;150/255]);
J=imadjust(L,[50/255;150/255],[20/55;230/255]);
subplot(221),imshow(L),title('low contrast');
subplot(222),imhist(L),title('low contrast');
subplot(223),imshow(J),title('gray stretch');
subplot(224),imhist(J),title('gray stretch');
3 灰度图像均衡
可使低对比度的灰度图对比度提高
i=imread('songshu.jpg');
i=rgb2gray(i);
LC=imadjust(i,[],[50/255;150/255]);%将全图的元素缩到50-150
figure(1),subplot(221),imshow(LC);
title('low contrast');
figure(1),subplot(222),imhist(LC);
title('low contrast');
HE1=histeq(LC);
figure(1),subplot(223),imshow(HE1);
title('histeq img');
figure(1),subplot(224),imhist(HE1);
title('histeq img');