Function iaserot

namespace:morph
page:iaserot

Synopse

Rotate a structuring element.

  • BROT = iaserot(B, theta=45, DIRECTION="CLOCKWISE")
    • BROT: Structuring Element
    • B: Structuring Element
    • theta: Double Degrees of rotation. Available values are multiple of 45 degrees.
    • DIRECTION: String 'CLOCKWISE' or ' ANTI-CLOCKWISE'.
01. from numpy import *
02. from string import upper
03. 
04. def iaserot(B, theta=45, DIRECTION="CLOCKWISE"):
05.     from iamat2set import iamat2set
06.     from iabinary import iabinary
07.     from iaset2mat import iaset2mat
08. 
09. 
10.     DIRECTION = upper(DIRECTION)
11.     if DIRECTION == "ANTI-CLOCKWISE":
12.        theta = -theta
13.     SA = iamat2set(B)
14.     theta = pi * theta/180
15.     (y,v)=SA
16.     if len(y)==0: return iabinary([0])
17.     x0 = y[:,1] * cos(theta) - y[:,0] * sin(theta)
18.     x1 = y[:,1] * sin(theta) + y[:,0] * cos(theta)
19.     x0 = int32((x0 +0.5)*(x0>=0) + (x0-0.5)*(x0<0))
20.     x1 = int32((x1 +0.5)*(x1>=0) + (x1-0.5)*(x1<0))
21.     x = transpose(array([transpose(x1),transpose(x0)]))
22.     BROT = iaset2mat((x,v))
23. 
24.     return BROT

Description

iaserot rotates a structuring element B of an angle theta.

Examples

Example 1

01. from ia870 import iaserot
02. from ia870 import iaimg2se
03. from ia870 import iabinary
04. from ia870 import iaseshow
05. 
06. 
07. b = iaimg2se( iabinary([[0, 0, 0], [0, 1, 1], [0, 0, 0]]));
08. adshow(iaseshow(b,'EXPAND'))
09. adshow(iaseshow( iaserot(b),'EXPAND'))
10. adshow(iaseshow( iaserot(b,45,'ANTI-CLOCKWISE'),'EXPAND'))

Equation

where

Reflection is given by

Limitations

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