Function iaseunion

Synopse

Union of structuring elements

  • B = iaseunion(B1, B2)
    • B: Structuring Element
    • B1: Structuring Element
    • B2: Structuring Element
01. from numpy import *
02. 
03. def iaseunion(B1, B2):
04.     from ialimits import ialimits
05. 
06.     if B1.dtype != B2.dtype:
07.         print 'B1=',B1
08.         print 'B2=',B2
09.     assert B1.dtype == B2.dtype, \
10.       'iaseunion: Cannot have different datatypes: \
11.       %s and %s' % (str(B1.dtype), str(B2.dtype))
12.     type1 = B1.dtype
13.     #if len(B1) == 0: return B2
14.     if len(B1.shape) == 1: B1 = B1[newaxis,:]
15.     if len(B2.shape) == 1: B2 = B2[newaxis,:]
16.     if B1.shape <> B2.shape:
17.         inf = ialimits(B1)[0]
18.         h1,w1 = B1.shape
19.         h2,w2 = B2.shape
20.         H,W = max(h1,h2),max(w1,w2)
21.         Hc,Wc = (H-1)/2,(W-1)/2    # center
22.         BB1,BB2 = asarray(B1),asarray(B2)
23.         B1, B2  = inf * ones((H,W)), inf *ones((H,W))
24.         dh1s , dh1e = (h1-1)/2 , (h1-1)/2 + (h1+1)%2 # deal with even and odd dimensions
25.         dw1s , dw1e = (w1-1)/2 , (w1-1)/2 + (w1+1)%2
26.         dh2s , dh2e = (h2-1)/2 , (h2-1)/2 + (h2+1)%2
27.         dw2s , dw2e = (w2-1)/2 , (w2-1)/2 + (w2+1)%2
28.         B1[ Hc-dh1s : Hc+dh1e+1  ,  Wc-dw1s : Wc+dw1e+1 ] = BB1
29.         B2[ Hc-dh2s : Hc+dh2e+1  ,  Wc-dw2s : Wc+dw2e+1 ] = BB2
30.     B = maximum(B1,B2).astype(type1)
31.     return B

Description

iaseunion creates a structuring element from the union of two structuring elements.

Examples

Example 1

01. from ia870 import iaseunion
02. from ia870 import iaseline
03. from ia870 import iaseshow
04. from ia870 import iasedisk
05. 
06. b1 = iaseline(5)
07. adshow( iaseshow(b1,'EXPAND'))
08. b2 = iasedisk(2)
09. adshow( iaseshow(b2,'EXPAND'))
10. b3 = iaseunion(b1,b2)
11. adshow( iaseshow(b3,'EXPAND'))

1. f = array([-inf, -8., 0., 3., inf])
2. g = array([0., 1., 2.])
3. print iaseunion(f,g)
[[-inf   0.   1.   3.  inf]]

Equation