Euler number of binary image
eul = bweuler(BW,n)
Read binary image into workspace, and display it.
BW = imread('circles.png'); imshow(BW)
Calculate the Euler number. In this example, all the circles touch so they create one object. The object contains four "holes", which are the black areas created by the touching circles. Thus the Euler number is 1 minus 4, or -3.
ans = -3
BW— Input binary image
Input binary image, specified as a logical or numeric matrix that must be 2-D, real, and nonsparse.
BW = imread('circles.png');eul = bweuler(BW,4);
Connectivity, specified as either the value
BW2 = bweuler(BW,4);
eul— Euler number
Euler number, returned as a numeric scalar value of class
bweuler computes the Euler number by considering
patterns of convexity and concavity in local 2-by-2 neighborhoods.
See  for
a discussion of the algorithm used.
 Horn, Berthold P. K., Robot Vision, New York, McGraw-Hill, 1986, pp. 73-77.
 Pratt, William K., Digital Image Processing, New York, John Wiley & Sons, Inc., 1991, p. 633.
Usage notes and limitations:
This function supports the generation of C code using MATLAB®
Note that if you choose the generic
MATLAB Host Computer target
platform, the function generates code that uses a precompiled, platform-specific
shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For
more information, see Understand Code Generation with Image Processing Toolbox.