offset = round(offset*img.shape[0]) # convert to pixels dims = (img.shape[0]+offset, img.shape[1], img.shape[2]) g = m.makeCarrier(dims, T) print 'computing gratings...' L = 0.04 # learning rate niter = 501 # of iterations for i in range(niter): if i % 25 == 0: print "iteration [%4d/%4d]" % (i, niter) # update grating err = (1-img)/2 - (g[0:-offset,:,:] - g[offset:,:,:]) g[0:-offset,:,:] += L*err g[offset:,:,:] -= L*err g = m.smoothenPhase(g, 1e-4/T) print 'saving image...' g = m.makeGrating(g) # visualize gratings m.show(g, 312, 'grating') # visualize superpositions e = m.ones((offset, img.shape[1], img.shape[2])) s = m.vstack((e, g))*m.vstack((g, e)) m.show(s, 313, 'superposition') fig.savefig('./results/moire3.png', dpi=300)
if i % 25 == 0: print "iteration [%4d/%4d]" % (i, niter) # update gratings err1 = (1 - img[0]) / 2 - (g1[:-offset, :, :] - g2[offset:, :, :]) err2 = (1 - img[1]) / 2 - (g2[:-offset, :, :] - g1[offset:, :, :]) g1[:-offset, :, :] += L * err1 g2[offset:, :, :] -= L * err1 g2[:-offset, :, :] += L * err2 g1[offset:, :, :] -= L * err2 # enforce grating smoothness by clipping the laplacian g1 = m.smoothenPhase(g1, 1e-4 / T) print "saving image..." g1 = m.makeGrating(g1) g2 = m.makeGrating(g2) # visualize gratings m.show(g1, 323, "grating 1") m.show(g2, 324, "grating 2") # visualize superpositions e = m.ones((offset, dims[1], dims[2])) s1 = m.vstack((e, g1)) * m.vstack((g2, e)) s2 = m.vstack((e, g2)) * m.vstack((g1, e)) m.show(s1, 325, "superposition 1") m.show(s2, 326, "superposition 2") fig.savefig("./results/moire2.png", dpi=300)
offset = round(offset * img.shape[0]) # convert to pixels dims = (img.shape[0] + offset, img.shape[1], img.shape[2]) g = m.makeCarrier(dims, T) print 'computing gratings...' L = 0.04 # learning rate niter = 501 # of iterations for i in range(niter): if i % 25 == 0: print "iteration [%4d/%4d]" % (i, niter) # update grating err = (1 - img) / 2 - (g[0:-offset, :, :] - g[offset:, :, :]) g[0:-offset, :, :] += L * err g[offset:, :, :] -= L * err g = m.smoothenPhase(g, 1e-4 / T) print 'saving image...' g = m.makeGrating(g) # visualize gratings m.show(g, 312, 'grating') # visualize superpositions e = m.ones((offset, img.shape[1], img.shape[2])) s = m.vstack((e, g)) * m.vstack((g, e)) m.show(s, 313, 'superposition') fig.savefig('./results/moire3.png', dpi=300)
g1[:-offset, :, :] += L * err1 g2[offset:, :, :] -= L * err1 g2[:-offset, :, :] += L * err2 g1[offset:, :, :] -= L * err2 # enforce grating smoothness by clipping the laplacian g1 = m.smoothenPhase(g1, 1e-4 / T) g2 = m.smoothenPhase(g2, 1e-4 / T) print 'saving image...' g1 = m.makeGrating(g1) g2 = m.makeGrating(g2) # visualize gratings m.saveImage(g1, combinedFilename + '-grating1', dpi) m.saveImage(g2, combinedFilename + '-grating2', dpi) m.show(g1, 323, 'grating 1') m.show(g2, 324, 'grating 2') # visualize superpositions e = m.ones((offset, dims[1], dims[2])) s1 = m.vstack((e, g1)) * m.vstack((g2, e)) s2 = m.vstack((e, g2)) * m.vstack((g1, e)) m.saveImage(s1, combinedFilename + '-superposition1') m.saveImage(s2, combinedFilename + '-superposition2') m.show(s1, 325, 'superposition 1') m.show(s2, 326, 'superposition 2') fig.savefig('./results/' + combinedFilename + '.png', dpi=300)