Morph-M Python - Neighborhoods » History » Version 2
Serge Koudoro, 10/23/2009 05:04 PM
1 | 2 | Serge Koudoro | h1. Morph-M Python - Neighborhoods |
---|---|---|---|
2 | 1 | Serge Koudoro | |
3 | h2{color:#8B0000;background:#ddd}. Neighborhoods |
||
4 | |||
5 | The most useful constructs for complex algorithms are Neighborhoods: |
||
6 | |||
7 | <pre><code class="ruby"> |
||
8 | # this is the almost-complete code for a dilation: |
||
9 | neighb=createNeighborhood(imIn, NeighborList.neighborsHex2D) |
||
10 | it=imIn.imageData() |
||
11 | out=imOut.imageData() |
||
12 | while it.isNotFinished(): |
||
13 | neighb.setCenter(it) |
||
14 | out.setPixel( max(neighb) ) |
||
15 | it.next() |
||
16 | out.next() |
||
17 | </code></pre> |
||
18 | |||
19 | _max_ is a Python function that return the maximum value of any *"iterable"* object. |
||
20 | |||
21 | NeighborhoodIterators are also available: |
||
22 | |||
23 | <pre><code class="ruby"> |
||
24 | neighb=createNeighborhood(imIn, NeighborList.neighborsHex2D) |
||
25 | it=imIn.imageData() |
||
26 | while it.isNotFinished(): |
||
27 | neighb.setCenter(it) |
||
28 | nit=neighb.__iter__() |
||
29 | while nit.isNotFinished(): |
||
30 | print nit.getOffset() , nit.getPixel() |
||
31 | nit.next() |
||
32 | it.next() |
||
33 | </code></pre> |
||
34 | |||
35 | The _getOffset_ is available for complex algorithms, as well as the _getPixel._ |