Friday, July 1, 2011

Calculating Image moments and Centroids

Image moments describe simple properties of an image, or in our case, the region representing the insect.

Using image moments, one can find the centroid and orientation of a given object. OpenCV implements the moments structure, but I was surprised to find out that OpenCV does not implement finding the centroid or eigenvectors representing major and minor axes of an object because these properties are easy to implement, and commonly associated with image moments.

First I create a binary image and find the contours of the image. Then I assume that the contour with the most pixels is the insect, and ignore all other contours. From here I can use the moments to calculate the centroid:

Contour of insect
Original image with detected centroid


More examples of detected centroid:
 

 

 

Note that some of the centroids are a little bit off. This is most likely due to the pixels in the wings, since the centroid is simply a weighted average over all pixels.

Something interesting to try out might be to look at the number of pixels in a rectangular box around the centroid, noting that some insects have a thinner petiole or "waist" than others.

Today I also looked at Singular Value Decomposition and Principle Component Analysis. I don't completely understand these concepts yet, but I will continue to look more into them next time.

No comments:

Post a Comment