Project

General

Profile

Actions

Morph-M Python - Neighborhoods

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 ยท 2 revisions