Effacer les filtres
Effacer les filtres

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

6 vues (au cours des 30 derniers jours)
NeuronDB
NeuronDB le 6 Avr 2021
Commenté : DGM le 7 Avr 2021
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 commentaires
NeuronDB
NeuronDB le 6 Avr 2021
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 le 6 Avr 2021
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.

Connectez-vous pour commenter.

Réponse acceptée

DGM
DGM le 6 Avr 2021
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 commentaires
NeuronDB
NeuronDB le 7 Avr 2021
Super! thank you :)
DGM
DGM le 7 Avr 2021
If it resolves your question, please accept the answer so the question gets moved into the right list.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Images dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by