Actions
Morph-M Python - Python Pixel Manipulation » History » Revision 2
« Previous |
Revision 2/3
(diff)
| Next »
Serge Koudoro, 10/26/2009 01:51 PM
Morph-M Python - Python Pixel Manipulation¶
Introduction¶
Although the speed of an algorithm entirely written in MorpheePython is usually abysmal, it is very convenient for rapid development. Most functions that operate directly on pixels have been ported from C++.
From the image¶
Two functions are available to access pixel data from an image: getPixel (possibly also known as pixelFromOffset) and setPixel. They mirror the C++ method pixelFromOffset. These functions are not currently range-checked.
Example Gray Image | Example Color Image |
---|---|
|
|
Iterators¶
Iterators also have getPixel and setPixel. They also have the getOffset that is used often in morphological algorithms.
Example Iterator:
def MyErosion( imIn, nl ,imOut ):
""" Personnal erosion with iterator """
itIn = imIn.imageData()
itOut = imOut.imageData()
neighb = createNeighborhood( imIn, nl )
while itIn.isNotFinished() and itOut.isNotFinished():
neighb.setCenter( itIn )
# "min" work with iterator
itOut.setPixel( min( neighb.imageData() ) )
# Do not forget!
itIn.next()
itOut.next()
if __name__=='__main__':
im = fileRead(images_dir+"/Gray/foreman.png")
imEro = getSame(im)
imEroRef = getSame(im)
nl = NeighborList.neighborsSquare2D
MyErosion( im, nl, imEro )
ImErode( im, nl, imEroRef)
assert(isEqual(imEro, imEroRef))
Iterators with Mask¶
Updated by Serge Koudoro about 15 years ago · 2 revisions