在圆形图像区域应用2d高斯滤波器 - Matlab [英] Applying 2d gaussian filter in a circular image area - Matlab

查看:387
本文介绍了在圆形图像区域应用2d高斯滤波器 - Matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以在圆形图像区域中应用2d高斯滤波器(简单来说就是一个现成的matlab函数)或者是否必须自己实现这个?

Is there an easy way to apply a 2d gaussian filter in a circular image area (by easy i mean a ready matlab function) or does one have to implement this on his own ??

推荐答案

如果要将任何滤镜应用于图像的选定部分,一个选项是使用二进制遮罩。

If you want to apply any filter to a selected portion of the image, one option is to use a binary mask.

img 成为您的图像,设置圆形蒙版的位置和半径以及滤镜的尺寸:

Let img be your image, set the position and the radius of the circular mask as well as the dimension of the filter:

centre=[50 50];
radius=20;
n=5;

然后创建面具:

Mask=zeros(size(img));
Disk = fspecial('disk',radius)==0;
Mask(centre(1)-radius:centre(1)-radius+size(Disk,1)-1, centre(2)-radius:centre(2)-radius+size(Disk,2)-1)=double(~Disk);

按照@Gacek的建议应用过滤:

Apply filtering as suggested by @Gacek:

h = fspecial('gaussian', n);
Filtered=filter2(h, img);

将过滤后的区域与原始图像合并并显示结果:

Combine the filtered area with the original image and show the result:

Result=img.*uint8(~Mask)+uint8(Filtered.*Mask);
imshow(Result)

示例结果:

注意: 1.将类 uint8 更改为原始图像的相应类。 2.示例图像位于公共领域,来源:en.wikipedia.org/wiki/File:Phase_correlation.png。

Notes: 1. change the class uint8 to the appropriate class of your original image. 2. The example image is in the public domain, source: en.wikipedia.org/wiki/File:Phase_correlation.png.

这篇关于在圆形图像区域应用2d高斯滤波器 - Matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆