[mmseline] [Up] [mmseshow] | Structuring Elements |
Implemented in Python.
B | Structuring Element |
theta | Double Degrees of rotation. Available values are multiple of 45 degrees. Default:
|
DIRECTION | String 'CLOCKWISE' or ' ANTI-CLOCKWISE'. Default:
|
BROT | Structuring Element |
mmserot rotates a structuring element
B
of an angle
theta
.
>>> 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')
Only 2-D structuring elements can be rotated. The rotation angles allowed are multiples of 45 degrees.
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
[mmseline] [Up] [mmseshow] | ![]() |
Copyright (c) 2003, Roberto A. Lotufo, UNICAMP-University of Campinas; Rubens C. Machado, CenPRA-Renato Archer Research Center. |