matlab完成分段函数的灰度变换 - 图文

更新时间:2024-01-27 08:53:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

图像反转程序:

I=imread('pout.tif');

JJ=imadjust(I,[0 1],[1 0]); 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([0 255 0 255]); [m,n]=size(b); h=double(b);

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

figure,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&di=c&di=d&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); for i=1:M

for j=1:N if f(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值可以取合理任意值

elseif f(i,j)<=f(200,200)%f(200,200)可以改为某个介于【0,255】 g(i,j)=5*f(i,j)+2; %同上

elseif f(i,j)<=f(M,N) %f(M,N)可以改为某个介于【0,255】 g(i,j)=-1*f(i,j)+2; %同上 end end end

h=mat2gray(g); imshow(h);

本文来源:https://www.bwwdw.com/article/vykw.html

Top