1. Original image and the negative image (value 0 represent background while 1 represents object).
S = imread('p6-in1.jpg');
ShowColorImage(S,'Original Image');
2. Labeling the objects in the image. The advance programming language will support this function and label the objects automatically.
// Labeled the component(s), and plot the centroid on the original image
S3 = SearchBlobs(S2);
ShowImage(S3,'Labeled Image');
3. Getting the properties of the objects that require for calculation, which are: the width and height for the object, the area of the object, and the centroid of the object.
ToBeCalculated = CreateFeatureStruct(%t); // Feature struct is generated.
S4 = AnalyzeBlobs(S3,ToBeCalculated);
4. Now, evaluate the "roundness" of the objects. this is evaluated by 2 criteria:
a. Comparing the width and the height diameter for the object,
b. Comparing the Area with the formula pi*r^2.
The "scores" are normalized so that 1 represent "best fit"
for cnt = 1:length(S4)
score1(cnt) = 1-abs(S4(cnt).BoundingBox(3)-S4(cnt).BoundingBox(4))/max([S4(cnt).BoundingBox(3),S4(cnt).BoundingBox(4)]);
score2(cnt) = 1 - abs(%pi*((mean([S4(cnt).BoundingBox(3),S4(cnt).BoundingBox(4)]))/2)^2-length(S4(cnt).PixelIndexList))/length(S4(cnt).PixelIndexList);
end
score = mean([score1 score2],'c');
5. Display the result visually
ShowImage(S2,'0');
[m,n] = size(S2);
for cnt = 1:length(S4)
xnumb(S4(cnt).Centroid(1),m-S4(cnt).Centroid(2),score(cnt));
t = gce();
t.font_foreground = color('red');
end
So now, can you tell which one is the round object by just looking at the "roundness index"?