使用 python 对图像应用高斯模糊
apply gaussian blur to an image ussing python
我正在尝试使用高斯滤波器(来自期刊的图像)复制图像的以下平滑处理:
论文中说,为了从左图像到右图像,我必须应用值 x,y = 1,...,100 和 sigma = 14 的高斯滤波器来获得 "best resuts"
我在 python 中开发了以下程序来尝试实现这种平滑:
import scipy.ndimage as ndimage
import matplotlib.pyplot as plt
img = ndimage.imread('left2.png')
img = ndimage.gaussian_filter(img, sigma=(14), order=0)
plt.imshow(img)
plt.show()
由于某些原因得到的结果与右图不相似。
有人可以指出我必须在程序中修改什么才能从左图变为右图吗?
谢谢。
我来猜一猜:
因为他们提到他们的 x 和 y 值在 0-100 之间,所以他们可能应用 "sigma = 14 unit blur" 而不是 "sigma = 14 pixel blur"。
scipy.ndimage.gaussian_filter
中的sigma
参数是以像素为单位的。如果我对作者的意图是正确的,你需要缩放你传入的 sigma 参数。
如果作者指定 x
和 y
都在 0-100 范围内,则 x 和 y 方向的 sigma 将不同,因为您的输入数据出现的数量不同行多于列(即它不是一个完美的正方形图像)。
也许尝试类似的方法?
nrows, ncols = img.shape
sigma = (14 * nrows / 100.0, 14 * ncols / 100.0)
img = ndimage.gaussian_filter(img, sigma=sigma)
我正在尝试使用高斯滤波器(来自期刊的图像)复制图像的以下平滑处理:
论文中说,为了从左图像到右图像,我必须应用值 x,y = 1,...,100 和 sigma = 14 的高斯滤波器来获得 "best resuts"
我在 python 中开发了以下程序来尝试实现这种平滑:
import scipy.ndimage as ndimage
import matplotlib.pyplot as plt
img = ndimage.imread('left2.png')
img = ndimage.gaussian_filter(img, sigma=(14), order=0)
plt.imshow(img)
plt.show()
由于某些原因得到的结果与右图不相似。 有人可以指出我必须在程序中修改什么才能从左图变为右图吗?
谢谢。
我来猜一猜:
因为他们提到他们的 x 和 y 值在 0-100 之间,所以他们可能应用 "sigma = 14 unit blur" 而不是 "sigma = 14 pixel blur"。
scipy.ndimage.gaussian_filter
中的sigma
参数是以像素为单位的。如果我对作者的意图是正确的,你需要缩放你传入的 sigma 参数。
如果作者指定 x
和 y
都在 0-100 范围内,则 x 和 y 方向的 sigma 将不同,因为您的输入数据出现的数量不同行多于列(即它不是一个完美的正方形图像)。
也许尝试类似的方法?
nrows, ncols = img.shape
sigma = (14 * nrows / 100.0, 14 * ncols / 100.0)
img = ndimage.gaussian_filter(img, sigma=sigma)