def paint_latents( event ):
global r, Z, output,painted_rects,MASK,USER_MASK,RECON
# Get extent of latent paintbrush
x1, y1 = ( event.x - d.get() ), ( event.y - d.get() )
x2, y2 = ( event.x + d.get() ), ( event.y + d.get() )
selected_widget = event.widget
# Paint in latent space and update Z
painted_rects.append(event.widget.create_rectangle( x1, y1, x2, y2, fill = rb(color.get()),outline = rb(color.get()) ))
r[max((y1-bd),0):min((y2-bd),r.shape[0]),max((x1-bd),0):min((x2-bd),r.shape[1])] = color.get()/255.0;
Z = np.asarray([np.mean(o) for v in [np.hsplit(h,Z.shape[0])\
for h in np.vsplit((r),Z.shape[1])]\
for o in v]).reshape(Z.shape[0],Z.shape[1])
if SAMPLE_FLAG:
update_photo(None,output)
update_canvas(w) # Remove this if you wish to see a more free-form paintbrush
else:
DELTA = model.sample_at(np.float32([Z.flatten()]))[0]-to_tanh(np.float32(RECON))
MASK=scipy.ndimage.filters.gaussian_filter(np.min([np.mean(np.abs(DELTA),axis=0),np.ones((64,64))],axis=0),0.7)
# D = dampen(to_tanh(np.float32(RECON)),MASK*DELTA+(1-MASK)*ERROR)
D = MASK*DELTA+(1-MASK)*ERROR
IM = np.uint8(from_tanh(to_tanh(RECON)+D))
update_canvas(w) # Remove this if you wish to see a more free-form paintbrush
update_photo(IM,output)
# Scroll to lighten or darken an image patch
评论列表
文章目录