0
我想提出一個簡單的高斯模糊,因爲我不能讓SciPy的的卷積的工作,我做我自己的:我高斯濾波器太慢
def Convolve(matr_, ker_):
output = matr_.astype(np.float64)
for x in range(len(matr_)):
for y in range(len(matr_[x])):
sum = 0
count = 0
width = int(len(ker_)/2)
for x_c in range(len(ker_)):
for y_c in range(len(ker_)):
x_index = x - x_c + width
y_index = y - y_c + width
if (x_index >= 0) and (x_index < len(matr_)) and (y_index >= 0) and (y_index < len(matr_[x])):
sum += ker_[x_c][y_c] * matr_[x_index][y_index]
count += ker_[x_c][y_c]
else:
#print("{0} -> {1}, {2} -> {3}".format(x, x_index, y, y_index))
pass
output[x][y] = sum/count
return output.astype(matr_.dtype)
我也正常化像素就在這裏,所以他們仍然會總是適合matr_
的類型。但它的工作非常慢,需要20秒才能處理1440x900圖像。這怎麼能更快地工作呢?
你可以使用'scipy.ndimage.gaussian_filter':http://docs.scipy.org/doc/scipy/reference/generated/scipy.ndimage.gaussian_filter.html –
@WarrenWeckesser我想嘗試寫我自己的。 – RomaValcer