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)
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.
The following six moments give us six different numeric values that are insensitive to image transformations like scale changes, mirroring and rotation:
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:
where K = MN. Then, the covariance matrix can be built, with a size of mxm, like this:
The eigenvalues and eigenvectors would then be:
We can reduce the number of eigenvalues to q. Then, the previous equation would turn into:
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)
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.YK by Q matrices whose columns are the main eigenvectors.
P.Cxm by m covariance matrix.
P.XK by m, matrix whose rows are the vectors that were rebuilt from the eigenvalues.
You can practice these concepts using