[python-dtcwt] 238/497: add example of image registration

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Tue Jul 21 18:06:09 UTC 2015


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/sid
in repository python-dtcwt.

commit 8491d6e945620f5e1304b9dfa8d79ef630c676b2
Author: Rich Wareham <rjw57 at cam.ac.uk>
Date:   Mon Jan 27 15:18:59 2014 +0000

    add example of image registration
---
 examples/image-registration-2.py | 69 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

diff --git a/examples/image-registration-2.py b/examples/image-registration-2.py
new file mode 100755
index 0000000..1f2278a
--- /dev/null
+++ b/examples/image-registration-2.py
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+"""
+An example of image registration via the DTCWT.
+
+This script demonstrates some methods for image registration using the DTCWT.
+
+"""
+
+from __future__ import division, print_function
+
+import itertools
+import logging
+import os
+
+from matplotlib.pyplot import *
+import numpy as np
+
+import dtcwt
+import dtcwt.sampling
+from dtcwt.registration import *
+
+logging.basicConfig(level=logging.INFO)
+
+# Load test images
+logging.info('Loading frames')
+test_frames = np.load(os.path.join(os.path.dirname(__file__), '..', 'tests', 'traffic.npz'))
+f1 = test_frames['f1']
+f2 = test_frames['f2']
+
+# Take the DTCWT of both frames.
+logging.info('Taking DTCWT')
+nlevels = 6
+Yl1, Yh1 = dtcwt.dtwavexfm2(f1, nlevels=nlevels)
+Yl2, Yh2 = dtcwt.dtwavexfm2(f2, nlevels=nlevels)
+
+# Solve for transform
+logging.info('Finding flow')
+avecs = estimateflow(Yh1, Yh2)
+
+logging.info('Computing warped image')
+warped_f1 = warp(f1, avecs, method='bilinear')
+
+logging.info('Computing velocity field')
+step = 8
+X, Y = np.meshgrid(np.arange(f1.shape[1]), np.arange(f1.shape[0]))
+vxs, vys = velocityfield(avecs, f1.shape, method='bilinear')
+
+figure()
+subplot(221)
+imshow(np.dstack((f1, f2, np.zeros_like(f1))))
+title('Overlaid frames')
+
+subplot(222)
+imshow(np.dstack((warped_f1, f2, np.zeros_like(f2))))
+title('Frame 1 warped to Frame 2 (image domain)')
+
+subplot(223)
+imshow(np.dstack((f1, f2, np.zeros_like(f2))))
+quiver(X[::step,::step], Y[::step,::step],
+        -vxs[::step,::step]*f1.shape[1], -vys[::step,::step]*f1.shape[0],
+        color='b', angles='xy', scale_units='xy', scale=1)
+title('Computed velocity field')
+
+subplot(224)
+imshow(np.sqrt(vxs*vxs + vys*vys), interpolation='none', cmap=cm.hot)
+colorbar()
+title('Magnitude of computed velocity')
+
+show()

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/python-dtcwt.git



More information about the debian-science-commits mailing list