Region description

Basic description

Basic properties like area, Euler number, minimum rectangle that wraps the figure, etc. a region can be defined inside an image. In MATLAB we do this process in the following way:


B = bwlabel(f);
D = regionprops(B, properties)

where f is the image that contains the regions that we want to describe. The first thing we do is to convert the image to a representation through labels, using the first command.

The second command takes that labelled matrix and calculates the properties that we want. For example:

D = regionprops(B, 'area', 'boundingbox')

This would produce a structure like the following:


D =
Area: 19939
BoundingBox: [30.5000 19.5000 223 306]

The properties we want to calculate are listed separated by commas, as shown in the previous example. There are several properties:

• area: Calculates the area of the region in squared pixels.
• boundingbox: Calculates the position and dimensions of the minimum rectangle that wraps the region.
• Centroid: Position of the centroid of the region.
• ConvexHull: Matrix with the position of the pixels that define the convex helmet that wrapsthe region.
• ConvexImage: Binary image with the shape of a convex helmet.
• Eccentricity: Scalar number that gives the eccentricity of the image.
• EulerNumber: Scalar that gives the Euler number of the region.
• MayorAxisLength: Length of the largest axis of the region.
• MinorAxisLength: Length of the smallest axis of the region.

Invariant moments

${\mu }_{pq}=\sum _{x=-\infty }^{\infty }\sum _{y=-\infty }^{\infty }{\left(x-{x}_{c}\right)}^{2}{\left(y-{y}_{c}\right)}^{q}f\left(x,y\right)$

The following six moments give us six different numeric values that are insensitive to image transformations like scale changes, mirroring and rotation:

${\varphi }_{1}={\eta }_{20}+{\eta }_{02}$

${\varphi }_{2}={\left({\eta }_{20}-{\eta }_{02}\right)}^{2}+4{\eta }_{11}^{2}$

${\varphi }_{3}={\left({\eta }_{30}-3{\eta }_{12}\right)}^{2}+{\left(3{\eta }_{21}-{\eta }_{30}\right)}^{2}$

${\varphi }_{4}={\left({\eta }_{30}+{\eta }_{12}\right)}^{2}+{\left({\eta }_{21}+{\eta }_{30}\right)}^{2}$

${\varphi }_{5}=\left({\eta }_{30}-3{\eta }_{12}\right)\left({\eta }_{30}+{\eta }_{12}\right)\left[{\left({\eta }_{30}+{\eta }_{12}\right)}^{2}-3{\left({\eta }_{21}+{\eta }_{30}\right)}^{2}\right]+\left(3{\eta }_{21}-{\eta }_{03}\right)\left({\eta }_{21}+{\eta }_{03}\right)\left[3{\left({\eta }_{30}+{\eta }_{12}\right)}^{2}-{\left({\eta }_{21}+{\eta }_{03}\right)}^{2}\right]$

${\varphi }_{6}=\left({\eta }_{20}-{\eta }_{02}\right)\left[{\left({\eta }_{30}+{\eta }_{12}\right)}^{2}-{\left({\eta }_{21}+{\eta }_{03}\right)}^{2}\right]+4{\eta }_{11}\left({\eta }_{30}+{\eta }_{12}\left({\eta }_{21}+{\eta }_{03}\right)\right)$

Main Components

We can describe an image using main componets. Suppose we have a group of images and we build the following group of matrices:

The average vector would be:

${m}_{x}=\frac{1}{K}\underset{k=1}{\overset{K}{\sum {x}_{k}}}$

where K = MN. Then, the covariance matrix can be built, with a size of mxm, like this:

${C}_{x}=\frac{1}{K-1}\sum _{k=1}^{K}K\left({x}_{k}-{m}_{x}\right){\left({x}_{k}-{m}_{x}\right)}^{T}$

The eigenvalues and eigenvectors would then be:

$y=A\left(x-{m}_{x}\right)$

$x={A}^{T}y+{m}_{x}$

We can reduce the number of eigenvalues to q. Then, the previous equation would turn into:

$\stackrel{^}{x}={{A}_{q}}^{T}y+{m}_{x}$

If we stay with the main eigenvalues (the largest ones), we can obtain a reduced group of images that have the most relevant information. At the same time, this eigenvalues characterize the properties of the images.

The following command in MATLAB makes all the necessary calculations:

P = princomp(X,q)

where X is a matrix that contains the vectors x of the previous expressions, q is the number of eigenvalues that we want to obtain, and P is a structure that contains several things:

• P.Y K by Q matrices whose columns are the main eigenvectors.
• P.Cx m by m covariance matrix.
• P.X K by m, matrix whose rows are the vectors that were rebuilt from the eigenvalues.

You can practice these concepts using snippet08.