scipy.ndimage.gaussian_filter函数的Sigma参数我不理解轴的概念

发布于 2025-02-08 10:03:23 字数 1577 浏览 1 评论 0原文

我有简单的示例,这些示例无法像预期的

import numpy as np
from PIL import Image
from scipy import ndimage

def gaussian_smoothing(image, sigma = 1):
    im = np.array(image)
    sim = ndimage.gaussian_filter(im, sigma=sigma)

    print(im.shape)
    return Image.fromarray(sim)

def main():
    im = Image.open("./data/kodim03.png")

    filtered_image = gaussian_smoothing(im, 1)

    filtered_image.show()

输入图像一样工作:

”

图像的形状为(512,768,3)

输出图像:

“”

图像被弄清楚了。那不是我所期望的。

我做了一些挖掘,但我仍然感到困惑。来自scipy.ndimage.gaussian_filter文档页面:

sigma:标量或标量序列

高斯内核的标准偏差。标准偏差 给出每个轴的高斯滤波器作为一个序列,或作为单个 数字,在这种情况下,所有轴都相等。

当我更改代码并替换行sim = ndimage.gaussian_filter(im,sigma = sigma) sim = ndimage.gaussian_filter(im,sigma =(sigma,sigma,sigma,sigma,sigma,0))) 我会得到预期的结果。

预期输出:

“”

我不了解轴的概念。我认为前两个轴是X方向和Y方向。但是第三轴是颜色吗?

我在卷积和过滤器方面的经验非常有限,但我一直认为这是一个简单的盒子,可以在图像上移动并应用高斯舒缓。由于我们在这里有三个渠道,RGB,我想这一过程将在所有3个渠道中重复,并且将发生某种平均值。

有人可以向我解释有关X,Y和色彩方向的想法以及如何工作的想法。

I have simple example that is not working as expected

import numpy as np
from PIL import Image
from scipy import ndimage

def gaussian_smoothing(image, sigma = 1):
    im = np.array(image)
    sim = ndimage.gaussian_filter(im, sigma=sigma)

    print(im.shape)
    return Image.fromarray(sim)

def main():
    im = Image.open("./data/kodim03.png")

    filtered_image = gaussian_smoothing(im, 1)

    filtered_image.show()

Input Image:

The shape of the image is (512, 768, 3).

Output Image:

The image is greyed out. That is not what I was expecting.

Ive done some digging but I am still confused. From the scipy.ndimage.gaussian_filter doc page:

sigma: scalar or sequence of scalars

Standard deviation for Gaussian kernel. The standard deviations of the
Gaussian filter are given for each axis as a sequence, or as a single
number, in which case it is equal for all axes.

When I change my code and replace the line sim = ndimage.gaussian_filter(im, sigma=sigma) with sim = ndimage.gaussian_filter(im, sigma=(sigma, sigma, 0)) I get expected result.

Expected output:

I don't understand the concept of the axes. I think the first two axes are X direction and Y direction. But is third axis a color?

My experience with convolutions and filters is very limited but I always thought about it as a simple box moving across the image and applying Gaussian soothing. Since we have three channels here, RGB, I would imagine the process will be repeated across all 3 channels and some sort of averaging will happen.

Can someone explain to me what is the idea about going in X, Y and color direction and how does it work.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文