matlab图像操作与空间滤波

使用matlab进行图片操作与空间滤波
两幅尺寸大小不同的图像进行连接

例如,两幅图像的高(宽)不同,把高度(宽度)较大的图像等比例缩小,使得两幅图像的高度(宽度)一致,然后把两幅图像横着(竖着)连接起来并显示。

img1 = imread(path1);
img2 = imread(path2);
[h1, w1, i1] = size(img1);
[h2, w2, i2] = size(img2);
if h1 < h2
    img2 = imresize(img2, [h1, w2]);
    img3 = [img1, img2];  % 横向连接
    imshow(img3)
else
    img1 = imresize(img1, [h2, w1]);
    img3 = [img1; img2];  % 竖直连接
    imshow(img3)
end

两幅高度不同,宽度相同的图片

把图片水平和竖直翻转
function task4(path)
img = imread(path);
subplot(1, 3, 1);imshow(img);title('原图');
% 水平翻转
img_h = fliplr(img);
subplot(1, 3, 2);imshow(img_h);title('水平翻转');

% 竖直翻转
img_v = flipud(img);
subplot(1, 3, 3);imshow(img_v);title('竖直翻转');

图片进行翻转

使用均值滤波

关于imfilter函数的使用介绍:imfilter()

function task5(path)
img = imread(path);
subplot(2, 3, 1);imshow(img);title('原图');

filter5 = fspecial('average', 5);
img5 = imfilter(img, filter5, 'corr', 'replicate', 'same');
subplot(2, 3, 2);imshow(img5);title('5*5均值滤波');

filter9 = fspecial('average', 9);
img9 = imfilter(img, filter9, 'corr', 'replicate', 'same');
subplot(2, 3, 3);imshow(img9);title('9*9均值滤波');

filter15 = fspecial('average', 15);
img15 = imfilter(img, filter15, 'corr', 'replicate', 'same');
subplot(2, 3, 4);imshow(img15);title('15*15均值滤波');

filter35 = fspecial('average', 35);
img35 = imfilter(img, filter35, 'corr', 'replicate', 'same');
subplot(2, 3, 5);imshow(img35);title('35*35均值滤波');

使用不同尺寸的均值滤波

使用中值滤波

中值滤波可以降低图片的椒盐噪声。

function task6(path)
img = imread(path);
subplot(1, 2, 1);imshow(img);title('原图');
% imshow(img)
% 进行3 * 3中值滤波
img_mid = medfilt2(img, [3, 3]);
subplot(1, 2, 2);imshow(img_mid);title('3*3中值滤波');

中值滤波的效果

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值