February 11, 2020 - Figuring Out How to Segment out Individual Objects in a Large Contour
Today, I tried to figure out a way of segmenting the images in a more accurate way so that I could measure the individual eggs in an image. As seen in the last post, even though the script does a pretty good job at parsing out the individual objects in an image, if there are multiple objects connected to each other, then these objects are counted as one large object.
Thus, one of the first things that I thought might be helpful to use in order to solve this issue was a watershed algorithm. I tried running this, but the result was not very promising.
It seemed like there were areas of the image that were undersegmented and also parts of the image that were oversegmented.
Thus, I started to find a way to segment the image without using a watershed algorithm. I realized that since there are definitive edges in each object that is contoured, then there must be a way to identify the presence of these edges. If there is way to say that when certain edges are in a certain formation, form a line between each edge, then “circles” of each object would be formed, hypothetically.
In order to see if this plan would actually work, the first step is to see if we can actually identify the edges of the contour.
After looking around, I found that the command cv2.goodFeaturesToTrack might be a possible way to find the edges of the contour that I want. But after trying it out on the image, the results were not promising:
I think this can be attributed to the fact that the command takes into consideration the whole image rather than the specific contour that you would like to be segmented.
cv2.convexHull and cv2.convexityDefects
While looking around, I also saw that the commands cv2.convexHull and cv2.convexityDefects may be a viable way to find the edges of the contour. After running the script with these commands, the results were more promising, but there is still definitely room for improvement:
Finally, I saw that the command cv2.approxPolyDP may be a viable way of obtaining the points needed. After running the script under a variety of parameter ranges, I saw that the results may be more promising than the other commands that were used:
Larger epsilon value:
Smaller epsilon value:
These were the sources that I used to help me find and figure out how to use the commands stated above:
Single blob, multiple objects (Ideas on how to separate objects)
- Continue to try and improve the accuracy of segmentation (possibly using a combination of cv2.convexHull, cv2.convexityDefects, and cv2.approxPolyDP.