[最新]生成图片
源程序:
I=imread('lena.jpg');
imshow(I);
title('原始图像');
imwrite(I,'wawa.jpg');
imfinfo lena.jpg
(1)生成图形:
(2)利用imwrite函数完成图像的写入(保存),得图wawa.jpg
(3)利用imfinfo函数查询图像文件的有关信息
实验五 图像平滑与滤波
(一)加噪图像分别进行中值,均值滤波:
(1)源程序:
I=imread('lena.jpg');
figure(1);
imshow(I);
title('原始图像');
%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
%----------------给图像加入方差为200的高斯噪声
figure(2);
J1= imnoise(I,'gaussian', 0,200); %给图像加入高斯噪声 subplot(4,2,1); imshow(J1);
title('加均值为0,方差为200的高斯噪声图像'); %#########均值滤波
h=fspecial('average',3);
g1=imfilter(J1,h);
subplot(4,2,3); imshow(g1); title('3×3
模板
个人简介word模板免费下载关于员工迟到处罚通告模板康奈尔office模板下载康奈尔 笔记本 模板 下载软件方案模板免费下载
均值滤波');
h=fspecial('average',5);
g2=imfilter(J1,h);
subplot(4,2,5); imshow(g2); title('5×5模板均值滤波');
h=fspecial('average',9);
g3=imfilter(J1,h);
subplot(4,2,7); imshow(g3); title('9×9模板均值滤波');
%########中值滤波
gz1=medfilt2(J1);
subplot(4,2,4);imshow(gz1);title('3×3模板中值滤波');
gz2=medfilt2(J1,[5 5]);
subplot(4,2,6);imshow(gz2);title('5×5模板中值滤波');
gz3=medfilt2(J1,[9 9]);
subplot(4,2,8);imshow(gz3);title('9×9模板中值滤波');
%----------------给图像加入方差为400的高斯噪声
figure(3);
J2= imnoise(I,'gaussian', 0,400); %给图像加入高斯噪声 subplot(4,2,1); imshow(J2);
title('加均值为0,方差为400的高斯噪声图像'); %#########均值滤波
h=fspecial('average',3);
%#########均值滤波
g4=imfilter(J2,h);
subplot(4,2,3); imshow(g4); title('3×3模板均值滤波');
h=fspecial('average',5);
g5=imfilter(J2,h);
subplot(4,2,5); imshow(g5); title('5×5模板均值滤波');
h=fspecial('average',9);
g6=imfilter(J2,h);
subplot(4,2,7); imshow(g6); title('9×9模板均值滤波');
%########中值滤波
gz4=medfilt2(J2);
subplot(4,2,4);imshow(gz4);title('3×3模板中值滤波');
gz5=medfilt2(J2,[5 5]);
subplot(4,2,6);imshow(gz5);title('5×5模板中值滤波');
gz6=medfilt2(J2,[9 9]);
subplot(4,2,8);imshow(gz6);title('9×9模板中值滤波');
%&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
%----------------给图像加入概率为0.1椒盐噪声
figure(4);
J3=imnoise(I,'salt & pepper',0.1);%给图像加入椒盐噪声 subplot(4,2,1); imshow(J3);
title('加入概率为0.1椒盐噪声的图像');
%#########均值滤波
h=fspecial('average',3);
j1=imfilter(J3,h);
subplot(4,2,3); imshow(j1); title('3×3模板均值滤波');
h=fspecial('average',5);
j2=imfilter(J3,h);
subplot(4,2,5); imshow(j2); title('5×5模板均值滤波');
h=fspecial('average',9);
j3=imfilter(J3,h);
subplot(4,2,7); imshow(j3); title('9×9模板均值滤波');
%########中值滤波
jz1=medfilt2(J3);
subplot(4,2,4);imshow(jz1);title('3×3模板中值滤波');
jz2=medfilt2(J3,[5 5]);
subplot(4,2,6);imshow(jz2);title('5×5模板中值滤波');
jz3=medfilt2(J3,[9 9]);
subplot(4,2,8);imshow(jz3);title('9×9模板中值滤波');
%----------------给图像加入概率为0.2的椒盐噪声
figure(5);
J4=imnoise(I,'salt & pepper',0.2);%给图像加入椒盐噪声 subplot(4,2,1); imshow(J4);
title('加入概率为0.2椒盐噪声的图像'); %#########均值滤波
h=fspecial('average',3);
j4=imfilter(J4,h);
subplot(4,2,3); imshow(j4); title('3×3模板均值滤波');
h=fspecial('average',5);
j5=imfilter(J4,h);
subplot(4,2,5); imshow(j5); title('5×5模板均值滤波');
h=fspecial('average',9);
j6=imfilter(J4,h);
subplot(4,2,7); imshow(j6); title('9×9模板均值滤波');
%########中值滤波
jz4=medfilt2(J4);
subplot(4,2,4);imshow(jz4);title('3×3模板中值滤波');
jz5=medfilt2(J4,[5 5]);
subplot(4,2,6);imshow(jz5);title('5×5模板中值滤波');
jz6=medfilt2(J4,[9 9]);
subplot(4,2,8);imshow(jz6);title('9×9模板中值滤波');
(2)生成图形:
(二)加噪图像进行截至频率D分别为10、25的高斯低通滤波:0
(1)源程序:
I=imread('lena.jpg'); J=imnoise(I,'salt & pepper',0.2); f=double(J);
ff=fft2(f);
g=fftshift(ff);
[n1,n2]=size(g);
d1=10; %@@@@@@@@@截至频率为10 u0=round(n1/2);
v0=round(n2/2);
for i=1:n1
for j=1:n2
d=sqrt((i-u0)^2+(j-v0)^2);
h=exp(-d^2/(2*d1^2));
y(i,j)=g(i,j)*h;
end;
end;
y1=ifftshift(y);
e1=ifft2(y1);
e2=uint8(real(e1));
subplot(4,1,1);imshow(I);title('原始图像');
subplot(4,1,2);imshow(J);title('加入椒盐噪声的图像');
subplot(4,1,3);imshow(e2);title('截至频率D0为10的高斯低通滤波的图像');
d2=25; %@@@@@@@@@截至频率为25
u0=round(n1/2);
v0=round(n2/2);
for i=1:n1
for j=1:n2
d=sqrt((i-u0)^2+(j-v0)^2);
h=exp(-d^2/(2*d2^2));
y(i,j)=g(i,j)*h;
end;
end;
y1=ifftshift(y);
e1=ifft2(y1);
e2=uint8(real(e1));
subplot(4,1,4);imshow(e2);title('截至频率D0为25的高斯低通滤波的图像');
(2)生成图形:
(三)加噪图像进行小波阈值降噪:
(1)源程序:
I=imread('lena.jpg');
J=imnoise(I,'salt & pepper',0.2);
[c,s]=wavedec2(J,2,'sym4');%使用sym4小波进行2层小波分解 [thr,sorh,keepapp]=ddencmp('den','wv',J); %使用ddencmp函数来计算噪声
%的认阈值
xd1=wdencmp('gbl',c,s,'sym4',2,thr,sorh,keepapp); %使用wdencmp函数来实现图像的降噪
subplot(1,3,1);imshow(I);title('原始图像'); subplot(1,3,2);imshow(J);title('加入椒盐噪声的图像'); subplot(1,3,3);imshow(xd1,[]);title('阈值降噪后的图像'); (2)生成图形:
实验四: