Euler number of binary image
returns the Euler number for the binary image
eul = bweuler(
BW. The Euler
number (also known as the Euler characteristic) is the total number of objects in
the image minus the total number of holes in those objects.
conn specifies the connectivity. Objects are connected sets
on pixels, that is, pixels having a value of 1.
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— Binary image
Binary image, specified as a 2-D numeric matrix or 2-D logical matrix. For
numeric input, any nonzero pixels are considered to be
Connectivity, specified as the values
4 for 4-connected
8 for 8-connected objects.
eul— Euler number
Euler number, returned as a numeric scalar.
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:
bweuler supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic
MATLAB Host Computer
bweuler 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 Types of Code Generation Support in Image Processing Toolbox.