数字图像课程设计.docx

上传人:b****3 文档编号:5489080 上传时间:2023-05-08 格式:DOCX 页数:19 大小:454.03KB
下载 相关 举报
数字图像课程设计.docx_第1页
第1页 / 共19页
数字图像课程设计.docx_第2页
第2页 / 共19页
数字图像课程设计.docx_第3页
第3页 / 共19页
数字图像课程设计.docx_第4页
第4页 / 共19页
数字图像课程设计.docx_第5页
第5页 / 共19页
数字图像课程设计.docx_第6页
第6页 / 共19页
数字图像课程设计.docx_第7页
第7页 / 共19页
数字图像课程设计.docx_第8页
第8页 / 共19页
数字图像课程设计.docx_第9页
第9页 / 共19页
数字图像课程设计.docx_第10页
第10页 / 共19页
数字图像课程设计.docx_第11页
第11页 / 共19页
数字图像课程设计.docx_第12页
第12页 / 共19页
数字图像课程设计.docx_第13页
第13页 / 共19页
数字图像课程设计.docx_第14页
第14页 / 共19页
数字图像课程设计.docx_第15页
第15页 / 共19页
数字图像课程设计.docx_第16页
第16页 / 共19页
数字图像课程设计.docx_第17页
第17页 / 共19页
数字图像课程设计.docx_第18页
第18页 / 共19页
数字图像课程设计.docx_第19页
第19页 / 共19页
亲,该文档总共19页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

数字图像课程设计.docx

《数字图像课程设计.docx》由会员分享,可在线阅读,更多相关《数字图像课程设计.docx(19页珍藏版)》请在冰点文库上搜索。

数字图像课程设计.docx

数字图像课程设计

均衡化:

图像一直方图集中在低灰度区,图像偏暗;图像二直方图集中在高灰度区,图像偏亮;图像三直方图集中在中部,图像效反差小。

a=imread('fig1_1_1.bmp');

b=imread('fig1_1_2.bmp');

c=imread('fig1_1_3.bmp');

a1=histeq(a);

b1=histeq(b);

c1=histeq(c);

subplot(3,3,1),imshow(a),title('原始图像1');

subplot(3,3,2),imshow(b),title('原始图像2');

subplot(3,3,3),imshow(c),title('原始图像3');

subplot(3,3,4),imhist(a),title('图1直方图');

subplot(3,3,5),imhist(b),title('图2直方图');

subplot(3,3,6),imhist(c),title('图3直方图');

subplot(3,3,7),imshow(a1),title('均衡化后图像1');

subplot(3,3,8),imshow(b1),title('均衡化后图像2');

subplot(3,3,9),imshow(c1),title('均衡化后图像3');

平滑滤波:

a=imread('fig1_2.bmp');

a1=imnoise(a,'salt&pepper',0.02);

l1=filter2(fspecial('average',3),a1)/255;

l2=filter2(fspecial('average',5),a1)/255;

l3=filter2(fspecial('average',7),a1)/255;

l4=filter2(fspecial('average',9),a1)/255;

figure

(1)

subplot(2,3,1),imshow(a),title('原始图像');

subplot(2,3,2),imshow(l1);title('3*3模板平滑滤波');

subplot(2,3,3),imshow(l2);title('5*5模板平滑滤波');

subplot(2,3,4),imshow(l3);title('7*7模板平滑滤波');

subplot(2,3,5),imshow(l4);title('9*9模板平滑滤波');

l11=filter2(fspecial('average',3),a)/255;

l22=filter2(fspecial('average',5),a)/255;

l33=filter2(fspecial('average',7),a)/255;

l44=filter2(fspecial('average',9),a)/255;

figure

(2)

subplot(2,3,1),imshow(a),title('原始图像');

subplot(2,3,2),imshow(a1),title('添加椒盐噪声的图像');

subplot(2,3,3),imshow(l11);title('3*3模板平滑滤波');

subplot(2,3,4),imshow(l22);title('5*5模板平滑滤波');

subplot(2,3,5),imshow(l33);title('7*7模板平滑滤波');

subplot(2,3,6),imshow(l44);title('9*9模板平滑滤波¨');

平滑滤波是低频增强的空间域滤波技术。

它的目的有两类:

一类是模糊;另一类是消除噪音。

空间域的平滑滤波一般采用简单平均法进行,就是求邻近像元点的平均亮度值。

在噪声均匀分布在边缘时,使用平滑滤波会有较大的误差,如果噪声不是均匀分布,可有效去除噪声。

邻域的大小与平滑的效果直接相关,邻域越大平滑的效果越好,但邻域过大,平滑会使边缘信息损失的越大,从而使输出的图像变得模糊,因此需合理选择邻域的大小。

锐化滤波:

i=imread('fig1_2.bmp');

f=[8];

g=[-1-1-1;-18-1;-1-1-1];m=[-1-1-1-1-1;-1-18-1-1;-1-1-1-1-1];

n=[-1-1-1-1-1-1-1;-1-1-18-1-1-1;-1-1-1-1-1-1-1];

p=[-1-1-1-1-1-1-1-1-1;-1-1-1-18-1-1-1-1;-1-1-1-1-1-1-1-1-1];

h=double(i);

e=conv2(h,f,'same');

j=conv2(h,g,'same');

x=conv2(h,m,'same');

y=conv2(h,n,'same');

z=conv2(h,n,'same');

subplot(2,3,1);imshow(h);title('原始图像');

subplot(2,3,2);imshow(e);title('滤波后图像1');

subplot(2,3,3);imshow(j);title('滤波后图像2');

subplot(2,3,4);imshow(x);title('滤波后图像3');

subplot(2,3,5);imshow(y);title('滤波后图像4');

subplot(2,3,6);imshow(z);title('滤波后图像5');

图像锐化处理的目的是为了使图像的边缘、轮廓线以及图像的细节变的清晰。

一般情况下,在计算机图像处理中可用微分运算和高通滤波器来实现图像的锐化。

空间域图像的锐化常用的是拉普拉斯运算,它不仅是偏导数的线性组合,而且是各向同性的,这样可以使图像中间任何方向伸展的边缘和轮廓线变得清晰

低通滤波:

I=imread('fig1_2.bmp');

[mnp]=size(I);

I=double(I);

subplot(2,2,1);image(I);colormap(gray),title('原始图');

Noise=wgn(m,n,25);

New=Noise+I;

subplot(2,2,2);image(New),title('噪声图');

g=fft2(New);

g=fftshift(g);

[M,N]=size(g);

nn=2;

d0=20;

m=fix(M/2);n=fix(N/2);

fori=1:

M

forj=1:

N

d=sqrt((i-m)^2+(j-n)^2);

h=1/(1+0.414*(d/d0)^(2*nn));

result(i,j)=h*g(i,j);

end

end

result=ifftshift(result);

J2=ifft2(result);

J3=uint8(real(J2));

subplot(2,2,3);image(J3),title('截止频率20');

nn=2;

d0=100;

m=fix(M/2);n=fix(N/2);

fori=1:

M

forj=1:

N

d=sqrt((i-m)^2+(j-n)^2);

h=1/(1+0.414*(d/d0)^(2*nn));

result(i,j)=h*g(i,j);

end

end

result=ifftshift(result);

J2=ifft2(result);

J3=uint8(real(J2));

subplot(2,2,4);image(J3),title('截止频率100')

去掉信号中不必要的高频成分,降低采样频率,避免频率混淆,去掉高频干扰

高通滤波:

I=imread('fig1_2.bmp');

[mnp]=size(I);

I=double(I);

subplot(2,2,1),image(I),colormap(gray);,title('原始图');

Noise=wgn(m,n,25);

New=Noise+I;

subplot(2,2,2);image(New),title('噪声图');

g=fft2(New);

g=fftshift(g);

[M,N]=size(g);

d0=15;

m=fix(M/2);n=fix(N/2);

fori=1:

M

forj=1:

N

d=sqrt((i-m)^2+(j-n)^2);

if(d<=d0)

h=0;

elseh=1;

end

result(i,j)=h*g(i,j);

end

end

result=ifftshift(result);

J1=ifft2(result);

J2=uint8(real(J1));

subplot(2,2,3),imshow(J2),title('IHPF滤波(d0=15)');

[M,N]=size(g);

d0=100;

m=fix(M/2);n=fix(N/2);

fori=1:

M

forj=1:

N

d=sqrt((i-m)^2+(j-n)^2);

if(d<=d0)

h=0;

elseh=1;

end

result(i,j)=h*g(i,j);

end

end

result=ifftshift(result);

J1=ifft2(result);

J2=uint8(real(J1));

subplot(2,2,4),imshow(J2),title('IHPF滤波(d0=100)');

高通滤波器衰减或抑制低频分量而通过高频分量。

图像的边缘、细节主要在高频部分得到反映。

而图像的模糊是高频部分较弱造成的。

为了消除模糊,突出图像的边缘信息,则采用高通滤波器让高频部分通过,消弱图像的低频成分,再经过傅里叶逆变换得到边缘锐化的图像。

图像还原:

I=imread('fig1_3_1.bmp');

subplot(2,2,1);imshow(I);title('模糊图像');

[m,n]=size(I);

F=fftshift(fft2(I));

k=0.0025;

foru=1:

m

forv=1:

n

H(u,v)=exp((-k)*(((u-m/2)^2+(v-n/2)^2)^(5/6)));

end

end

G=F.*H;

I0=real(ifft2(fftshift(G)));

I1=imnoise(uint8(I0),'gaussian',0,0.001)

subplot(2,2,2),imshow(uint8(I1)),title('模糊退化且添加高斯噪声的图像');

F0=fftshift(fft2(I1));

F1=F0./H;

I2=ifft2(fftshift(F1));

subplot(2,2,3),imshow(uint8(I2)),title('全逆滤波复原图');

K=0.1;

foru=1:

m

forv=1:

n

H(u,v)=exp(-k*(((u-m/2)^2+(v-n/2)^2)^(5/6)));H0(u,v)=(abs(H(u,v)))^2;

H1(u,v)=H0(u,v)/(H(u,v)*(H0(u,v)+K));

end

end

F2=H1.*F0;

I3=ifft2(fftshift(F2));

subplot(2,2,4),imshow(uint8(I3)),title('维纳滤波复原图');

形态学图像处理:

I1=imread('fig1_4_1.bmp');

I3=im2bw(I1);

Subplot(221),imshow(I1)

Subplot(222),imshow(I3)

I4=bwmorph(I3,'open');

Subplot(223),imshow(I4)

I5=bwmorph(I4,'close');

 

I=imread('fig1_4_2.bmp');

B=strel('diamond',1);

J1=imopen(I,B);

J2=imclose(J1,B);

subplot(1,2,1);imshow(I);title('原始图像');

subplot(1,2,2);imshow(J2);title('滤噪结果');

 

rgb=imread('fig1_5.bmp');

rgb=im2double(rgb);

r=rgb(:

:

1);

g=rgb(:

:

2);

b=rgb(:

:

3);

subplot(3,3,1),imshow(rgb),title('原始图像');

subplot(3,3,4),imshow(r),title('原始图像红色分量');

subplot(3,3,5),imshow(g),title('原始图像绿色分量');

subplot(3,3,6),imshow(b),title('原始图像蓝色分量');

num=0.5*((r-g)+(r-b));

symden;

fen=sqrt((r-g).^2+(r-g).*(g-b));

theta=acos(num./(fen+eps));

H=theta;

H(b>g)=2*pi-H(b>g);

H=H/(2*pi);

num=min(min(r,g),b);

fen=r+g+b;

fen(fen==0)=eps;

S=1-3.*num./fen;

H(S==0)=0;

I=(r+g+b)/3;

hsi=cat(3,H,S,I);

subplot(3,3,7),imshow(H),title('H');

subplot(3,3,8),imshow(S),title('S');

subplot(3,3,9),imshow(I),title('I');

I1=rgb2gray(rgb);

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

title('灰度图像');

k1=filter2(fspecial('average',3),I1)/255;

subplot(3,3,3),imshow(k1);title('平滑滤波图像');

 

图像的校正:

A=imread('fig3_1.bmp');

se=strel('ball',12,0);

BW=imdilate(A,se);´

BW2=bwmorph(BW,'thin',Inf);

[H,T,R]=hough(BW2);

P=houghpeaks(H,5);

lines=houghlines(BW2,T,R,P);

fork=1:

length(lines)

xy=[lines(k).point1;lines(k).point2];

end

m=(xy(2,2)-xy(1,2))/(xy(2,1)-xy(1,1));

M=atan(m);

M=M*180/3.14;

C=imrotate(A,M);

subplot(1,2,1);imshow(A);title('原图像');

subplot(1,2,2);imshow(C);title('校正后的图像');

图像融合:

X1=imread('fig4_1_a.jpg');

X2=imread('fig4_1_b.jpg');

X3=imread('fig4_1_c.jpg');

X4=imread('fig4_1_d.jpg');

X5=imread('fig4_1_e.jpg');

X6=imread('fig4_1_f.jpg');

subplot(3,2,1);imshow(X1);title('序列图像1');

subplot(3,2,2);imshow(X2);title('序列图像2');

subplot(3,2,3);imshow(X3);title('序列图像3');

subplot(3,2,4);imshow(X4);title('序列图像4');

subplot(3,2,5);imshow(X5);title('序列图像5');

subplot(3,2,6);imshow(X6);title('序列图像');

X1=double(X1);

X2=double(X2);

X3=double(X3);

X4=double(X4);

X5=double(X5);

X6=double(X6);

[c1,I1]=wavedec2(X1,3,'sym4');

[c2,I2]=wavedec2(X2,3,'sym4');

[c3,I3]=wavedec2(X3,3,'sym4');

[c4,I4]=wavedec2(X4,3,'sym4');

[c5,I5]=wavedec2(X5,3,'sym4');

[c6,I6]=wavedec2(X6,3,'sym4');

%对分解系数进行融合

c=c1+c2+c3+c4+c5+c6;

I=I1+I2+I3+I4+I5+I6;

c=0.001*(c1+c2+c3+c4+c5+c6);

%应用融合系数进行图像重构并显示

XX=waverec2(c,I1,'sym4');

figure;

XX=double(XX);

imshow(XX);title('融合图像');

 

图像压缩:

clear

I=imread('fig5_1.tif');

%该图片在安装matlab的目录中找,原图为灰度图象

I=im2double(I);%图像存储类型转换

T=dctmtx(8);%离散余弦变换矩阵

B=blkproc(I,[88],'P1*x*P2',T,T');%对原图像进行DCT变换

mask=[11110000

11100000

11000000

10000000

00000000

00000000

00000000

00000000];

B2=blkproc(B,[88],'P1.*x',mask);%数据压缩,丢弃右下角高频数据

I2=blkproc(B2,[88],'P1*x*P2',T',T);%进行DCT反变换,得到压缩后的图像

subplot(1,2,1),imshow(I),title('原始图像')

subplot(1,2,2),imshow(I2),title('压缩后的图像')

imwrite(I2,'cameraman_proc.tif')

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

当前位置:首页 > IT计算机 > 电脑基础知识

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

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