反色functionInverse_Callback(hObject,eventdata,handles)x=imread(‘*.bmp’)y=255-x;直方图均衡HisteQ_Callback(hObject,eventdata,handles)x=imread(‘*.bmp’)N=256;[row,col]=size(x);p=zeros(N);fori=1:row*col;p(x(i)+1)=p(x(i)+1)+1;%%%%%%%计算灰度值为i的个数,类似%%%%%p(i+1)=length(find(x==i))/(m*n);endp=(double(p))/(row*col);fork=2:Np(k)=p(k)+p(k-1);ends=fix(256*p);fori=1:row*col;x(i)=s(x(i)+1)-1;end阈值变换x=imread(‘*.bmp’)prompt={'Threshold(0~255):'};name='InputforThresholding';numlines=1;defaultanswer={'50'};anss=inputdlg(prompt,name,numlines,defaultanswer);th=str2num(anss{1});[row,col]=size(x);fori=1:row*col;ifx(i)thx(i)=256;elsex(i)=0;endend全局线性变换..f=imread(‘*.bmp’)[row,col]=size(f);f1=double(f);prompt={'themingraylevelforoutputimage(0~255):''themaxgraylevelforoutputimage(0~255):'};name='InputforContrastStretching';numlines=1;defaultanswer={'0''255'};anss=inputdlg(prompt,name,numlines,defaultanswer);b=str2num(anss{1});a=str2num(anss{2});fminGray=min(min(f1));fmaxGray=max(max(f1));g=double(zeros([row,col]));forx=1:rowfory=1:colg(x,y)=[(a-b)*(f1(x,y)-fminGray)/(fmaxGray-fminGray)]+b;endend分段线性变换...f=imread(‘*.bmp’)[row,col]=size(f);f1=double(f);N=256;prompt={'thexofthefirstpoint:''theyofthefirstpoint:''thexofthesecondpoint:''theyofthesecondpoint:''themaximumgraylevelforoutputimage:'};name='InputforContrastStretching';numlines=1;defaultanswer={'80''70''170''180''255'};anss=inputdlg(prompt,name,numlines,defaultanswer);x1=str2num(anss{1});y1=str2num(anss{2});x2=str2num(anss{3});y2=str2num(anss{4});gmaxGray=str2num(anss{5});fmaxGray=max(max(f1));forx=1:rowfory=1:coliff1(x,y)=x1g(x,y)=x2*f1(x,y)/x1;elseif(f1(x,y)x1)&(f1(x,y)=x2)g(x,y)=(y2-y1)*(f1(x,y)-x1)/(x2-x1)+y1;elseg(x,y)=(gmaxGray-y2)*(f1(x,y)-x2)/(fmaxGray-x2);endendendend对数非线性变换...f=imread(‘*.bmp’)[row,col]=size(f);mode.WindowStyle='modal';mode.Interpreter='tex';msgbox('g(x,y)=a+(ln[f(x,y)+1])/(b*ln(c))','theformul','mode');prompt={'parametera:''parameterb:''parameterc:'};name='InputforLOGtranformation';numlines=1;defaultanswer={'0''1''10'};anss=inputdlg(prompt,name,numlines,defaultanswer);a=str2num(anss{1});b=str2num(anss{2});c=str2num(anss{3});f1=double(f);N=256;g=a*ones([row,col])+log(f1+ones([row,col]))/(b*log(c));指数非线性变换...f=imread(‘*.bmp’)f1=double(f);[row,col]=size(f);mode.WindowStyle='modal';mode.Interpreter='tex';msgbox('g(x,y)=b^(c*[f(x,y)-a])','theformula','mode');prompt={'parametera:''parametrb:''parameterc:'};name='InputforExptranformation';numlines=1;defaultanswer={'0''2''0.04'};anss=inputdlg(prompt,name,numlines,defaultanswer);a=str2num(anss{1});b=str2num(anss{2});c=str2num(anss{3});N=256;g=b.^(c*(f1-a*ones([row,col])))-1;椒盐噪声f=imread(‘*.bmp’)f1=imnoise(f,'salt&pepper',0.04);高斯噪声f=imread(‘*.bmp’)f1=imnoise(f,'gaussian',0.04);均值法f=imread(‘*.bmp’)f2=double(f);[M,N]=size(f);f3=zeros([M,N]);forx=2:(M-1);fory=2:(N-1);f3(x,y)=(f2(x-1,y-1)+f2(x,y-1)+f2(x+1,y-1)+f2(x-1,y)+f2(x,y)+f2(x+1,y)+f2(x-1,y+1)+f2(x,y+1)+f2(x+1,y+1))/9;endend邻域平均法f=imread(‘*.bmp’)f2=double(f);[row,col]=size(f);f3=zeros([row,col]);forx=2:(row-1);fory=2:(col-1);f3(x,y)=(f2(x-1,y-1)+f2(x,y-1)+f2(x+1,y-1)+f2(x-1,y)+f2(x+1,y)+f2(x-1,y+1)+f2(x,y+1)+f2(x+1,y+1))/8;endend中值滤波法f=imread(‘*.bmp’);f2=double(f);[row,col]=size(f);f3=zeros([row,col]);forx=2:(row-1);fory=2:(col-1);f3(x,y)=median([f2(x-1,y-1),f2(x,y-1),f2(x+1,y-1),f2(x-1,y),f2(x,y),f2(x+1,y),f2(x-1,y+1),f2(x,y+1),f2(x+1,y+1)]);endend巴特沃氏低通滤波f=imread(‘*.bmp’);f2=double(f);[row,col]=size(f);g=fft2(f2);g=fftshift(g);nn=256;d0=40;nx=fix(row/2);ny=fix(col/2);fori=1:rowforj=1:cold=sqrt((i-nx)^2+(j-ny)^2);h=1/(1+0.414*(d/d0)^(2*nn));result(i,j)=h*g(i,j);endendresult=ifftshift(result);f3=ifft2(result);f4=abs(f3);梯度锐化..f=imread(‘*.bmp’);[row,col]=size(f);prompt={'Threshold(0~255):'};name='InputforGradientSharping';numlines=1;defaultanswer={'10'};anss=inputdlg(prompt,name,numlines,defaultanswer);th=str2num(anss{1});f1=double(f);f2=zeros(row,col);forx=2:(row-1)fory=2:(col-1)g=abs(f1(x,y)-f1(x+1,y))+abs(f1(x,y)-f1(x,y+1));ifg=thf2(x,y)=g;elsef2(x,y)=f1(x,y);endendend拉普拉斯锐化f=imread(‘*.bmp’);f1=double(f);[row,col]=size(f);f2=zeros(row,col);forx=2:(row-1)fory=2:(col-1)g=f1(x-1,y)+f1(x+1,y)+f1(x,y-1)+f1(x,y+1)-4*f1(x,y);f2(x,y)=f1(x,y)-g;g=0;endend巴特沃氏高通滤波f=imread(‘*.bmp’);f2=double(f);[row,col]=size(f);g=fft2(f2);g=fftshift(g);nn=256;d0=40;nx=fix(row/2);ny=fix(col/2);fori=1:rowforj=1:cold=sqrt((i-nx)^2+(j-ny)^2);h=1/(1+0.414*(d0/d)^(2*nn));result(i,j)=h*g(i,j);endendresult=ifftshift(result);f3=ifft2(result);f4=f2-abs(f3);伪彩色-亮度切割法f=imread(‘*.bmp’);[row,col]=size(f);f2=double(f);f3=zeros(row,col,3);forx=1:row;fory=1:col;iff2(x,y)160f3(x,y,1)=f2(x,y)+1;f3(x,y,2)=0;f3(x,y,3)=0;elseiff2(x,y)80f3(x,y,2)=f2(x,y)+1;f3(x,y,1)=0;f3(x,y,3)=0;elsef3(x,y,3)=f2(x,y)+1;f3(x,y,1)=0;f3(x,y,2)=0;endendendend伪彩色-灰度级彩色变换法f=imread(‘*.bmp’);[row,col]=size(f);f2=double(f);f3=zeros(row,col,3);forx=1:row;fory=1:col;f3(x,y,1)=255*sin(2*pi*f2(x,y)/255);f3(x,y,2)=255*sin(2*pi*f2(x,y)/255+pi/4);f3(x,y,3)=255*sin(2*pi*f2(x,y)/255+pi/2);endend