0

假设我有一个如下二维数组的图像:

img = np.array([
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0],
           [0, 0, 0, 1, 0, 0, 0, 0, 0.5, 0, 0, 0, 0]])

我想对其应用高斯模糊,因此图像如下:

imgBlurred = np.array([
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1],
           [0.0, 0.2, 0.7, 1, 0.7, 0.2, 0.3, 0.4, 0.5, 0.4, 0.3, 0.2, 0.1]])

基本上,我想要一个结果,其中那些值的高斯非常厚,而原始图像中的 0.5 值则更大。

到目前为止,我进行如下操作:

 from scipy import ndimage
 import numpy as np
 #img is a numpy array
 imgBlurred = ndimage.filters.gaussian_filter(img, sigma=0.7)
 #Normalisation by maximal value, because the gaussian blur reduce the 1 to ~0.5
 imgBlurred = imgBlurred/imgBlurred.max()
 imgBlurred[imgBlurred > 1] = 1# In case of the maximal value was > 1

但是这样做会让模糊图像上的那些和 0.5 相同。如果有人知道如何解决这个“问题”,我想有一些建议!

4

0 回答 0