MATLAB中滤波演示

MATLAB中使用均值、中值、prewitt滤波器的几个例子

clc;clear; close all
%% 盒式滤波器
img = imread('lena256.bmp');%图像读取
img = rgb2gray(img);%转换为灰度图
h1 = fspecial('average',3); %3×3卷积核
img_filted1 = imfilter(img,h1);
h2 = fspecial('average',11); %11×11卷积核
img_filted2= imfilter(img,h2);
h3 = fspecial('average',21); %21×21卷积核
img_filted3 = imfilter(img,h3);
%显示原图及结果
figure,
subplot(221),
imshow(img,[]);
title('原图');
subplot(222),
imshow(img_filted1,[]);
title('3×3盒式滤波结果');
subplot(223),
imshow(img_filted2,[]);
title('11×11盒式滤波结果');
subplot(224),
imshow(img_filted3,[]);
title('21×21盒式滤波结果');
%% 中值滤波
img_medfilt = medfilt2(img);
figure,
subplot(121),
imshow(img,[]);
title('原图');
subplot(122);
imshow(img_medfilt,[]),
title('中值滤波结果');

%% Prewitt滤波
h_p1 = fspecial('prewitt');
h_p2 = h_p1';
img_prefilt1 = imfilter(img,h_p1);
img_prefilt2 = imfilter(img,h_p2);
figure,
subplot(131),
imshow(img,[]);
title('原图');
subplot(132),
imshow(img_prefilt1,[]);
title('prewitt滤波(水平)');
subplot(133),
imshow(img_prefilt2,[]);
title('prewitt滤波(垂直)');
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值