Function iaadd4dil

namespace:morph
page:iaadd4dil

Synopse

Addition for dilation

  • a = iaadd4dil(f, c)
    • a: Image
    • f: Image Image
    • c: Image Constant
01. from numpy import *
02. 
03. def iaadd4dil(f, c):
04.     from ialimits import ialimits
05. 
06.     if not c:
07.        return f
08.     if f.dtype == 'float64':
09.         y = f + c
10.     else:
11.         y = asarray(f,int64) + c
12.         k1,k2 = ialimits(f)
13.         y = ((f==k1) * k1) + ((f!=k1) * y)
14.         y = clip(y,k1,k2)
15.     a = y.astype(f.dtype)
16.     return a

Examples

With "float64" data type

1. import ia870 as ia
2. 
3. f = array([-inf, -30, 4, 33, inf])
4. print 'f.dtype', f.dtype
5. print 'f:',f
6. print 'f + 3:',ia.iaadd4dil(f,3)
7. print 'f - 10',ia.iaadd4dil(f,-10)
f.dtype float64
f: [-inf -30.   4.  33.  inf]
f + 3: [-inf -27.   7.  36.  inf]
f - 10 [-inf -40.  -6.  23.  inf]

With "int32" data type

1. a = arange(8).astype('int32')
2. k1,k2 = ia.ialimits(a)
3. f = array([k1,-3,0,5,10,k2]).astype('int32')
4. print 'f.dtype', f.dtype
5. print 'f:',f
6. print 'f + 3:',ia.iaadd4dil(f,3)
7. print 'f - 10',ia.iaadd4dil(f,-10)
f.dtype int32
f: [-2147483647          -3           0           5          10  2147483647]
f + 3: [-2147483647           0           3           8          13  2147483647]
f - 10 [-2147483647         -13         -10          -5           0  2147483637]

With 'uint8' data type

1. a = arange(8).astype('uint8')
2. k1,k2 = ia.ialimits(a)
3. f = array([k1,5,10,100,k2]).astype('uint8')
4. print 'f.dtype', f.dtype
5. print 'f:',f
6. print 'f + 3:',ia.iaadd4dil(f,3)
7. print 'f + 250',ia.iaadd4dil(f,250)
8. print 'f - 10',ia.iaadd4dil(f,-10)
f.dtype uint8
f: [  0   5  10 100 255]
f + 3: [  0   8  13 103 255]
f + 250 [  0 255 255 255 255]
f - 10 [  0   0   0  90 245]

Equation