[pypy-commit] extradoc extradoc: add morphology to demo
hakanardo
noreply at buildbot.pypy.org
Thu Sep 13 16:04:56 CEST 2012
Author: Hakan Ardo <hakan at debian.org>
Branch: extradoc
Changeset: r4807:d4d870cec4eb
Date: 2012-09-13 16:01 +0200
http://bitbucket.org/pypy/extradoc/changeset/d4d870cec4eb/
Log: add morphology to demo
diff --git a/talk/dls2012/demo/demo.py b/talk/dls2012/demo/demo.py
--- a/talk/dls2012/demo/demo.py
+++ b/talk/dls2012/demo/demo.py
@@ -104,7 +104,58 @@
pause("Still a bit noisy, let's increase it even more.")
vim.type('6ggA<BS><BS><BS>200<ESC>:w<CR>', 0.2)
- pause("That's all!")
+ pause("Now, let us start designing an object detector. First step would\n"+
+ "be to implement dilation to get rid of small holes within\n"+
+ "the objects,")
+ with open('detect.py', 'w') as fd:
+ print >>fd, """
+from reloader import autoreload
+from io import view, viewsc
+
+def dilate(fg, r=1):
+ res = fg.new()
+ for y in xrange(fg.height):
+ for x in xrange(fg.width):
+ res[x, y] = fg[x, y]
+ for dx in xrange(-r, r+1):
+ for dy in xrange(-r, r+1):
+ res[x, y] = max(res[x, y], fg[x+dx, y+dy])
+ return res
+
+ at autoreload
+def find_objects(fg):
+ seg = dilate(fg, 3)
+ viewsc(seg, 'segments')
+
+"""
+ vim.send(':e detect.py<CR>')
+
+ pause('and to call it from our tracker.')
+ vim.send(':e analytics.py<CR>')
+ vim.type('5ggofrom detect import find_objects<ESC>')
+ vim.type('14ggofind_objects(fg)<ESC>:w<CR>')
+
+ pause("That's a bit slow, but this operation is separable, let's see\n"+
+ "if it is faster with two passes.")
+ vim.send(':e detect.py<CR>')
+ vim.type('6ggix<ESC>9ggix<ESC>jjdd')
+ vim.send('<<')
+ vim.type('ix<ESC>9wix<ESC>13wxxx', 0.2)
+ vim.type('VkkkkkyP6jx')
+ vim.type('15ggx7wcwxres<ESC>')
+ vim.type('jbbbcwdy<ESC>jhx9wx6wcwxres<ESC>3wxxxllli+dy<ESC>:w<CR>', 0.2)
+
+ pause("Now we need som erosion to thin out the objects again. Let's\n"+
+ "generalize dilate make it implement both dilation and erotion")
+ vim.type('5ggwcwmorph<ESC>$hi<BS><BS>, fn<ESC>')
+ vim.type('11gg7wcwfn<ESC>', 0.2)
+ vim.type('17gg7wcwfn<ESC>', 0.2)
+ vim.type('20ggOdef dilate(fg, r=1):<CR>return morph(fg, r, max)<CR>')
+ vim.type('<CR>def erode(fg, r=1):<CR>return morph(fg, r, min)<CR><ESC>')
+ vim.type('28ggwwierode(<ESC>A, 4)<ESC>:w<CR>')
+
+ pause("That's all! Feel free to make your own adjustments or (to quit),")
+
runner.kill()
if __name__ == '__main__':
More information about the pypy-commit
mailing list