Counting Beans
This igraph illustrates the use of the distMap operator and blob analysis
operators to count the number of beans in an image.
-
readObj reads in an image with black and white beans,
some of which are touching.
-
thresh thresholds the image at a predetermined level,
producing a binary image.
-
distMap computes the distance map.
Each pixel value now represents how close the pixel was from
any off pixel in the binary image.
Pixels which were on and far away from any off pixels
will have
a high value in the distance map.
Pixels which were on but close to an off pixel will
have lower values.
Pixels which were off will become zero.
-
thresh #1 picks up only the peaks of the distance map.
-
getBlobFeatures converts the image into a set of blobs.
-
plotFeatures extracts the centroid of each blob
and create a graphic point object for each centroid.
-
overlayData superimposes the centroids on top of the
original image.
-
getField extract the size field from the vector (list)
of blobs.
This field corresponds to the number of blobs, and therefore beans,
in the original image.
-
The number of beans is displayed as a large number with display.