Project

General

Profile

Actions

Morph-M Python - Neighborhoods » History » Revision 1

Revision 1/2 | Next »
Serge Koudoro, 10/23/2009 05:03 PM


Morph-M Python - Neighborhood

Neighborhoods

The most useful constructs for complex algorithms are Neighborhoods:

# this is the almost-complete code for a dilation:
neighb=createNeighborhood(imIn, NeighborList.neighborsHex2D)
it=imIn.imageData()
out=imOut.imageData()
while it.isNotFinished():
       neighb.setCenter(it)
       out.setPixel( max(neighb) )
       it.next()
       out.next()

max is a Python function that return the maximum value of any "iterable" object.

NeighborhoodIterators are also available:

neighb=createNeighborhood(imIn, NeighborList.neighborsHex2D)
it=imIn.imageData()
while it.isNotFinished():
      neighb.setCenter(it)
      nit=neighb.__iter__()
      while nit.isNotFinished():
          print nit.getOffset() , nit.getPixel()
          nit.next()
      it.next()

The getOffset is available for complex algorithms, as well as the getPixel.

Updated by Serge Koudoro about 15 years ago · 1 revisions