1、0f(x,y)g(x,y)abcd(,)(,),(,)dcg x yf x yac af x ybba分段线性灰度变换ayxfyxfacbyxfacayxfabcdMyxfbdbyxfbMdMyxgffg),(0),(),(),(),(),(),(%Matlab 代码I=imread(lina.bmp);%读图象M,N=size(I);%获取图象大小R=zeros(M,N);%初始化结果图象for i=1:M%行 for j=1:N%列 g=I(i,j);%当前象素灰度 if g=a)&(gb)R(i,j)=(d-c)*(g-a)/(b-a)+c;else R(i,j)=(Mg-d)*(g-b
2、)/(Mf-b)+d;end;end;end;a,b,c是按需要可以调整的参数。cbyxfayxgln 1),(ln),(对数变换1),(),(ayxfcbyxga,b,c是按需要可以调整的参数。指数变换原始图象非线性灰度变换对数效应低灰度区扩展,高灰度区压缩非线性灰度变换指数效应低灰度区压缩,高灰度区扩展分段线性化出现假轮廓灰度倒置底片效果阈值化阈值128阈值化阈值180阈值化阈值66%例1 灰度图象I=imread(pout.tif);J=imadjust(I,0.3 0.7,);imshow(I),figure,imhist(I);figure,imshow(J),figure,imhi
3、st(J);imadjust%例2 彩色图象RGB1=imread(flowers.tif);RGB2=imadjust(RGB1,.2.3 0;.6.7 1,);imshow(RGB1),figure,imshow(RGB2)M,N=size(I);s=256;%灰度级H=zeros(1,s);for i=1:M for j=1:N g=I(i,j);H(1,g+1)=H(1,g+1)+1;end;end;rjrj+rsjsj+s)(1)()(000rTsdsdsspdrrprssrdrrprT0)13()()()23()()(00kjkjjjkknnrprTsrkr0=0r1=1/7r2=
4、2/7r3=3/7r4=4/7r5=5/7r6=6/7r7=1 nk 790102385065632924512281p(rk)0.190.250.210.160.080.060.030.02rkr0=0r1=1/7r2=2/7r3=3/7r4=4/7r5=5/7r6=6/7r7=1 nk 790102385065632924512281p(rk)0.190.250.210.160.080.060.030.02sk计算计算 0.190.440.650.810.890.950.981.00rkr0=0r1=1/7r2=2/7r3=3/7r4=4/7r5=5/7r6=6/7r7=1 nk 7901
5、02385065632924512281p(rk)0.190.250.210.160.080.060.030.02sk计算计算 0.190.440.650.810.890.950.981.00sk舍入舍入 1/73/75/76/76/71112.2.把计算的把计算的s sk k就近安排到就近安排到8 8个个灰度级中灰度级中rkr0=0r1=1/7r2=2/7r3=3/7r4=4/7r5=5/7r6=6/7r7=1 nk 790102385065632924512281p(rk)0.190.250.210.160.080.060.030.02sk计算计算 0.190.440.650.810.89
6、0.950.981.00sk舍入舍入 1/73/75/76/76/7111sk nsk 7901023850985448p(sk)0.190.250.210.240.113.3.重新命名重新命名s sk k,归并相同灰度归并相同灰度级的象素数级的象素数均衡化前后直方图比较1、显示直方图 imhist()I=imread(pout.tif);imshow(I);figure;imhist(I);%例1 J=histeq(I);imshow(I);title(原始图象);figure,imshow(J);title(直方图均衡化后图象);2、直方图均衡化 histeq()%例2I=imread(tire.tif);J=histeq(I);imshow(I);figure,imshow(J)