def getRandomMotionBlurMask(extent):
X = makeRandomWalkCurve(40, 20, 2)
Y = smoothCurve(X, 20)
Y = Y - np.mean(Y, 0)[None, :]
Y = Y/np.max(Y, 0)
Y = Y*extent
theta = np.random.rand()*2*np.pi
Y[:, 0] = Y[:, 0] + np.cos(theta)*np.linspace(0, extent, Y.shape[0])
Y[:, 1] = Y[:, 1] + np.sin(theta)*np.linspace(0, extent, Y.shape[0])
D = np.sum(Y**2, 1)[:, None]
D = D + D.T - 2*Y.dot(Y.T)
D[D < 0] = 0
D = 0.5*(D + D.T)
D = np.sqrt(D)
Y = Y*extent/np.max(D)
Y = Y - np.mean(Y, 0)[None, :]
Y = Y - np.min(Y)
I = np.zeros((extent, extent))
for i in range(Y.shape[0]-1):
c = [Y[i, 0], Y[i, 1], Y[i+1, 0], Y[i+1, 1]]
c = [int(np.round(cc)) for cc in c]
rr, cc = line(c[0], c[1], c[2], c[3])
rr = [min(max(rrr, 0), extent-1) for rrr in rr]
cc = [min(max(ccc, 0), extent-1) for ccc in cc]
I[rr, cc] += 1.0
I = I/np.sum(I)
return (Y, I)
评论列表
文章目录