Calculate the Euler number of a binary image.
This function calculates the Euler number eul of a binary image BW. This number is a scalar whose value represents the total number of objects in BW minus the number of holes.
n is an optional argument that specifies the neighbourhood connectivity. Must either be 4 or 8. If omitted, defaults to 8.
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: bwmorph, bwperim, 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
Package: image