图像预处理例子.docx

上传人:b****1 文档编号:602034 上传时间:2023-04-29 格式:DOCX 页数:17 大小:17.56KB
下载 相关 举报
图像预处理例子.docx_第1页
第1页 / 共17页
图像预处理例子.docx_第2页
第2页 / 共17页
图像预处理例子.docx_第3页
第3页 / 共17页
图像预处理例子.docx_第4页
第4页 / 共17页
图像预处理例子.docx_第5页
第5页 / 共17页
图像预处理例子.docx_第6页
第6页 / 共17页
图像预处理例子.docx_第7页
第7页 / 共17页
图像预处理例子.docx_第8页
第8页 / 共17页
图像预处理例子.docx_第9页
第9页 / 共17页
图像预处理例子.docx_第10页
第10页 / 共17页
图像预处理例子.docx_第11页
第11页 / 共17页
图像预处理例子.docx_第12页
第12页 / 共17页
图像预处理例子.docx_第13页
第13页 / 共17页
图像预处理例子.docx_第14页
第14页 / 共17页
图像预处理例子.docx_第15页
第15页 / 共17页
图像预处理例子.docx_第16页
第16页 / 共17页
图像预处理例子.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

图像预处理例子.docx

《图像预处理例子.docx》由会员分享,可在线阅读,更多相关《图像预处理例子.docx(17页珍藏版)》请在冰点文库上搜索。

图像预处理例子.docx

图像预处理例子

一、图像傅里叶变换

例1.利用傅里叶变换图像,观察分析变换结果

A=imread('E:

\张儒良图像处理课件\car1.bmp');

B=imread('E:

\张儒良图像处理课件\girl.bmp');

A1=fft2(double(A));

B1=fft2(double(B));

subplot(1,4,1);imshow(A);

subplot(1,4,2);imshow(A1);

subplot(1,4,3);imshow(B);

subplot(1,4,4);imshow(B1);

例2.利用傅里叶变换图像,然后用逆傅里叶变换观察分析变换结果

A=imread('E:

\张儒良图像处理课件\car1.bmp');

B=imread('E:

\张儒良图像处理课件\girl.bmp');

A1=fft2(double(A));

B1=fft2(double(B));

A2=abs(ifft2(A1));

B2=abs(ifft2(B1));

subplot(2,3,1);image(A);

subplot(2,3,2);imshow(A1);

subplot(2,3,3);image(A2);

subplot(2,3,4);image(B);

subplot(2,3,5);imshow(B1);

subplot(2,3,6);image(B2);

例3.利用傅里叶变换图像,然后用逆傅里叶变换观察压缩结果

A=imread('E:

\张儒良图像处理课件\apple1.bmp');

m=rgb2gray(A);

A1=fft2(double(m));

s=size(A1);

P1=zeros(s);

P1(1:

s

(1),1:

s

(2)/1.1)=A1(1:

s

(1),1:

s

(2)/1.1);

E0=(ifft2(A1));

E1=abs(ifft2(P1));

subplot(2,2,1);image(m);

subplot(2,2,2);imshow(A1);

subplot(2,2,3);image(E0);

subplot(2,2,4);image(E1);

二、离散余弦变换

例4.利用离散余弦变换图像,然后用逆离散余弦变换

A=imread('E:

\张儒良图像处理课件\car1.bmp');

B=imread('E:

\张儒良图像处理课件\girl.bmp');

C=imread('E:

\张儒良图像处理课件\car.bmp');

A1=dct2(A);

B1=dct2(B);

C1=dct2(C);

subplot(2,3,1);imshow(A);

subplot(2,3,2);imshow(A1);

subplot(2,3,3);imshow(B);

subplot(2,3,4);imshow(B1);

subplot(2,3,5);imshow(C);

subplot(2,3,6);imshow(C1)

例5.利用离散余弦变换图像,然后用逆离散余弦变换观察压缩结果

D=imread('E:

\张儒良图像处理课件\car1.bmp');

s=size(D)

D1=dct2(D);

D2=idct2(D1);

P=zeros(s);

P(1:

100,1:

100)=D1(1:

100,1:

100);

E=idct2(P);

subplot(2,2,1);

imshow(D);

subplot(2,2,2);

imshow(D1);

subplot(2,2,3);

image(D2);

subplot(2,2,4);

image(E);

例6.编程实现离散余弦变换图像(实在太慢)

A=imread('E:

\张儒良图像处理课件\car1.bmp');

A=double(A);

s=size(A)

M=s

(1);

N=s

(2);

ap0=sqrt(1/M);

ap=sqrt(2/M);

aq0=sqrt(1/N);

aq=sqrt(2/N);

forp=1:

M-1

forq=1:

N-1

k=0;

form=0:

M-1

forn=0:

N-1

k=A(m+1,n+1)*cos(pi*(2*m+1)*p/(2*M))*cos(pi*(2*n+1)*q/(2*N))+k;

end

end

B(p+1,q+1)=ap*aq*k;

end

end

B

三、灰度变换

例7:

灰度变换例程(p64)

clc

I=imread('E:

\张儒良图像处理课件\car.bmp');

J1=imadjust(I,[0.3,0.7],[0,1],1);

J2=imadjust(I,[0.3,0.7],[0,1],0.5);

J3=imadjust(I,[0.3,0.7],[0,1],1.5);

J4=imadjust(I,[0.3,0.7],[1,0],1.5);

subplot(2,3,1);imshow(I);

subplot(2,3,2);imshow(J1);

subplot(2,3,3);imshow(J2);

subplot(2,3,4);imshow(J3);

subplot(2,3,5);imshow(J4);

例7.1灰度线性变换自编程序(与imadjust(I,[0.3,0.7],[0,1],1)一致)

clc

A=imread('E:

\张儒良图像处理课件\car.bmp');

A2=double(A);

M1=floor(0.3*255);

M2=floor(0.7*255);

A3=(A2-M1)*255/(M2-M1);

s=size(A3);

fori=1:

s

(1)

forj=1:

s

(2)

ifA3(i,j)<0

A3(i,j)=0;

end

ifA3(i,j)>255

A3(i,j)=255;

end

end

end

J1=imadjust(A,[0.3,0.7],[0,1],1);

A3=uint8(A3);

subplot(1,3,1);imshow(A);

subplot(1,3,2);imshow(A3);

subplot(1,3,3);imshow(J1)

例8:

显示图像与直方图(p67)

解法1:

clc

I=imread('E:

\张儒良图像处理课件\girl.bmp');

subplot(1,2,1);imshow(I);

subplot(1,2,2);imhist(I);

解法2:

clc

A1=imread('E:

\张儒良图像处理课件\girl.bmp');

=size(A1);

A2=floor(double(A1));

N=zeros(1,256);

fori=1:

s

(1)

forj=1:

s

(2)

k=A2(i,j);

N(k+1)=N(k+1)+1;

end

end

subplot(1,3,1);imshow(A1);

subplot(1,3,2);imhist(A1);

subplot(1,3,3);bar(N)

例9:

直方图均衡化(p70)

clc

I=imread('E:

\张儒良图像处理课件\demo1.bmp');

J1=histeq(I,64);J2=histeq(I,32);J3=histeq(I);subplot(4,2,1);imshow(I);subplot(4,2,2);imhist(I);

subplot(4,2,3);imshow(J1);subplot(4,2,4);imhist(J1);

subplot(4,2,5);imshow(J2);subplot(4,2,6);imhist(J2);

subplot(4,2,7);imshow(J3);subplot(4,2,8);imhist(J3);

例10:

直方图规定化(p73)

clc

I=imread('E:

\张儒良图像处理课件\demo1.bmp');

Q=imread('E:

\张儒良图像处理课件\girl.bmp');

J=histeq(I,32);

subplot(3,2,1);imshow(J);subplot(3,2,2);imhist(J);

subplot(3,2,3);imshow(Q);subplot(3,2,4);imhist(Q);

[counts,x]=imhist(J);M=histeq(Q,counts);

subplot(3,2,5);imshow(M);subplot(3,2,6);imhist(M);

四、空间域图像平滑

例11:

加噪声(p79)

clc

I=imread('E:

\张儒良图像处理课件\demo1.bmp');

J1=imnoise(I,'gaussian');

J2=imnoise(I,'salt&pepper');

J3=imnoise(I,'speckle');

subplot(2,2,1);imshow(I);subplot(2,2,2);imshow(J1);

subplot(2,2,3);imshow(J2);subplot(2,2,4);imshow(J3);

例12:

二维中值滤波函数消噪声(p80)

clc

hood=3;hood1=5;hood2=7;

[I,map]=imread('E:

\张儒良图像处理课件\demo1.bmp');

noisy=imnoise(I,'salt&pepper',0.05);

filtered1=medfilt2(noisy,[hoodhood]);

filtered2=medfilt2(noisy,[hood1hood1]);

filtered3=medfilt2(noisy,[hood2hood2]);

subplot(2,3,1);imshow(I,map);

subplot(2,3,2);imshow(noisy,map);

subplot(2,3,3);imshow(filtered1,map);

subplot(2,3,4);imshow(filtered2,map);

subplot(2,3,5);imshow(filtered3,map);

例12-1自编程序,对图像进行邻域操作,使图形轮廓清晰。

clc

A1=imread('E:

\张儒良图像处理课件\girl.bmp');

A3=double(A1);

s=size(A3);

C=[-1-1-1;-18-1;-1-1-1];

fori=2:

s

(1)-1

forj=2:

s

(2)-1

L=A3(i-1:

i+1,j-1:

j+1).*C;

A4(i,j)=sum(sum(L));

end

end

A4=uint8(A4);

subplot(1,2,1);imshow(A1);

subplot(1,2,2);imshow(A4);

 

例13:

四邻域和八邻域平均滤波消噪声(p81)

clc

[I,map]=imread('E:

\张儒良图像处理课件\demo1.bmp');

noisy=imnoise(I,'gaussian',0.05);

myfilt1=[111;111;111];

myfilt1=myfilt1/9;

filtered1=filter2(myfilt1,noisy);

myfilt2=[111;121;111];

myfilt2=myfilt2/10;

filtered2=filter2(myfilt2,noisy);

myfilt3=[121;242;121];

myfilt3=myfilt3/10;

filtered3=filter2(myfilt3,noisy);

subplot(2,3,1);imshow(I,map);

subplot(2,3,2);imshow(noisy,map);

subplot(2,3,3);imshow(filtered1,map);

subplot(2,3,4);imshow(filtered2,map);

subplot(2,3,5);imshow(filtered3,map);

空间域图像锐化

例14:

梯度法图像锐化(p85)

clc;

[I,map]=imread('E:

\张儒良图像处理课件\girl.bmp');

I=double(I);

[IX,IY]=gradient(I);

GM=sqrt(IX.*IX+IY.*IY);

OUT1=GM;

OUT2=I;

J=find(GM>=10);

OUT2(J)=GM(J);

OUT3=I;

J=find(GM>=10);

OUT3(J)=255;

OUT4=I;

J=find(GM<=10);

OUT4(J)=255;

OUT5=I;

J=find(GM>=10);

OUT5(J)=255;

Q=find(GM<10);

OUT5(Q)=0;

subplot(3,2,1);imshow(I,map);

subplot(3,2,2);imshow(OUT1,map);

subplot(3,2,3);imshow(OUT2,map);

subplot(3,2,4);imshow(OUT3,map);

subplot(3,2,5);imshow(OUT4,map);

subplot(3,2,6);imshow(OUT5,map);

例15:

空域高通滤波法(p87)

clc;

[I,map]=imread('E:

\张儒良图像处理课件\girl.bmp');

myfilt1=[0-10;-15-1;0-10];

filtered1=filter2(myfilt1,I);

myfilt2=[-1-1-1;-19-1;-1-1-1];

filtered2=filter2(myfilt2,I);

myfilt3=[1-21;-25-2;1-21];

filtered3=filter2(myfilt3,I);

myfilt4=[-1-2-1;-219-2;-1-2-1];

myfilt4=myfilt4/7;

filtered4=filter2(myfilt4,I);

myfilt5=[-21-2;161;-21-2];

myfilt5=myfilt5/2;

filtered5=filter2(myfilt5,I);

subplot(3,2,1);imshow(I,map);

subplot(3,2,2);imshow(filtered1,map);

subplot(3,2,3);imshow(filtered2,map);

subplot(3,2,4);imshow(filtered3,map);

subplot(3,2,5);imshow(filtered4,map);

subplot(3,2,6);imshow(filtered5,map);

例16:

模板法锐化(p90)

clc;

[I,map]=imread('E:

\张儒良图像处理课件\girl.bmp');

[M,N]=size(I);

myfilt1=[121;000;-1-2-1];

filtered1=filter2(myfilt1,I);

myfilt2=[210;10-1;0-1-2];

filtered2=filter2(myfilt2,I);

myfilt3=[10-1;20-2;10-1];

filtered3=filter2(myfilt3,I);

myfilt4=[0-1-2;10-1;10-1];

filtered4=filter2(myfilt4,I);

myfilt5=[-1-2-1;000;121];

filtered5=filter2(myfilt5,I);

myfilt6=[-2-10;-10-1;012];

filtered6=filter2(myfilt6,I);

myfilt7=[-101;-202;-101];

filtered7=filter2(myfilt7,I);

myfilt8=[012;-101;-2-10];

filtered8=filter2(myfilt8,I);

fori=1:

M

forj=1:

N

x=[filtered1(i,j),filtered2(i,j),filtered3(i,j),filtered4(i,j),...

filtered5(i,j),filtered6(i,j),filtered7(i,j),filtered8(i,j)];

OUT(i,j)=max(x);

end

end

subplot(1,2,1);imshow(I,map);

subplot(1,2,2);imshow(OUT,map);

例17:

模板法锐化(p93)

各种频域低通滤波器

clc;

[I,map]=imread('E:

\张儒良图像处理课件\girl.bmp');

noisy=imnoise(I,'gaussian',0.001);

[M,N]=size(I);

F=fft2(double(noisy));

fftshift(F);

Dcut=100;

D0=150;

D1=250;

foru=1:

M

forv=1:

N

D(u,v)=sqrt(u^2+v^2);

BUTTERH(u,v)=1/(1+(sqrt

(2)-1)*(D(u,v)/Dcut)^2);

EXPOTH(u,v)=exp(log(1/sqrt

(2))*(D(u,v)/Dcut)^2);

ifD(u,v)<=200

IDEALH(u,v)=1;

else

IDEALH(u,v)=0;

end

ifD(u,v)<=D0

TRAPEH(u,v)=1;

elseifD(u,v)<=D1

TRAPEH(u,v)=(D(u,v)-D1)/(D0-D1);

else

TRAPEH(u,v)=0;

end

end

end

IDEALG=IDEALH.*F;

IDEALfiltered=ifft2(IDEALG);

BUTTERG=BUTTERH.*F;

BUTTERfiltered=ifft2(BUTTERG);

EXPOTG=EXPOTH.*F;

EXPOTfiltered=ifft2(EXPOTG);

TRAPEG=TRAPEH.*F;

TRAPEfiltered=ifft2(TRAPEG);

subplot(3,2,3);imshow(BUTTERfiltered,map);

subplot(3,2,4);imshow(EXPOTfiltered,map);

subplot(3,2,5);imshow(TRAPEfiltered,map);

例17:

灰色分层方法处理(p98)

clc;

I1=imread('E:

\张儒良图像处理课件\068.tif');

I=rgb2gray(I1);

I=imresize(I,0.2);

imshow(I);

X=grayslice(I,32);

figure;imshow(X,hot(32));

例18:

变换方法处理(p100)

I1=imread('E:

\张儒良图像处理课件\066.tif');

I=rgb2gray(I1);

I=imresize(I,0.2);

imshow(I);

I=double(I);

[M,N]=size(I);

L=256;

fori=1:

M

forj=1:

N

ifI(i,j)<=L/4

R(i,j)=0;

G(i,j)=4*I(i,j);

B(i,j)=L;

elseifI(i,j)<=L/2

R(i,j)=0;

G(i,j)=L;

B(i,j)=-4*I(i,j)+2*L;

elseifI(i,j)<=3*L/4

R(i,j)=4*I(i,j)-2*L;

G(i,j)=L;

B(i,j)=0;

else

R(i,j)=L;

G(i,j)=-4*I(i,j)+4*L;

B(i,j)=0;

end

end

end

fori=1:

M

forj=1:

N

OUT(i,j,1)=R(i,j);

OUT(i,j,2)=G(i,j);

OUT(i,j,3)=B(i,j);

end

end

OUT=OUT/256;

figure;

imshow(OUT);

例19:

滤波变换处理(p103)(没有调试通过)

clc;

I1=imread('E:

\张儒良图像处理课件\068.tif');

I=rgb2gray(I1);

I=imresize(I,0.2);

[M,N]=size(I);

F=fft2(I);

fftshift(F);

REDcut=100;

GREENcut=200;

BLUEcenter=150;

BLUEwidth=100;

BLUEu0=10;

BLUEv0=10;

foru=1:

M

forv=1:

N

D(u,v)=sqrt(u^2+v^2);

REDH(u,v)=1/(1+(sqrt

(2)-1)*(D(u,v)/REDcut)^2);

GREENH(u,v)=1/(1+(sqrt

(2)-1)*(GREENcut/D(u,v))^2);

BLUED(u,v)=sqrt((u-BLUEu0)^2+(v-BLUEv0)^2);

BLUEH(u,v)=1-1/(1+(BLUED(u,v)*BLUEwidth/((BLUED(u,v))^2-(BLUEcenter)^2))^2);

end

end

RED=REDH.*F;

REDcolor=ifft2(RED);

GREEN=GREENH.*F;

GREENcolor=ifft2(GREEN);

BLUE=BLUE.*F;

BLUEcolor=ifft2(BLUE);

REDcolor=real(REDcolor)/256;

GREENcolor=real(GREENcolor)/256;

BLUEcolor=real(BLUEcolor)/256;

fori=1:

M

forj=1:

N

OUT(i,j,1)=REDcolor(i,j);

OUT(i,j,2)=GREENcolor(i,j);

OUT(i,j,3)=BLUEcolor(i,j);

end

end

figure;

OUT=abs(OUT);

imshow(OUT);

 

例20:

假彩色变换(p105)

clc;

RGB=imread('E:

\张儒良图像处理课件\066.tif');

imshow(RGB);

RGBnew(:

:

1)=RGB(:

:

3);

RGBnew(:

:

2)=RGB(:

:

1);

RGBnew(:

:

3)=RGB(:

:

2);

figure;

imshow(RGBnew);

 

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 学习总结

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2