How to fit an ellipse to a blob in binary image?
9 ビュー (過去 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 件のコメント
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
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
2021 年 4 月 7 日
If it resolves your question, please accept the answer so the question gets moved into the right list.
その他の回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

