[mmsedisk] [Up] [mmserot] Structuring Elements

mmseline
Create a line structuring element.

Synopsis

B = mmseline( l = 3, theta = 0 )

Implemented in Python.

Input

l Double Non-negative integer.

Default: 3

theta Double

(degrees, clockwise)

Default: 0

Description

mmseline creates a structuring element B that is a line segment that has an extremity at the origin, length l and angle theta (0 degrees is east direction, clockwise). If l=0, it generates the origin.

Examples

>>> mmseshow(mmseline())
array([0, 0, 1, 1, 1],'1')
>>> b1 = mmseline(4,45)

              
>>> mmseshow(b1)
array([[0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 1, 0],
       [0, 0, 0, 0, 1]],'1')
>>> b2 = mmseline(4,-180)

              
>>> mmseshow(b2)
array([1, 1, 1, 1, 0, 0, 0],'1')
>>> a=mmtext('Line')

              
>>> b=mmdil(a,b1)

              
>>> mmshow(a)

              
>>> mmshow(b)
        

            
a b

Equation

Source Code

def mmseline(l=3, theta=0):
    from Numeric import pi, tan, cos, sin, sign, floor, arange, transpose, array, ones
    theta = pi*theta/180
    if abs(tan(theta)) <= 1:
        s  = sign(cos(theta))
        x0 = arange(0, l * cos(theta)-(s*0.5),s)
        x1 = floor(x0 * tan(theta) + 0.5)
    else:
        s  = sign(sin(theta))
        x1 = arange(0, l * sin(theta) - (s*0.5),s)
        x0 = floor(x1 / tan(theta) + 0.5)
    x = int32(transpose(array([x1,x0])))
    B = mmset2mat((x,mmbinary(ones((x.shape[1],1)))))
    return B
    

See also

mmfreedom Control automatic data type conversion.
mmsedisk Create a disk or a semi-sphere structuring element.
mmsebox Create a box structuring element.
mmsecross Diamond structuring element and elementary 3x3 cross.
mmimg2se Create a structuring element from a pair of images.
mmdil Dilate an image by a structuring element.
mmseshow Display a structuring element as an image.
[mmsedisk] [Up] [mmserot] Python