def gk(c1,r1,c2,r2):
# First, create X and Y arrays indicating distance to the boundaries of the paintbrush
# In this current context, im is the ordinal number of pixels (64 typically)
sigma = 0.3
im = 64
x = np.repeat([np.concatenate([np.mgrid[-c1:0],np.zeros(c2-c1),np.mgrid[1:1+im-c2]])],im,axis=0)
y = np.repeat(np.vstack(np.concatenate([np.mgrid[-r1:0],np.zeros(r2-r1),np.mgrid[1:1+im-r2]])),im,axis=1)
g = np.exp(-(x**2/float(im)+y**2/float(im))/(2*sigma**2))
return np.repeat([g],3,axis=0) # remove the 3 if you want to apply this to mask rather than an RGB channel
# This function reduces the likelihood of a change based on how close each individual pixel is to a maximal value.
# Consider conditioning this based on the gK value and the requested color. I.E. instead of just a flat distance from 128,
# have it be a difference from the expected color at a given location. This could also be used to "weight" the image towards staying the same.
评论列表
文章目录