How to inscribe largest ellipse inside an irregular shaped object

Viewed 51

I am trying to find the largest or best fitting ellipse inside an irregularly shaped object from a binarized image, in order to get a more consistent center of mass and orientation angle.

I am trying to analyze a video that contains many of these objects and track the object as it moves around in the frame. I have cut out the other objects in the original video to just focus on one object at a time, and have it as centered as I can. Currently region_props gives me centroid coordinates and an orientation angle. But because of small pixel variations throughout, those coordinates change, giving a very unsteady video. Here is the image from the video:

enter image description here

The main blob in the center doesn't change over the course of the video, but the curly things coming out slightly bend and change, giving me problems. My goal is to find the largest ellipse inside the object and get the center of mass from that as well as the orientation angle. I will be analyzing a lot of videos, and also a lot of object of various sizes, but if I can get some idea of how to do it for one image I can build up. I have seen some things regarding inscribing ellipses inside bounding boxes but because these objects are all very irregular a bounding box won't work.

How could I approach a problem like this?

1 Answers

Apply an opening with a disk structuring element that is slightly larger than the appendages, but smaller than the central body. This will remove the appendages, and leave only the central body. Your region_props results should then be consistent enough.

For example, using DIPlib (disclosure: I'm an author) you would do it this way:

import diplib as dip
img = dip.ImageRead('uhp1D.jpg')
core = dip.Opening(img, 19)
core.Show()

result of operation above

The larger the structuring element, the more compact the output is.

Related