Skip to content
This repository was archived by the owner on Jul 30, 2024. It is now read-only.

Commit 1957eb1

Browse files
committed
Merge pull request #101 from rjw57/remove-ipython
remove ipython directive from Sphinx docs
2 parents 77dd4ce + ac72798 commit 1957eb1

2 files changed

Lines changed: 113 additions & 60 deletions

File tree

docs/conf.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@
4646
'sphinx.ext.todo',
4747
'sphinx.ext.coverage',
4848
'sphinx.ext.mathjax',
49-
'matplotlib.sphinxext.ipython_directive',
5049
'matplotlib.sphinxext.plot_directive',
51-
'IPython.sphinxext.ipython_console_highlighting',
5250
]
5351

5452
# Add any paths that contain templates here, relative to this directory.

docs/registration.rst

Lines changed: 113 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -260,113 +260,168 @@ As an example, we will register two frames from a video of road traffic.
260260
Firstly, as boilerplate, import plotting command from pylab and also the
261261
:py:mod:`datasets` module which is part of the test suite for :py:mod:`dtcwt`.
262262

263-
.. ipython::
263+
.. code::
264264
265-
In [0]: from pylab import *
266-
267-
In [0]: import datasets
265+
from pylab import *
266+
import datasets
268267
269268
If we show one image in the red channel and one in the green, we can see where
270269
the images are incorrectly registered by looking for red or green fringes:
271270

272-
.. ipython::
271+
.. code::
273272
274-
@doctest
275-
In [1]: ref, src = datasets.regframes('traffic')
273+
ref, src = datasets.regframes('traffic')
276274
277-
In [1]: figure()
275+
figure()
276+
imshow(np.dstack((ref, src, np.zeros_like(ref))))
277+
title('Registration input images')
278278
279-
In [3]: imshow(np.dstack((ref, src, np.zeros_like(ref))))
280-
Out[3]: <matplotlib.image.AxesImage at 0x319d9d0>
279+
.. plot::
281280

282-
@savefig gen-registration-input.png align=center
283-
In [4]: title('Registration input images')
284-
Out[4]: <matplotlib.text.Text at 0x3193ad0>
281+
from pylab import *
282+
import datasets
285283

286-
To register the images we first take the DTCWT:
284+
ref, src = datasets.regframes('traffic')
287285

288-
.. ipython::
289-
:doctest:
286+
figure()
287+
imshow(np.dstack((ref, src, np.zeros_like(ref))))
288+
title('Registration input images')
290289

291-
In [5]: import dtcwt
290+
To register the images we first take the DTCWT:
292291

293-
In [6]: transform = dtcwt.Transform2d()
292+
.. code::
294293
295-
In [7]: ref_t = transform.forward(ref, nlevels=6)
294+
import dtcwt
296295
297-
In [8]: src_t = transform.forward(src, nlevels=6)
296+
transform = dtcwt.Transform2d()
297+
ref_t = transform.forward(ref, nlevels=6)
298+
src_t = transform.forward(src, nlevels=6)
298299
299300
Registration is now performed via the :py:func:`dtcwt.registration.estimatereg`
300301
function. Once the registration is estimated, we can warp the source image to
301302
the reference using the :py:func:`dtcwt.registration.warp` function.
302303

303-
.. ipython::
304+
.. code::
304305
305-
In [9]: import dtcwt.registration as registration
306+
import dtcwt.registration as registration
306307
307-
@doctest
308-
In [10]: reg = registration.estimatereg(src_t, ref_t)
309-
310-
:doctest:
311-
In [13]: warped_src = registration.warp(src, reg, method='bilinear')
308+
reg = registration.estimatereg(src_t, ref_t)
309+
warped_src = registration.warp(src, reg, method='bilinear')
312310
313311
Plotting the warped and reference image in the green and red channels again
314312
shows a marked reduction in colour fringes.
315313

316-
.. ipython::
314+
.. code::
315+
316+
figure()
317317
318-
In [1]: figure()
318+
imshow(np.dstack((ref, warped_src, np.zeros_like(ref))))
319+
title('Source image warped to reference')
319320
320-
In [14]: imshow(np.dstack((ref, warped_src, np.zeros_like(ref))))
321-
Out[14]: <matplotlib.image.AxesImage at 0x3186d90>
321+
.. plot::
322322

323-
@savefig gen-registration-warped.png align=center
324-
In [15]: title('Source image warped to reference')
323+
from pylab import *
324+
import datasets
325+
ref, src = datasets.regframes('traffic')
326+
import dtcwt
327+
transform = dtcwt.Transform2d()
328+
ref_t = transform.forward(ref, nlevels=6)
329+
src_t = transform.forward(src, nlevels=6)
330+
import dtcwt.registration as registration
331+
332+
reg = registration.estimatereg(src_t, ref_t)
333+
warped_src = registration.warp(src, reg, method='bilinear')
334+
figure()
335+
336+
imshow(np.dstack((ref, warped_src, np.zeros_like(ref))))
337+
title('Source image warped to reference')
325338

326339
The velocity field, in units of image width/height, can be calculated by the
327340
:py:func:`dtcwt.registration.velocityfield` function. We need to scale the
328341
result by the image width and height to get a velocity field in pixels.
329342

330-
.. ipython::
343+
.. code::
331344
332-
@doctest
333-
In [24]: vxs, vys = registration.velocityfield(reg, ref.shape[:2], method='bilinear')
345+
vxs, vys = registration.velocityfield(reg, ref.shape[:2], method='bilinear')
346+
vxs = vxs * ref.shape[1]
347+
vys = vys * ref.shape[0]
334348
335-
In [0]: vxs = vxs * ref.shape[1]
349+
We can plot the result as a quiver map overlaid on the reference image:
336350

337-
In [0]: vys = vys * ref.shape[0]
351+
.. code::
338352
353+
figure()
339354
340-
We can plot the result as a quiver map overlaid on the reference image:
355+
X, Y = np.meshgrid(np.arange(ref.shape[1]), np.arange(ref.shape[0]))
356+
357+
imshow(ref, cmap=cm.gray, clim=(0,1))
341358
342-
.. ipython::
359+
step = 8
343360
344-
In [1]: figure()
361+
quiver(X[::step,::step], Y[::step,::step],
362+
vxs[::step,::step], vys[::step,::step],
363+
color='g', angles='xy', scale_units='xy', scale=0.25)
345364
346-
In [26]: X, Y = np.meshgrid(np.arange(ref.shape[1]), np.arange(ref.shape[0]))
365+
title('Estimated velocity field (x4 scale)')
347366
348-
In [27]: imshow(ref, cmap=cm.gray, clim=(0,1))
349-
Out[27]: <matplotlib.image.AxesImage at 0x7ded610>
367+
.. plot::
350368

351-
In [25]: step = 8
369+
from pylab import *
370+
import datasets
371+
ref, src = datasets.regframes('traffic')
372+
import dtcwt
373+
transform = dtcwt.Transform2d()
374+
ref_t = transform.forward(ref, nlevels=6)
375+
src_t = transform.forward(src, nlevels=6)
376+
import dtcwt.registration as registration
352377

353-
In [28]: quiver(X[::step,::step], Y[::step,::step],
354-
....: vxs[::step,::step], vys[::step,::step],
355-
....: color='g', angles='xy', scale_units='xy', scale=0.25)
356-
Out[28]: <matplotlib.quiver.Quiver at 0x7df1110>
378+
reg = registration.estimatereg(src_t, ref_t)
379+
warped_src = registration.warp(src, reg, method='bilinear')
357380

358-
@savefig gen-registration-vel-field.png align=center
359-
In [29]: title('Estimated velocity field (x4 scale)')
381+
vxs, vys = registration.velocityfield(reg, ref.shape[:2], method='bilinear')
382+
vxs = vxs * ref.shape[1]
383+
vys = vys * ref.shape[0]
384+
385+
figure()
386+
387+
X, Y = np.meshgrid(np.arange(ref.shape[1]), np.arange(ref.shape[0]))
388+
389+
imshow(ref, cmap=cm.gray, clim=(0,1))
390+
391+
step = 8
392+
393+
quiver(X[::step,::step], Y[::step,::step],
394+
vxs[::step,::step], vys[::step,::step],
395+
color='g', angles='xy', scale_units='xy', scale=0.25)
396+
397+
title('Estimated velocity field (x4 scale)')
360398

361399
We can also plot the magnitude of the velocity field which clearly shows the moving cars:
362400

363-
.. ipython::
401+
.. code::
402+
403+
figure()
404+
imshow(np.abs(vxs + 1j*vys), cmap=cm.hot)
405+
title('Velocity field magnitude')
406+
407+
.. plot::
408+
409+
from pylab import *
410+
import datasets
411+
ref, src = datasets.regframes('traffic')
412+
import dtcwt
413+
transform = dtcwt.Transform2d()
414+
ref_t = transform.forward(ref, nlevels=6)
415+
src_t = transform.forward(src, nlevels=6)
416+
import dtcwt.registration as registration
364417

365-
In [1]: figure()
418+
reg = registration.estimatereg(src_t, ref_t)
419+
warped_src = registration.warp(src, reg, method='bilinear')
366420

367-
In [30]: imshow(np.abs(vxs + 1j*vys), cmap=cm.hot)
368-
Out[30]: <matplotlib.image.AxesImage at 0x7ded250>
421+
vxs, vys = registration.velocityfield(reg, ref.shape[:2], method='bilinear')
422+
vxs = vxs * ref.shape[1]
423+
vys = vys * ref.shape[0]
369424

370-
@savefig gen-registration-vel-mag.png align=center
371-
In [31]: title('Velocity field magnitude')
372-
Out[31]: <matplotlib.text.Text at 0x3193ad0>
425+
figure()
426+
imshow(np.abs(vxs + 1j*vys), cmap=cm.hot)
427+
title('Velocity field magnitude')

0 commit comments

Comments
 (0)