1. Original image and the negative image (value 0 represent background while 1 represent oject).
S = imread('pic10.jpg');
S = im2bw(S);
S2 = ~S;
imshow(S2);

2. Labeling the objects in the image. The advance programming language will support this function and label the objects.
S3 = bwlabel(S2);
imshow(S3,[]);

3. Some properties of the objects are extracted using the command. In this example, we just use the area and perimeter for our calculation.
S4 = regionprops(S3,'Area','Perimeter','centroid');
4. Now, evaluate the "squareness" of the objects. this is evaluated by only 1 criteria in this example:
a. Calculate the length or width of the object by using the formulas of area and perimeter, comparing the result and the square objects would have higher score than others. Do note that instead of for loop, the code below is a vectorized code.
score = (min(sqrt([S4.Area]),[S4.Perimeter]/4)./(max(sqrt([S4.Area]), ...[S4.Perimeter]/4))).^2;
5. Display the result visually
imshow(S2)
for cnt = 1:length(S4)
text(S4(cnt).Centroid(1),S4(cnt).Centroid(2),num2str(score(cnt)),'color','red');
end

Do note that this example assumes perfect images. For more accurate results, more properties can be compared by using more criteria. The example above is done using MATLAB®.
MATLAB® is registered trademarks of The MathWorks.



It seems like great but the usage of these output are useless until we really know what we want to do. For exmaple, we want to find the white rabbit, we need to perform some pre-processing before the edge detection so that we can fully utilize the function to suite to our needs.
The post processing can be used to remove unwanted noise.

