MATLAB 中的高斯滤波器

发布于 2024-08-31 13:12:04 字数 79 浏览 8 评论 0原文

MATLAB 中的“高斯”滤波器是否将图像与高斯核进行卷积?另外,如何选择参数 hsize(滤波器的大小)和 sigma?你这样做的依据是什么?

Does the 'gaussian' filter in MATLAB convolve the image with the Gaussian kernel? Also, how do you choose the parameters hsize (size of filter) and sigma? What do you base it on?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

染年凉城似染瑾 2024-09-07 13:12:04

首先使用 fspecial< 创建过滤器/a> 然后使用 将图像与过滤器进行卷积imfilter(适用于多维图像,如示例所示)。

您可以在 fspecial 中指定 sigmahsize

代码:

%%# Read an image
I = imread('peppers.png');
%# Create the gaussian filter with hsize = [5 5] and sigma = 2
G = fspecial('gaussian',[5 5],2);
%# Filter it
Ig = imfilter(I,G,'same');
%# Display
imshow(Ig)

You first create the filter with fspecial and then convolve the image with the filter using imfilter (which works on multidimensional images as in the example).

You specify sigma and hsize in fspecial.

Code:

%%# Read an image
I = imread('peppers.png');
%# Create the gaussian filter with hsize = [5 5] and sigma = 2
G = fspecial('gaussian',[5 5],2);
%# Filter it
Ig = imfilter(I,G,'same');
%# Display
imshow(Ig)
霊感 2024-09-07 13:12:04

@Jacob 已经向您展示了如何在 Matlab 中使用高斯滤波器,所以我不会重复这个。

我会选择每个方向上的滤波器大小约为 3*sigma(四舍五入为奇数整数)。因此,滤波器在边缘处衰减到接近零,并且您不会在滤波后的图像中看到不连续性。

西格玛的选择很大程度上取决于您想要做什么。高斯平滑是低通滤波,这意味着它会抑制高频细节(噪声,还有边缘),同时保留图像的低频部分(即那些变化不大的部分)。换句话说,滤镜会模糊所有比滤镜小的东西。

例如,如果您希望抑制图像中的噪声以增强对小特征的检测,我建议选择使高斯略小于特征的西格玛。

@Jacob already showed you how to use the Gaussian filter in Matlab, so I won't repeat that.

I would choose filter size to be about 3*sigma in each direction (round to odd integer). Thus, the filter decays to nearly zero at the edges, and you won't get discontinuities in the filtered image.

The choice of sigma depends a lot on what you want to do. Gaussian smoothing is low-pass filtering, which means that it suppresses high-frequency detail (noise, but also edges), while preserving the low-frequency parts of the image (i.e. those that don't vary so much). In other words, the filter blurs everything that is smaller than the filter.

If you're looking to suppress noise in an image in order to enhance the detection of small features, for example, I suggest to choose a sigma that makes the Gaussian just slightly smaller than the feature.

女中豪杰 2024-09-07 13:12:04

在 MATLAB R2015a 或更高版本中,不再需要(或从性能角度来看建议)使用 fspecial 后跟 imfilter,因为有一个名为 imgaussfilt 可以一步更高效地执行此操作。

基本语法:

B = imgaussfilt(A,sigma) 使用二维高斯平滑内核(标准差由 sigma 指定)对图像 A 进行过滤。

给定高斯标准差 (sigam) 的滤波器大小是自动选择的,但也可以手动指定:

B = imgaussfilt(A,sigma,'FilterSize',[3 3]);

默认值为 2*ceil(2*sigma)+1代码>.

imgaussfilter 的其他功能包括能够在 gpuArray 上运行、在频域或空间域中进行过滤以及高级图像填充选项。它看起来很像 IPP...嗯。另外,还有一个名为 imgaussfilt3 的 3D 版本。

In MATLAB R2015a or newer, it is no longer necessary (or advisable from a performance standpoint) to use fspecial followed by imfilter since there is a new function called imgaussfilt that performs this operation in one step and more efficiently.

The basic syntax:

B = imgaussfilt(A,sigma) filters image A with a 2-D Gaussian smoothing kernel with standard deviation specified by sigma.

The size of the filter for a given Gaussian standard deviation (sigam) is chosen automatically, but can also be specified manually:

B = imgaussfilt(A,sigma,'FilterSize',[3 3]);

The default is 2*ceil(2*sigma)+1.

Additional features of imgaussfilter are ability to operate on gpuArrays, filtering in frequency or spacial domain, and advanced image padding options. It looks a lot like IPP... hmmm. Plus, there's a 3D version called imgaussfilt3.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文