版权所有:caoleiscu欢迎指正:caoleiemail@163.com[filename,pathname]=uigetfile('*.bmp;*.tif;*.jpg;*.png','输入原图像'); file_name=[pathname filename]; I=imread(file_name);disp('四种基本的灰度变换,请输入选择项');disp('0--图像反转');disp('1--对数变换');disp('2--伽马变换');disp('3--分段线性变换');disp('4--直方图均衡'); d=input('please input you choice(请输入您的选择):');switch d case 0 J=double(I); J=256-1-J; H=uint8(J); subplot(121),imshow(I); subplot(122),imshow(H);case 1 J=log(1+double(I)); subplot(121),imshow(I); subplot(122),imshow(J,[]);case 2 x=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);case 3 f0=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([0 255 0 255]); [m,n]=size(I) h=double(I); figure,imshow(mat2gray(h)); for i=1:m for j=1:n t=h(i,j); g(i,j)=0; if((t>=f0)&&(t<=f1)) g(i,j)=r1*t+b1; else if((t>=f1)&&(t<=f2)) g(i,j)=r2*t+b2; else if((t>=f2)&&(t<=f3)) g(i,j)=r3*t+b3; end end end end end figure,imshow(mat2gray(g)); case 4 H=histeq(I); %直方图均衡化 subplot(121),imshow(I); subplot(122),imshow(H);otherwise disp('你输入的是无效数字'); end