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¶
|
Example : Mathematical Morphology operation on Active window¶
|
Example : Set image Boundary with Active window¶
|
Of active window, coordinates and offsets¶
We have already seen how to create and use an Active Window.However, we can notice that an active Window defines a new system of coordinates.
That's why, it could be interesting to use offsets and Coordinates in this new system.
Two operations can be defined:
- coordinates to offset transformation
- offset to coordinates transformation
coordinates to offset¶
Let's consider the following example:
import morphee as mp
# I create a new image, size: 200x200x1
imIn = mp.createImage(mp.dataCategory.dtScalar, mp.scalarDataType.sdtUINT8)
imIn.setSize(200, 200)
imIn.allocateImage()
# Let's get an offset from a pixel inside the image:
print "offset at (50, 23):", mp.GetOffsetFromCoords( imIn, (50, 23, 0) )
# Let's define an active Window now !
# It begins at (50, 20, 0), length : (10, 10, 1)
imIn.setActiveWindow(50, 20, 0, 10, 10, 1)
# Let's get an offset inside the active Window
print "Active Window, offset at (0, 3):", mp.GetOffsetFromWindowCoords( imIn, (0, 3, 0) )
If we try to launch the previous example, we'll get as expected :
offset at (50, 23): 4650 Active Window, offset at (0, 3): 4650
From the previous example, we can notice that an offset is a global measure ! It means that your offset doesn't change when an active window is set.
You just need to remember that your coordinates change with an active Window but not your offset
offset to coordinates¶
We can now define the inverse function wich transforms an active window into coords.
The following code is quite simple:
import morphee as mp
# I create a new image, size: 200x200x1
imIn = mp.createImage(mp.dataCategory.dtScalar, mp.scalarDataType.sdtUINT8)
imIn.setSize(200, 200)
imIn.allocateImage()
# Let's get coords from an offset inside the image:
print "coords without active window:", mp.GetCoordsFromOffset( imIn, 4258 )
# Let's define an active Window now !
# It begins at (50, 20, 0), length : (10, 10, 1)
imIn.setActiveWindow(50, 20, 0, 10, 10, 1)
# Let's get coords inside the active Window
print "coords with active window:", mp.GetRelativeCoordsFromOffset( imIn, 4258 )
It will produce the following output:
coords without active window: (58, 21, 0) coords with active window: (8, 1, 0)
Unlike the first operation (coordinates to offset transformation), the offset to coordinates operation will check if
your offset is inside the image. As far as active window are concerned, it means that if you have set an active window,
you can't get coords out of your active window.
For example, this code will return an error:
import morphee as mp
# I create a new image, size: 200x200x1
imIn = mp.createImage(mp.dataCategory.dtScalar, mp.scalarDataType.sdtUINT8)
imIn.setSize(200, 200)
imIn.allocateImage()
# Let's get coords from a pixel inside the image:
# 4258 = 21 * 200 + 58 -> (58, 21, 0)
print "coords without active window:", mp.GetCoordsFromOffset( imIn, 4258 )
# Let's define an active Window now !
# It begins at (50, 10, 0), length : (10, 10, 1)
imIn.setActiveWindow(50, 10, 0, 10, 10, 1)
# Let's get try to get coords outside of the active Window,
# (58, 21, 0) is out of the active window
# it will return an error !
print "coords with active window, error:", mp.GetRelativeCoordsFromOffset( imIn, 4258 )
The error:
coords without active window: (58, 21, 0) coords with active window, error: Traceback (most recent call last): File "./test.py", line 19, in <module> print "coords with active window, error:", mp.GetRelativeCoordsFromOffset( imIn, 4258 ) RuntimeError: t_GetRelativeCoordsFromOffset : result outside the window -- Morphee backtrace:
Updated by Jean Felder almost 15 years ago · 4 revisions