How do you get regionprops "images" (e.g. FilledImage, Image, ConvexImage) to be the same size as the original image?

4 visualizaciones (últimos 30 días)
I have a label matrix. I am using regionprops to measure properties for each labeled region. Some of those properties are images (e.g. FilledImage, Image, ConvexImage), but they are always the size of the bounding box of the region. How can I convert this to the size of the original image?
Example
Suppose
L = [2 2 0 0 0 0;
2 2 0 1 1 0;
0 0 0 0 1 0;
0 0 1 1 1 0];
stats = regionprops(L,'all');
Then
stats(1).ConvexImage = [0 1 1;
0 1 1;
1 1 1];
But what I want is
[0 0 0 0 0 0;
0 0 0 1 1 0;
0 0 0 1 1 0;
0 0 1 1 1 0];
How can I achieve this?
I'm sure it can be done by using the BoundingBox, but for some reason, I cannot recall how to do this.
  1 comentario
Matthew Eicholtz
Matthew Eicholtz el 15 de Jul. de 2013
Perhaps another way to phrase this question is that I want to create a logical mask the size of the original image in which pixels inside of the bounding box are 1.
Then, I could just do something like
A = zeros(size(img));
A(mask) = stats(1).ConvexImage;

Iniciar sesión para comentar.

Respuesta aceptada

Image Analyst
Image Analyst el 16 de Jul. de 2013
I can think of a way, but not an easy way - uses BoundingBox like you said. Fortunately there is an easy way for some returned images like the filled regions and the convex regions, but it doesn't use regionprops. For filled regions, use imfill(). For the convex regions, use bwconvhull() (in later versions of the Image Processing Toolbox). If there is some other thing you want, other than those two, let me know.
  1 comentario
Matthew Eicholtz
Matthew Eicholtz el 16 de Jul. de 2013
Thanks for the reply. Yes, I was using bwconvhull() previously. Interestingly enough, it appears to call regionprops and I am running this computation thousands of times, which makes it quite slow.

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by