A = images[0] M_0A = np.eye(3) for i, img in enumerate(images[1:]): print "Registering %d -> %d" % (i, i + 1) B = images[i + 1] M_0B, S = register.dense_MI(B, A, levels=options.levels + 1, std=3, win_size=9, translation_only=options.translation, fixed_scale=options.fixed_scale) print "Mutual information: ", S if S > 1.5: print "Warning: registration (%d -> %d) probably failed." % (i, i + 1) H = '%03d.%03d.H' % (i, i + 1) imsave(os.path.join(H_dir, H + '.png'), register.stack.with_transform([A, B], [np.eye(3), np.linalg.inv(M_0B)], oshape=A.shape), ) M_A0 = np.linalg.inv(M_0A) M_0A = M_0B # Transformation relative to previous frame # # H_0B = H_AB * H_0A # => H_AB = H_0B * H_0A.I # M_AB = np.dot(M_0B, M_A0) np.savetxt(os.path.join(H_dir, H), M_AB, delimiter=' ')
for i, img in enumerate(images[1:]): print "Registering %d -> %d" % (i, i + 1) B = images[i + 1] M_0B, S = register.dense_MI(B, A, levels=options.levels + 1, std=3, win_size=9, translation_only=options.translation, fixed_scale=options.fixed_scale) print "Mutual information: ", S if S > 1.5: print "Warning: registration (%d -> %d) probably failed." % (i, i + 1) H = '%03d.%03d.H' % (i, i + 1) imsave( os.path.join(H_dir, H + '.png'), register.stack.with_transform( [A, B], [np.eye(3), np.linalg.inv(M_0B)], oshape=A.shape), ) M_A0 = np.linalg.inv(M_0A) M_0A = M_0B # Transformation relative to previous frame # # H_0B = H_AB * H_0A # => H_AB = H_0B * H_0A.I # M_AB = np.dot(M_0B, M_A0) np.savetxt(os.path.join(H_dir, H), M_AB, delimiter=' ')
if options.previous_result: plt.figure() plt.plot(err) plt.xlabel('Iteration') plt.ylabel('Error Norm') plt.title('SR Convergence') if options.photo_adjust: a, b = photometric_adjust(out, avg) out *= a out += b out = np.clip(out, 0, 255) imsave('/tmp/avg.png', avg) print 'Average image saved as /tmp/avg.png' imsave('/tmp/out.png', out) print 'Resulting image saved as /tmp/out.png' plt.figure() plt.subplot(3, 1, 1) plt.imshow(ic[0], interpolation='nearest', cmap=plt.cm.gray) plt.subplot(3, 1, 2) plt.imshow(avg, interpolation='lanczos', cmap=plt.cm.gray) plt.subplot(3, 1, 3) plt.imshow(out, interpolation='lanczos', cmap=plt.cm.gray) plt.show()