Project

General

Profile

Actions

Morph-M Python - Python Active Windows » History » Revision 2

« Previous | Revision 2/4 (diff) | Next »
Serge Koudoro, 10/23/2009 04:22 PM


Morph-M Python - Python Active Windows

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 images are better than words, so try all example.

Example: Construct 3D volume with image stack

Example : Build 1 image with some part of 2 different images

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")

Example : Mathematical Morphology operation on Active window

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")

Example : Set image Boundary with Active window

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")

Updated by Serge Koudoro about 15 years ago · 2 revisions