Calculates the Euler number of a binary image.
eul=bweuler(BW, n) calculates the Euler number eul of a binary image BW, which is a scalar whose value is the total number of objects in an image minus the number of holes.
n can have the values:
4
- bweuler will use 4-connected neighbourhood definition.
8
- bweuler will use 8-connected neighbourhood definition. This is the default value.
This function uses Bit Quads as described in "Digital Image Processing" to calculate euler number.
References: W. K. Pratt, "Digital Image Processing", 3rd Edition, pp 593-595
See also: qtgetblk
The following code
A=zeros(9,10); A([2,5,8],2:9)=1; A(2:8,[2,9])=1 bweuler(A) # Euler number (objects minus holes) is 1-2=-1 in an 8-like object
Produces the following output
A = 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 1 0 0 1 0 0 0 0 0 0 1 0 0 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 ans = -1