Function iaopentransf

Synopse

Open transform.

  • y = iaopentransf(f, type='OCTAGON', n=65535, Bc=ia_secross(), Buser=ia_secross())
    • y: Image
    • f: Image
    • type: String Disk family: 'OCTAGON', 'CHESSBOARD', 'CITY-BLOCK', 'LINEAR-V', 'LINEAR-H', 'LINEAR-45R', 'LINEAR-45L', 'USER'.
    • n: Double Maximum disk radii.
    • Bc: Structuring Element Connectivity for the reconstructive opening. Used if '-REC' suffix is appended in the 'type' string.
    • Buser: Structuring Element User disk, used if 'type' is 'USER'.
01. from numpy import *
02. from string import find, upper
03. from iasecross import iasecross
04. 
05. def iaopentransf(f, type='OCTAGON', n=65535, Bc=iasecross(), Buser=iasecross()):
06.     from iaisbinary import iaisbinary
07.     from iabinary import iabinary
08.     from iaisequal import iaisequal
09.     from iaopen import iaopen
10.     from iasesum import iasesum
11.     from iasedisk import iasedisk
12.     from iaaddm import iaaddm
13.     from iagray import iagray
14.     from iagrain import iagrain
15.     from ialabel import ialabel
16. 
17.     assert iaisbinary(f),'Error: input image is not binary'
18.     type = upper(type)
19.     rec_flag = find(type,'-REC')
20.     if rec_flag != -1:
21.         type = type[:rec_flag] # remove the -rec suffix
22.     flag = not ((type == 'OCTAGON')  or
23.                 (type == 'CHESSBOARD') or
24.                 (type == 'CITY-BLOCK'))
25.     if not flag:
26.         n  = min(n,min(f.shape))
27.     elif  type == 'LINEAR-H':
28.         se = iabinary([1, 1, 1])
29.         n  = min(n,f.shape[1])
30.     elif  type =='LINEAR-V':
31.         se = iabinary([[1],[1],[1]])
32.         n  = min(n,f.shape[0])
33.     elif  type == 'LINEAR-45R':
34.         se = iabinary([[0, 0, 1],[0, 1, 0],[1, 0, 0]])
35.         n  = min(n,min(f.shape))
36.     elif  type == 'LINEAR-45L':
37.         se = iabinary([[1, 0, 0],[0, 1, 0],[0, 0, 1]])
38.         n  = min(n,min(f.shape))
39.     elif  type == 'USER':
40.         se = Buser
41.         n  = min(n,min(f.shape))
42.     else:
43.         print 'Error: only accepts OCTAGON, CHESSBOARD, CITY-BLOCK, LINEAR-H, LINEAR-V, LINEAR-45R, LINEAR-45L, or USER as type, or with suffix -REC.'
44.         return []
45.     k = 0
46.     y = uint16(zeros(f.shape))
47.     a = iabinary([1])
48.     z = iabinary([0])
49.     while not ( iaisequal(a,z) or (k>=n)):
50.         print 'processing r=',k
51.         if flag:
52.             a = iaopen(f,iasesum(se,k))
53.         else:
54.             a = iaopen(f,iasedisk(k,'2D',type))
55.         y = iaaddm(y, iagray(a,'uint16',1))
56.         k = k+1
57.     if rec_flag != -1:
58.         y = iagrain( ialabel(f,Bc),y,'max')
59. 
60.     return y

Description

Compute the open transform of a binary image. The value of the pixels in the open transform gives the largest radii of the disk plus 1, where the open by it is not empty at that pixel. The disk sequence must satisfy the following: if r > s, rB is sB-open, i.e. rB open by sB is equal rB. Note that the Euclidean disk does not satisfy this property in the discrete grid. This function also computes the reconstructive open transform by adding the suffix '-REC' in the 'type' parameter.

Examples

Example 1

01. from ia870 import iaopentransf
02. from ia870 import iabinary
03. from ia870 import iasecross
04. 
05. f = iabinary([
06.               [0,0,0,0,0,0,0,0],
07.               [0,0,1,1,1,1,0,0],
08.               [0,0,1,1,1,1,1,0],
09.               [0,1,0,1,1,1,0,0],
10.               [1,1,0,0,0,0,0,0]])
11. print iaopentransf( f, 'city-block')
12. print iaopentransf( f, 'linear-h')
13. print iaopentransf( f, 'linear-45r')
14. print iaopentransf( f, 'user',10,iasecross(),iabinary([0,1,1]))
15. print iaopentransf( f, 'city-block-rec')
processing r= 0
processing r= 1
processing r= 2
processing r= 3
processing r= 4
[[0 0 0 0 0 0 0 0]
 [0 0 1 2 2 2 0 0]
 [0 0 2 2 2 2 2 0]
 [0 1 0 2 2 2 0 0]
 [1 1 0 0 0 0 0 0]]
processing r= 0
processing r= 1
processing r= 2
processing r= 3
processing r= 4
processing r= 5
processing r= 6
processing r= 7
[[0 0 0 0 0 0 0 0]
 [0 0 2 2 2 2 0 0]
 [0 0 3 3 3 3 3 0]
 [0 1 0 2 2 2 0 0]
 [2 2 0 0 0 0 0 0]]
processing r= 0
processing r= 1
processing r= 2
processing r= 3
processing r= 4
[[0 0 0 0 0 0 0 0]
 [0 0 1 4 1 2 0 0]
 [0 0 4 1 2 1 1 0]
 [0 4 0 2 1 1 0 0]
 [4 1 0 0 0 0 0 0]]
processing r= 0
processing r= 1
processing r= 2
processing r= 3
processing r= 4
[[0 0 0 0 0 0 0 0]
 [0 0 4 4 4 4 0 0]
 [0 0 5 5 5 5 5 0]
 [0 1 0 3 3 3 0 0]
 [2 2 0 0 0 0 0 0]]
processing r= 0
processing r= 1
processing r= 2
processing r= 3
processing r= 4
[[ 0.  0.  0.  0.  0.  0.  0.  0.]
 [ 0.  0.  2.  2.  2.  2.  0.  0.]
 [ 0.  0.  2.  2.  2.  2.  2.  0.]
 [ 0.  1.  0.  2.  2.  2.  0.  0.]
 [ 1.  1.  0.  0.  0.  0.  0.  0.]]

Example 2

1. f=adreadgray('numbers.tif') > 0
2. adshow(f)
3. g=iaopentransf(f,'OCTAGON')
4. adshow(g)
*** Exception while evaluating code:
Sandbox thread timeout [50 s]

Example 3

01. from ia870 import iasedisk
02. from ia870 import iaopen
03. from ia870 import iacmp
04. from ia870 import iais
05. 
06. b=iasedisk(3,'2D','OCTAGON')
07. g1=iaopen(f,b)
08. adshow(g1)
09. g2 = g > 3
10. print (g1 == g2).all()
------------------------------------------------------------
*** Exception while evaluating code:
  File "<string>", line 9, in <module>
NameError: name 'g' is not defined

------------------------------------------------------------

Equation

Limitations

As this function may take a long time to execute, there is a printout notifying the status of the execution. The radii of the disk is informed for each open executed. Due to the behavior of the structuring element in the frame of the image, one may want to insert a zero border around the image.