版权所有:caoleiscu欢迎指正:caoleiemail@163.com[filename,pathname]=uigetfile('*.bmp;*.tif;*.jpg;*.png','输入原图像');file_name=[pathnamefilename];I=imread(file_name);disp('四种基本的灰度变换,请输入选择项');disp('0--图像反转');disp('1--对数变换');disp('2--伽马变换');disp('3--分段线性变换');disp('4--直方图均衡');d=input('pleaseinputyouchoice(请输入您的选择):');switchdcase0J=double(I);J=256-1-J;H=uint8(J);subplot(121),imshow(I);subplot(122),imshow(H);case1J=log(1+double(I));subplot(121),imshow(I);subplot(122),imshow(J,[]);case2x=0:255;a=80,b=1.8,c=0.009;J=b.^(c.*(double(I)-a))-1;y=b.^(c.*(x-a))-1;subplot(2,2,1),imshow(I);subplot(2,2,2),imhist(I);subplot(2,2,3),imshow(J);subplot(2,2,4),imhist(J);figure,plot(x,y);case3f0=0;g0=0;f1=10;g1=30;f2=220;g2=180;f3=255;g3=255;figure,plot([f0,f1,f2,f3],[g0,g1,g2,g3]);r1=(g1-g0)/(f1-f0);b1=-r1*f0+g0;r2=(g2-g1)/(f2-f1);b2=-r2*f1+g1;r3=(g3-g2)/(f3-f2);b3=-r3*f2+g2;axis([02550255]);[m,n]=size(I)h=double(I);figure,imshow(mat2gray(h));fori=1:mforj=1:nt=h(i,j);g(i,j)=0;if((t=f0)&&(t=f1))g(i,j)=r1*t+b1;elseif((t=f1)&&(t=f2))g(i,j)=r2*t+b2;elseif((t=f2)&&(t=f3))g(i,j)=r3*t+b3;endendendendendfigure,imshow(mat2gray(g));case4H=histeq(I);%直方图均衡化subplot(121),imshow(I);subplot(122),imshow(H);otherwisedisp('你输入的是无效数字');end