Morph-M Python - Python Active Windows » History » Revision 2
Revision 1 (Serge Koudoro, 10/23/2009 04:19 PM) → Revision 2/4 (Serge Koudoro, 10/23/2009 04:22 PM)
h1. Morph-M Python - Python Active Windows
h2{color:#8B0000;background:#ddd}. Introduction
*What Active windows does ?*
Sometimes, you do not need to work on the whole image. Active window is here to help you ! Define 1,2,3 or more active window on your image, then get all these pixel and work with them.
Example with images are better than words, so try all example.
h2{color:#8B0000;background:#ddd}. Example: Construct 3D volume with image stack
h2{color:#8B0000;background:#ddd}. Example : 1: Build 1 image with some part of 2 different images
| !{width:400px}http://morphm.ensmp.fr/attachments/84/active_windows_1.PNG! |<pre><code class="ruby">
import morphee as mp
def combineImage(ImIn1,ImIn2):
#we activate the same window on each image (Red windows)
ImIn1.setActiveWindow(201,14,1,30,30,1)
ImIn2.setActiveWindow(201,14,1,30,30,1)
#copy only active window
mp.ImCopy(ImIn1,ImIn2)
# remove active window so all image is actived
ImIn1.resetActiveWindow()
ImIn2.resetActiveWindow()
#Now, we activate the same window on each image(Blue windows)
ImIn1.setActiveWindow(45,73,0,50,40,1)
ImIn2.setActiveWindow(45,73,0,50,40,1)
#copy only active window
mp.ImCopy(ImIn1,ImIn2)
#remove active window so all image is actived
ImIn1.resetActiveWindow()
ImIn2.resetActiveWindow()
return ImIn2
if __name__=='__main__':
#Read im1 and im2.
im1=mp.fileRead(images_dir+ "\\Gray\\tools.png")
im2=mp.fileRead(images_dir+ "\\Gray\\tw.png")
final_image = combineImage(im1,im2)
#write result
mp.fileWrite(final_image,"D:\\final_image.png")
</code></pre>|
h2{color:#8B0000;background:#ddd}. Example : 2: Mathematical Morphology operation on Active window
| !{width:400px}http://morphm.ensmp.fr/attachments/85/active_windows_2.PNG! |<pre><code class="ruby">
import morphee as mp
def ErodeImagePart(im):
imEro = mp.getSame(im)
#create structuring element
nl = mp.NeighborList.neighborsSquare2D
#we activate the same window on each image (Red box)
im.setActiveWindow(1,1,1,66,66,1)
imEro.setActiveWindow(1,1,1,66,66,1)
#Erode active window
mp.ImErode( im, mp.HomotheticSE(nl,10), imEro)
# remove active window so all image is actived
im.resetActiveWindow()
imEro.resetActiveWindow()
return imEro
if __name__=='__main__':
#Read image
im=mp.fileRead(images_dir+ "\\Bin\\balls.png")
final_image = ErodeImagePart(im)
#write result
mp.fileWrite(final_image,"D:\\final_image.png")
</code></pre>|
h2{color:#8B0000;background:#ddd}. Example : 3: Set image Boundary with Active window
| !{width:400px}http://morphm.ensmp.fr/attachments/86/active_windows_3.png! |<pre><code class="ruby">
import morphee as mp
def set_boundary(im, depth, value = 255):
for i in [(0,0,0),(im.wxSize-depth, 0, 0)]:
im.setActiveWindow(i[0], i[1], i[2], depth,
im.wySize,im.wzSize)
mp.ImSetConstant(im, value)
im.resetActiveWindow()
for i in [(0, 0, 0),(0, im.wySize-depth, 0)]:
im.setActiveWindow(i[0], i[1], i[2], im.wxSize,
depth,im.wzSize)
mp.ImSetConstant(im, value)
im.resetActiveWindow()
if im.getZSize() == 3:
for i in [(0, 0, 0),(0, 0, im3d.wzSize-depth)]:
im.setActiveWindow(i[0], i[1], i[2], im.wxSize,
im.wySize,depth)
mp.ImSetConstant(im, value)
im.resetActiveWindow()
return im
if __name__=='__main__':
#Read image
im=mp.fileRead(images_dir+ "\\Gray\\tw.png")
final_image = set_boundary(im, 50, 0):
#write result
mp.fileWrite(final_image,"D:\\final_image.png")
</code></pre>|