您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > matlab完成分段函数的灰度变换
图像反转程序:I=imread('pout.tif');JJ=imadjust(I,[01],[10]);imshow(JJ,[]);figure;imshow(I,[]);对数变换程序:I=imread('pout.tif');imshow(I);Image=log(1+double(I));figure(2),imshow(I,[])伽马变换程序:A=imread('pout.tif');x=0:255;a=90,b=1.5,c=0.008;B=b.^(c.*(double(A)-a))-1;y=b.^(c.*(x-a))-1;subplot(2,2,1)imshow(A)subplot(2,2,2)imhist(A)subplot(2,2,3)imshow(B)subplot(2,2,4)imhist(B)figure,plot(x,y)分段线性变换程序:b=imread('pout.tif');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([02550255]);[m,n]=size(b);h=double(b);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;endendendfigure,imshow(mat2gray(g));b=imread('e:\b.bmp');%i=rgb2gray(b);%di=double(i);imhist(i);a=min(min(di));b=max(max(di));c=120.0;d=150.0;a1=0.0;b1=255.0;c1=30.0;d1=171.0;n1=find(di=a&dic);n2=find(di=c&did);n3=find(di=d&dib);di2=di;di2(n1)=(di(n1)-a)*(c1-a1)/(c-a)+a1;di2(n2)=(di(n2)-c)*(d1-c1)/(d-c)+c1;di2(n3)=(di(n3)-d)*(b1-d1)/(b-d)+d1;i2=uint8(di2);subplot(221),imshow(i);subplot(222),imshow(i2);subplot(223),imhist(i);subplot(224),imhist(i2);f=imread('cameraman.tif');%读入图像,自己改个图像,不要雷同啊[M,N]=size(f);g=zeros(M,N);fori=1:Mforj=1:Niff(i,j)=f(80,80)%f(80,80)可以改为某个介于【0,255】g(i,j)=4*f(i,j);%g(x,y)=K*f(i,j)+b!K,B值可以取合理任意值elseiff(i,j)=f(200,200)%f(200,200)可以改为某个介于【0,255】g(i,j)=5*f(i,j)+2;%同上elseiff(i,j)=f(M,N)%f(M,N)可以改为某个介于【0,255】g(i,j)=-1*f(i,j)+2;%同上endendendh=mat2gray(g);imshow(h);
本文标题:matlab完成分段函数的灰度变换
链接地址:https://www.777doc.com/doc-1648087 .html