How to fit an ellipse to a blob in binary image?

14 次查看(过去 30 天)
Hi! I am trying to fit an ellipse to images, in which my object is partially masked. For example. a picture below, is a binarized image, you can see that the objects in front are partially masking the ellipse in the center. How can I fit an ellipse to such a partially masked blob images?
Thank you!
  3 个评论
NeuronDB
NeuronDB 2021-4-6
Thank youf or the link! Unfortunately, it doesnt work :( the results look like this, where the elipse is fit to all the blobs.
Here is what I would like to happen instead, fitting an ellipse to the blob in the middle (indicated with green) below -
Best wishes!
Adam Danz
Adam Danz 2021-4-6
It's not that the solution doesn't work. My guess is that it's not being implementing correctly.
The solution uses regionprops to get the major and minor axis lengths and the orientation. That's what I would use, too and it's all you need to define the elipses. But first you need to isolate the blob because the noise in the upper right may also be considered in the major/minor axis estimates.

请先登录,再进行评论。

采纳的回答

DGM
DGM 2021-4-6
Keep in mind that most tools for morphological operations assume that the foreground (i.e. the "objects" ) are white. In order to work on the blob, you'll need to pick a relevant threshold and invert the image. You could've used imbinarize(), but I don't have it in R2015b. This works too.
% Read image
I = imread('blobs.png');
Igray = rgb2gray(I);
% i kept the green content. adjust threshold otherwise
% foreground is typically considered to be the white areas
% so this also inverts the image
BW = Igray<0.9*255;
% Extract the maximum area
BW = imclearborder(BW); % get rid of objects connected to the image boundary
BW = bwareafilt(BW,1); % pick the single largest object
This gives the best fit ellipse:
Which looks about right. Bear in mind, it's a best fit to an irregular region. The holes in the object mean it's not going to follow the original contour, if that's what you'd hoped. If so, you could loosen it up with this once the object is isolated:
BW = bwconvhull(BW); % after using bwareafilt
  4 个评论
DGM
DGM 2021-4-7
If it resolves your question, please accept the answer so the question gets moved into the right list.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by