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

6 次查看(过去 30 天)
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 个评论
Matthew Eicholtz
Matthew Eicholtz 2013-7-15
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;

请先登录,再进行评论。

采纳的回答

Image Analyst
Image Analyst 2013-7-16
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 个评论
Matthew Eicholtz
Matthew Eicholtz 2013-7-16
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.

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by