def bilinear(w, h):
import math
data = np.zeros((w*h), dtype=float)
f = math.ceil(w / 2.)
c = (2 * f - 1 - f % 2) / (2. * f)
# print ('f:{}, c:{}'.format(f, c))
for i in range(w*h):
x = float(i % w)
y = float((i / w) % h)
v = (1 - abs(x / f - c)) * (1 - abs(y / f - c))
# print ('x:{}, y:{}, v:{}'.format(x, y, v))
np.put(data, i, v)
data = data.reshape((h, w))
return data
# Create 4D bilinear interpolation kernel in numpy for even size filters
评论列表
文章目录