Function iadil

Synopse

Dilate an image by a structuring element.

  • y = iadil(f, b=ia_secross(NULL))
    • y: Image
    • f: Image
    • b: Structuring Element
 1 from numpy import *
 2 
 3 def iadil(f, b=None):
 4     from iamat2set import iamat2set
 5     from ialimits import ialimits
 6     from iaisbinary import iaisbinary
 7     from iaintersec import iaintersec
 8     from iagray import iagray
 9     from iaadd4dil import iaadd4dil
10     from iasecross import iasecross
11 
12     if b is None: b = iasecross()
13 
14     if len(f.shape) == 1: f = f[newaxis,:]
15     h,w = f.shape
16     x,v = iamat2set(b)
17     if len(x)==0:
18         y = (ones((h,w)) * ialimits(f)[0]).astype(f.dtype)
19     else:
20         if iaisbinary(v):
21             v = iaintersec( iagray(v,'int32'),0)
22         mh,mw = max(abs(x)[:,0]),max(abs(x)[:,1])
23         y = (ones((h+2*mh,w+2*mw)) * ialimits(f)[0]).astype(f.dtype)
24         for i in range(x.shape[0]):
25             if v[i] > -2147483647:
26                 y[mh+x[i,0]:mh+x[i,0]+h, mw+x[i,1]:mw+x[i,1]+w] = maximum(
27                     y[mh+x[i,0]:mh+x[i,0]+h, mw+x[i,1]:mw+x[i,1]+w], iaadd4dil(f,v[i]))
28         y = y[mh:mh+h, mw:mw+w]
29 
30     return y

Description

iadil performs the dilation of image f by the structuring element b. Dilation is a neighbourhood operator that compares locally b with f, according to an intersection rule. Since Dilation is a fundamental operator to the construction of all other morphological operators, it is also called an elementary operator of Mathematical Morphology. When f is a gray-scale image, b may be a flat or non-flat structuring element.

Examples

Example 1

 1 import numpy as np
 2 from ia870 import iadil
 3 from ia870 import iabinary
 4 
 5 f=iabinary([
 6    [0, 0, 0, 0, 0, 0, 1],
 7    [0, 1, 0, 0, 0, 0, 0],
 8    [0, 0, 0, 0, 1, 0, 0]])
 9 b=iabinary([1, 1, 0])
10 print iadil(f,b).astype('int')
11 f=uint8([
12    [ 0,   1,  2, 50,  4,  5],
13    [ 2,   3,  4,  0,  0,  0],
14    [12, 255, 14, 15, 16, 17]])
15 print iadil(f,b)
[[0 0 0 0 0 1 1]
 [1 1 0 0 0 0 0]
 [0 0 0 1 1 0 0]]
[[  1   2  50  50   5   5]
 [  3   4   4   0   0   0]
 [255 255  15  16  17  17]]

Example 2

 1 from ia870 import iaimg2se
 2 from ia870 import iagradm
 3 from ia870 import iagshow
 4 import ia636 as ia
 5 
 6 f=iabinary( adreadgray('blob.tif'))
 7 bimg=iabinary( adreadgray('blob1.tif'))
 8 b=iaimg2se(bimg)
 9 adshow(f)
10 adshow( iadil(f,b))
11 adshow( iagshow(iadil(f,b),iagradm(f)))

Example 3

1 from ia870 import iasedisk
2 
3 f=adreadgray('pcb_gray.tif')
4 b=iasedisk(5)
5 fdil = iadil(f,b)
6 adshow(f)
7 adshow(fdil)
8 adshow(mmsurf(f))
9 adshow(mmsurf(fdil))

Using iadil com mmsedisk

1 from ia870 import iasecross
2 
3 f = iabinary(np.ones((5,4)))
4 f[2:4,2:4] = 0
5 print 'f=\n',
6 print iadil(f,iasecross())
7 print iadil(f,mmsecross())
f=
[[ True  True  True  True]
 [ True  True  True  True]
 [ True  True  True  True]
 [ True  True  True  True]
 [ True  True  True  True]]
------------------------------------------------------------
*** Exception while evaluating code:
  File "<string>", line 7, in <module>
  File "/awmedia/www/packages/ia870/iadil.py", line 17, in iadil
    x,v = iamat2set(b)
  File "/awmedia/www/packages/ia870/iamat2set.py", line 8, in iamat2set
    if len(A.shape) == 1: A = A[newaxis,:]
AttributeError: 'str' object has no attribute 'shape'

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

Equation

Where