This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Euler number of binary image




eul = bweuler(BW,n) returns the Euler number for the binary image BW. The Euler number is the total number of objects in the image minus the total number of holes in those objects. n specifies the connectivity. Objects are connected sets of on pixels, that is, pixels having a value of 1.

Code Generation support: Yes.

MATLAB Function Block support: Yes.


collapse all

Read binary image into workspace, and display it.

BW = imread('circles.png');

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 =


Input Arguments

collapse all

Input binary image, specified as a logical or numeric matrix that must be 2-D, real, and nonsparse.

Example: BW = imread('circles.png');eul = bweuler(BW,4);

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Connectivity, specified as either the value 4 or 8.

44-connected objects
88-connected objects

Example: BW2 = bweuler(BW,4);

Data Types: double

Output Arguments

collapse all

Euler number, returned as a numeric scalar value of class double.

More About

collapse all

Code Generation

This function supports the generation of C code using MATLAB® Coder™. 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 Understanding Code Generation with Image Processing Toolbox.

MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.


bweuler computes the Euler number by considering patterns of convexity and concavity in local 2-by-2 neighborhoods. See [2] for a discussion of the algorithm used.


[1] Horn, Berthold P. K., Robot Vision, New York, McGraw-Hill, 1986, pp. 73-77.

[2] Pratt, William K., Digital Image Processing, New York, John Wiley & Sons, Inc., 1991, p. 633.

See Also


Introduced before R2006a

Was this topic helpful?