Python代码在模拟oilpain中的几个问题

2024-10-05 10:18:39 发布

您现在位置:Python中文网/ 问答频道 /正文

在模拟油漆的过程中。你知道吗

    #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]个笔刷的数目,图像是二维数组。角度就是度数。你知道吗

我不知道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')

Tags: imagepimathfloatkernelshapedimangle

热门问题