在模拟油漆的过程中。
#first, generate xslope and yslope
gby,gbx = np.mgrid[0:brush_image.shape[0],0:brush_image.shape[1]]
gbx = gbx / float(brush_image.shape[1]) -.5
gby = gby / float(brush_image.shape[0]) -.5
dgx,dgy = rn()-.5,rn()-.5
#then mix the slopes according to angle
gbmix = gbx * math.cos(angle/180.*math.pi+dgx) - gby * math.sin(angle/180.*math.pi+dgx)
其中rn()
是一个随机函数,它产生[0,1] brush_image的数量是2-d数组。角度是度。
我不知道gbmix
曾经是油画颜料。遵循公式
gbx * math.cos(angle/180.*math.pi+dgx) - gby * math.sin(angle/180.*math.pi+dgx)
我不知道评论是什么意思。它可能与简单的运动模糊相关,包括其余的代码。该公式基于什么理论?
附加类似的代码
def generate_motion_blur_kernel(dim=3,angle=0.,threshold_factor=1.3,divide_by_dim=True):
radian = angle/360*math.pi*2 + math.pi/2
# perpendicular
# x2,y2 = math.cos(radian),math.sin(radian)
# the directional vector
# first, generate xslope and yslope
gby,gbx = np.mgrid[0:dim,0:dim]
cen = (dim+1)/2-1
gbx = gbx - float(cen)
gby = gby - float(cen)
# gbx = gbx / float(cen) -.5
# gby = gby / float(cen) -.5
# then mix the slopes according to angle
gbmix = gbx * math.cos(radian) - gby * math.sin(radian)
kernel = (threshold_factor - gbmix*gbmix).clip(min=0.,max=1.)
if divide_by_dim:
kernel /= dim * dim * np.mean(kernel)
else:
pass
return kernel.astype('float32')