Function iaimg2se

namespace:morph
page:iaimg2se

Synopse

Create a structuring element from a pair of images.

  • B = iaimg2se(fd, FLAT="FLAT", f=NULL)
    • B: Structuring Element
    • fd: Image The image is in the matrix format where the origin (0,0) is at the matrix center.
    • FLAT: String Structuring element: 'FLAT' or 'NON-FLAT'.
    • f: Image
01. from numpy import *
02. from string import upper
03. 
04. def iaimg2se(fd, FLAT="FLAT", f=None):
05.     from iaisbinary import iaisbinary
06.     from iaseshow import iaseshow
07.     from ialimits import ialimits
08. 
09.     fd = (fd > 0)
10.     #assert iaisbinary(fd),'First parameter must be binary'
11.     FLAT = upper(FLAT)
12.     if FLAT == 'FLAT':
13.         return iaseshow(fd)
14.     else:
15.         B = choose(fd, ( ialimits(int32([0]))[0]*ones(fd.shape),f) )
16.     B = iaseshow(int32(B),'NON-FLAT')
17. 
18.     return B

Description

iaimg2se creates a flat structuring element B from the binary image fd or creates a non-flat structuring element b from the binary image fd and the gray-scale image f. fd represents the domain of b and f represents the image of the points in fd.

Examples

iaimg2se to create structuring elements. In the example below, the flat 3x3 diamond is created.

Example 1

01. from ia870 import iaimg2se
02. from ia870 import iabinary
03. from ia870 import iaseshow
04. 
05. 
06. a = iaimg2se( iabinary([
07.   [0,1,0],
08.   [1,1,1],
09.   [0,1,0]]))
10. print iaseshow(a)
[[False  True False]
 [ True  True  True]
 [False  True False]]

Example 2

1. b = iabinary([
2.   [0,1,1,1],
3.   [1,1,1,0]])
4. b1 = iaimg2se(b)
5. print iaseshow(b1)
[[False False False False False]
 [False False  True  True  True]
 [False  True  True  True False]]

Example 3

01. c = iabinary([
02.   [0,1,0],
03.   [1,1,1],
04.   [0,1,0]])
05. d = int32([
06.   [0,0,0],
07.   [0,1,0],
08.   [0,0,0]])
09. e = iaimg2se(c,'NON-FLAT',d)
10. print iaseshow(e)
[[-2147483647           0 -2147483647]
 [          0           1           0]
 [-2147483647           0 -2147483647]]

Equation

H and W are the number of rows and columns of f, respectively.