发布网友 发布时间:2022-04-26 19:16
共1个回答
热心网友 时间:2023-10-23 07:34
代码分别对灰度图像,真彩色图像以及索引图像进行滤波处理,然后用if语句将三段整合,并使用isind,isrgb,isgray语句判断图像类型,做出相应处理。
W=input('输入原始图像及其拓展名:','s');
h = imread(W);
P=imnoise(h,'gaussian ',0.02);
x=isind(P)
y=isrgb(P)
z=isgray(P)
if x==1
[X,map]=imread(W);
imshow(X,map);
P=imnoise(X,'gaussian',0.02);
subplot(2,2,1),imshow(P,map),title('原始图像','fontsize',20,'fontname','隶书');
h1=filter2(fspecial('gaussian',[3 3],0.5),P);
subplot(2,2,2),imshow(h1,map),title('滤波图像 滤波器:3*3 sigma=0.5','fontsize',20,'fontname','隶书');
h2=filter2(fspecial('gaussian',[3 3],1.5),P);
subplot(2,2,3),imshow(h2,map),title('滤波图像 滤波器:3*3 sigma=1.5','fontsize',20,'fontname','隶书');
h3=filter2(fspecial('gaussian',[3 3],2.5),P);
subplot(2,2,4),imshow(h3,map),title('滤波图像 滤波器:3*3 sigma=2.5','fontsize',20,'fontname','隶书');
elseif y==1
subplot(2,2,1);imshow(P,[]);
title('(a)原始图像','fontsize',20,'fontname','隶书');
H = fspecial('gaussian');
gi= imfilter(P,H,'replicate');
subplot(2,2,2);imshow(gi,[]);
title('(b)滤波图像 滤波器3*3 sigma=0.5','fontsize',20,'fontname','隶书');
H1= fspecial('gaussian',[3,3],1.5);
gi1= imfilter(P,H1,'replicate');
subplot(2,2,3);imshow(gi1,[]);
title('(c)滤波图像 滤波器3*3 sigma=1.5','fontsize',20,'fontname','隶书');
H2=fspecial('gaussian',[3,3],2.5);
gi2=imfilter(P,H2,'replicate');
subplot(2,2,4);imshow(gi2,[]);
title('(d)滤波图像 滤波器3*3 sigma=2.5','fontsize',20,'fontname','隶书');
else z==1
subplot(2,2,1),imshow(P)
title('(a)原始图像','fontsize',20,'fontname','隶书');
J1=filter2(fspecial('gaussian',[3,3], 0.5),P)/255;
subplot(2,2,2),imshow(J1)
title('(b)滤波图像 滤波器3*3 sigma=0.5','fontsize',20,'fontname','隶书');
J2=filter2(fspecial('gaussian',[3,3], 1.5),P)/255;
subplot(2,2,3),imshow(J2)
title('(c)滤波图像 滤波器3*3 sigma=1.5','fontsize',20,'fontname','隶书');
J3=filter2(fspecial('gaussian',[3,3], 2.5),P)/255;
subplot(2,2,4),imshow(J3)
title('(d)滤波图像 滤波器3*3 sigma=2.5','fontsize',20,'fontname','隶书');
end