【发布时间】:2019-09-29 12:04:48
【问题描述】:
我正在使用一个简单的高斯滤镜来模糊下面 MWE 中的图像
import imageio
import matplotlib.pyplot as plt
import numpy as np
from scipy.ndimage.filters import gaussian_filter
image = imageio.imread('imageio:camera.png')
image_blurred = np.copy(image).astype(np.float)
image_blurred /= 255
image_blurred = gaussian_filter(image_blurred, sigma=3)
image_blurred *= 255
image_blurred = np.round(image_blurred).astype(np.uint8)
plt.close('all')
fig, ax = plt.subplots(2,2, figsize=(6,8))
ax[0][0].imshow(image, cmap='gray')
ax[0][0].set_title('Original')
ax[1][0].hist(image.ravel(), 256, density=True)
ax[0][1].imshow(image_blurred, cmap='gray')
ax[0][1].set_title('Blur 3')
ax[1][1].hist(image_blurred.ravel(), 256, density=True)
plt.show()
问题是,经过高斯滤波器后的图像在直方图中显示了一些孔,我们可以在下面右侧的直方图中看到
这是预期的吗?如果是这样,我可以对图像应用哪种操作来平滑直方图?
【问题讨论】:
-
当您使用与原版完全相同的垃圾箱时,您是否也会出现孔洞? IE。如果
h, bins = ax[1][0].hist(image.ravel(), 256, density=True),那么ax[1][1].hist(image_blurred.ravel(), bins=bins, density=True)? -
哇。不。我注意到
axes.hist中的 256 个垃圾箱给了我 257 个垃圾箱而不是 256 个。因此我将256更改为255,它给了我预期的[0, 1, 2, ..., 255]垃圾箱。 -
如
matplotlib hist文档中所说:如果给定整数,则计算并返回 bin + 1 bin 边
标签: python numpy image-processing computer-vision gaussianblur