Effacer les filtres
Effacer les filtres

Better code to crop out a connected component?

1 vue (au cours des 30 derniers jours)
Qingyang
Qingyang le 17 Juil 2012
Hi, I have written this code to crop out just a connected component on an image:
rp = regionprops(cc, 'BoundingBox');
minr = rp(stainid).BoundingBox(2);
minc = rp(stainid).BoundingBox(1);
maxr = rp(stainid).BoundingBox(2) + rp(stainid).BoundingBox(4);
maxc = rp(stainid).BoundingBox(1) + rp(stainid).BoundingBox(3);
imstainzoom = im(minr:maxr, minc:maxc);
It works, but isn't the best code possible. Also, the bounding box returns non-integers (why is that?). Is there a much more efficient way to do this?

Réponse acceptée

Image Analyst
Image Analyst le 17 Juil 2012
Modifié(e) : Image Analyst le 17 Juil 2012
See my image segmentation tutorial where I crop out objects using their bounding boxes. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
I believe it gives coordinates on the half pixel to eliminate any ambiguity about whether the bounding box is the inclusive box, or one pixel layer outside that. So you can use ceil() and floor() to make it do it either way depending on what you prefer.
  1 commentaire
Qingyang
Qingyang le 18 Juil 2012
Thanks! I completely forgot that you could just do it with imcrop. Great tutorials there, btw!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Geometric Transformation and Image Registration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by