from supreme.io import imread A = imread(sys.argv[1], flatten=True).astype(np.uint8) Ac = imread(sys.argv[1], flatten=False).astype(np.uint8) B = imread(sys.argv[2], flatten=True).astype(np.uint8) Bc = imread(sys.argv[2], flatten=False).astype(np.uint8) else: A = chelsea(grey=True).astype(np.uint8) Ac = A t = 20/180. * np.pi x = 3 y = 6 B = homography(A, [[np.cos(t), -np.sin(t), x], [np.sin(t), np.cos(t), y], [0, 0, 1]]) Bc = B M, S = register.dense_MI(A, B, levels=3, std=5, win_size=9) print "Mutual information: ", S if S < 1.5: print "Warning: registration probably failed." print "Transformation matrix:" print np.array2string(M, separator=', ') X = register.stack.with_transform([Ac, Bc], [np.eye(3), M], save_tiff=True) if len(sys.argv) != 3: import matplotlib.pyplot as plt plt.imshow(X) plt.show()
if len(sys.argv) == 3: from supreme.io import imread A = imread(sys.argv[1], flatten=True).astype(np.uint8) Ac = imread(sys.argv[1], flatten=False).astype(np.uint8) B = imread(sys.argv[2], flatten=True).astype(np.uint8) Bc = imread(sys.argv[2], flatten=False).astype(np.uint8) else: A = chelsea(grey=True).astype(np.uint8) Ac = A t = 20 / 180. * np.pi x = 3 y = 6 B = homography( A, [[np.cos(t), -np.sin(t), x], [np.sin(t), np.cos(t), y], [0, 0, 1]]) Bc = B M, S = register.dense_MI(A, B, levels=3, std=5, win_size=9) print "Mutual information: ", S if S < 1.5: print "Warning: registration probably failed." print "Transformation matrix:" print np.array2string(M, separator=', ') X = register.stack.with_transform([Ac, Bc], [np.eye(3), M], save_tiff=True) if len(sys.argv) != 3: import matplotlib.pyplot as plt plt.imshow(X) plt.show()
img_dir = img_dir[0] images = [imread(i, flatten=True).astype(np.uint8) for i in glob(os.path.join(os.path.join(vgg, img_dir), '*.' + img_dir))] H_dir = os.path.join(vgg, 'H') if not os.path.isdir(H_dir): os.mkdir(H_dir) 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
for i in glob(os.path.join(os.path.join(vgg, img_dir), '*.' + img_dir)) ] H_dir = os.path.join(vgg, 'H') if not os.path.isdir(H_dir): os.mkdir(H_dir) 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)