【发布时间】:2018-11-03 02:54:38
【问题描述】:
我有一些基本上被 0 值包围的数据,我想将高斯滤波器应用于屏蔽零值的非零值。
这是一个 MWE:
import numpy as np
import scipy.ndimage as ndimage
import matplotlib.pyplot as plt
import random
data = np.zeros((100, 100))
for i in range(25, 76, 1):
for j in range(25, 76, 1):
data[i, j] = random.random()
data2 = ndimage.gaussian_filter(data, sigma=5.0)
fig1 = plt.figure("data")
ax = fig1.add_subplot(111)
cf1 = ax.contourf(data)
fig1.colorbar(cf1)
fig1 = plt.figure("data2")
ax = fig1.add_subplot(111)
cf1 = ax.contourf(data2)
fig1.colorbar(cf1)
抱歉,我不知道为什么,但我无法上传 MWE 的结果。
MWE 在位于中心位置 [25:75, 25:75] 的子正方形 50x50 中生成一个 100x100 数组,其中包含非零值。
当我应用过滤器时,非零值的数量随着位置 [5:96, 5:96] 的增加而增加。
我希望它以某种方式掩盖零值而不在那里应用过滤器,过滤器必须仅在 50x50 子正方形中应用。
我尝试使用 numpy 掩码数组,但没有成功。
有人知道怎么做吗?
【问题讨论】:
-
您是要忍受 0 还是 0,还是希望 0 完全不影响过滤结果?
-
@CrisLuengo 我希望它们完全不影响过滤结果
标签: python python-2.7 image-processing imagefilter