[mmunion] [Up] [mmsebox] Structuring Elements

mmimg2se
Create a structuring element from a pair of images.

Synopsis

B = mmimg2se( fd, FLAT = "FLAT", f = None )

Implemented in Python.

Input

fd Image Binary image.

The image is in the matrix format where the origin (0,0) is at the matrix center.

FLAT String

'FLAT' or 'NON-FLAT'.

Default: "FLAT"

f Image Unsigned gray-scale (uint8 or uint16), signed (int32) or binary image.

Default: None

Description

mmimg2se creates a flat structuring element B from the binary image fd or creates a non-flat structuring element b from the binary image fd and the gray-scale image f. fd represents the domain of b and f represents the image of the points in fd.

Examples

Let us apply mmimg2se to create structuring elements. In the example below, the flat 3x3 diamond is created.

>>> a = mmimg2se(mmbinary([
  [0,1,0],
  [1,1,1],
  [0,1,0]]))

              
>>> print mmseshow(a)
[[0 1 0]
 [1 1 1]
 [0 1 0]]

In this next example, the image sizes are even. Note the origin of the structuring element.
>>> b = mmbinary([
  [0,1,1,1],
  [1,1,1,0]])

              
>>> b1 = mmimg2se(b)

              
>>> print mmseshow(b1)
[[0 0 0 0 0]
 [0 0 1 1 1]
 [0 1 1 1 0]]
In the example below, a non-flat diamond is created.
>>> c = mmbinary([
  [0,1,0],
  [1,1,1],
  [0,1,0]])

              
>>> d = int32([
  [0,0,0],
  [0,1,0],
  [0,0,0]])

              
>>> e = mmimg2se(c,'NON-FLAT',d)

              
>>> print mmseshow(e)
[[-2147483647           0 -2147483647]
 [          0           1           0]
 [-2147483647           0 -2147483647]]

Equation

Flat structuring element:
Non-flat structuring element:
H and W are the number of rows and columns of f, respectively.

Source Code

def mmimg2se(fd, FLAT="FLAT", f=None):
    from string import upper
    from Numeric import choose, ones
    assert mmisbinary(fd),'First parameter must be binary'
    FLAT = upper(FLAT)
    if FLAT == 'FLAT':
        return mmseshow(fd)
    else:
        B = choose(fd, (mmlimits(int32([0]))[0]*ones(fd.shape),f) )
    B = mmseshow(int32(B),'NON-FLAT')
    return B
    

See also

mmfreedom Control automatic data type conversion.
mmsebox Create a box structuring element.
mmsecross Diamond structuring element and elementary 3x3 cross.
mmsedisk Create a disk or a semi-sphere structuring element.
mmseline Create a line structuring element.
mmseshow Display a structuring element as an image.
mmdil Dilate an image by a structuring element.

See also

mmfreedom Control automatic data type conversion.
mmsecross Diamond structuring element and elementary 3x3 cross.
mmseshow Display a structuring element as an image.
mmdil Dilate an image by a structuring element.
mmmat2set Converts image representation from matrix to set
[mmunion] [Up] [mmsebox] Python