[mmseline] [Up] [mmseshow] Structuring Elements

mmserot
Rotate a structuring element.

Synopsis

BROT = mmserot( B, theta = 45, DIRECTION = "CLOCKWISE" )

Implemented in Python.

Input

B Structuring Element
theta Double

Degrees of rotation. Available values are multiple of 45 degrees.

Default: 45

DIRECTION String

'CLOCKWISE' or ' ANTI-CLOCKWISE'.

Default: "CLOCKWISE"

Output

Description

mmserot rotates a structuring element B of an angle theta.

Examples

>>> b = mmimg2se(mmbinary([[0, 0, 0], [0, 1, 1], [0, 0, 0]]));

              
>>> mmseshow(b)
array([0, 1, 1],'1')
>>> mmseshow(mmserot(b))
array([[0, 0, 0],
       [0, 1, 0],
       [0, 0, 1]],'1')
>>> mmseshow(mmserot(b,45,'ANTI-CLOCKWISE'))
        
array([[0, 0, 1],
       [0, 1, 0],
       [0, 0, 0]],'1')

Equation

where
Reflection is given by

Limitations

Only 2-D structuring elements can be rotated. The rotation angles allowed are multiples of 45 degrees.

Source Code

def mmserot(B, theta=45, DIRECTION="CLOCKWISE"):
    from string import upper
    from Numeric import array, sin, cos, transpose
    from Numeric import cos, sin, pi, concatenate, transpose, array
    DIRECTION = upper(DIRECTION)            
    if DIRECTION == "ANTI-CLOCKWISE":
       theta = -theta
    SA = mmmat2set(B)
    theta = pi * theta/180
    (y,v)=SA
    if len(y)==0: return mmbinary([0])
    x0 = y[:,1] * cos(theta) - y[:,0] * sin(theta)
    x1 = y[:,1] * sin(theta) + y[:,0] * cos(theta)
    x0 = int32((x0 +0.5)*(x0>=0) + (x0-0.5)*(x0<0))
    x1 = int32((x1 +0.5)*(x1>=0) + (x1-0.5)*(x1<0))
    x = transpose(array([transpose(x1),transpose(x0)]))
    BROT = mmset2mat((x,v))
    return BROT
    

See also

mmfreedom Control automatic data type conversion.
mmseshow Display a structuring element as an image.
mmimg2se Create a structuring element from a pair of images.
[mmseline] [Up] [mmseshow] Python