def fun(x): return to_scalar(np.rot90(x)) d_fun = lambda x : to_scalar(grad(fun)(x))
def fun(x): return np.rot90(x)
def fun(x): return to_scalar(np.rot90(x))
def callback_Test(mvable_pts, iter, g): # img, vesselImage, vesselPts = updateVesselImg(vesselImage, vesselSecretion, mvable_pts, img) # Loss ax_loss.cla() ax_loss.set_title('Train Loss') ax_loss.set_xlabel('t') ax_loss.set_ylabel('loss') nowLoss = fitness(mvable_pts, iter) all_loss.append(nowLoss) time = np.arange(0, len(all_loss), 1) ax_loss.plot(time, all_loss, '-', linestyle='solid', label='loss') #, color = colors[i] ax_loss.set_xlim(time.min(), time.max()) ax_loss.legend(loc="upper left") ax_img.cla() ax_img.set_title('Flow Image') ax_img.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) ax_img.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) imgplot = ax_img.imshow(np.rot90(np.array(img))) ax_diffused_img.cla() diffused_img_plt1 = diffusion(mvable_pts, vesselPts, img, vesselImage) ax_diffused_img.set_title('Diffused Image') ax_diffused_img.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) ax_diffused_img.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) diffusedplot = ax_diffused_img.imshow(np.rot90(diffused_img_plt1)) ax_loss_map.cla() loss_map = create_loss_map(np.array(diffused_img_plt1), vesselPts, threshold, iter) ax_loss_map.set_title('Diffusion Loss Map') ax_loss_map.tick_params(axis='x', which='both', bottom=False, top=False, labelbottom=False) ax_loss_map.tick_params(axis='y', which='both', left=False, right=False, labelleft=False) loss_plot = ax_loss_map.imshow(np.rot90(np.array(loss_map))) plt.draw() saveImageOne(iter) plt.pause(0.001) return 3
img = np.zeros((imageSize, imageSize)) vesselImage = np.zeros((imageSize, imageSize)) * vesselSecretion # movablePts = [(imageSize/2, imageSize/2.0), (imageSize/2 + 0.5, imageSize - 0.5)] # movablePts = [(2.01,2.5)] movablePts = [(2.0, 2.5)] # movablePts = [(imageSize/2 + 0.5, imageSize - 5.5)] # movablePts = [(imageSize/2.0, imageSize/2.0)] vesselPts = [(int(x), int(y)) for (x, y) in movablePts] for (xi, yi) in vesselPts: vesselImage[xi, yi] = vesselSecretion print('Starting Initial Diffusion') img = initial_diffusion(movablePts, vesselPts, img, vesselImage) print('Ended Initial Diffusion') plt.imshow(np.rot90(np.array(img)[1:, 1:])) plt.show() # os.sys.exit() def fitness(movablePts, iter): # vesselPts, img, vesselImage are obtained through dynamic binding diffused_img = diffusion(movablePts, vesselPts, img, vesselImage) return loss_health(diffused_img, vesselPts, threshold, iter) # Setup display figures fig = plt.figure(figsize=(16, 4), facecolor='white') ax_loss = fig.add_subplot(151, frameon=True) ax_node_graph = fig.add_subplot(152, frameon=True) ax_img = fig.add_subplot(153, frameon=True)
def conv2(x, y, mode='same'): return np.rot90(convolve2d(np.rot90(x, 2), np.rot90(y, 2), mode=mode), 2)