BW area and region props function not matching both.

3 views (last 30 days)
Respected sir, When i am using shape feature BW area and region props in my code both are varying in results or in values, whats the exact problem i am not getting. or else give me code of BW area and region props..

Answers (2)

Image Analyst
Image Analyst on 8 Apr 2013
It's explained in the help. regionprops() is "whole pixel based" and is what I use. bwarea() uses a different algorithm, as explained in the help:
bwarea estimates the area of all of the on pixels in an image by summing the areas of each pixel in the image. The area of an individual pixel is determined by looking at its 2-by-2 neighborhood. There are six different patterns, each representing a different area:
Patterns with zero on pixels (area = 0)
Patterns with one on pixel (area = 1/4)
Patterns with two adjacent on pixels (area = 1/2)
Patterns with two diagonal on pixels (area = 3/4)
Patterns with three on pixels (area = 7/8)
Patterns with all four on pixels (area = 1)
  4 Comments
JESUS MARTINEZ
JESUS MARTINEZ on 1 Apr 2020
HI, thanks.
All I have been able to figure out so far is that if I put all the code in one script all together: calling the image, processing and regionprops its fine, results are similar.
But if I have separate .m file for doing the processing and a separate one for regionprops detection then big difference happens.....
thanks anyway.
Image Analyst
Image Analyst on 1 Apr 2020
I seriously doubt that. Attach your three scripts (the combined one and the two separate ones) and the image. Your second script must be using a different binary image.

Sign in to comment.


JESUS MARTINEZ
JESUS MARTINEZ on 1 Apr 2020
Hi that is the image.
I think the problem is that I was saving the file from the imshow window..and the file generated was larger in size dimension.
I have used now imwrite and all seems fine.
Thanks.
  2 Comments
Image Analyst
Image Analyst on 1 Apr 2020
Yes, if you use saveas() or getframe() it basically grabs a screenshot of screen pixels so you'll get whatever that is, which can vary if you resize the figure window. Using imwrite() saves the actual image, pixel for pixel, regardless of the size it is on your monitor. You can resize the figure window all you want and imwrite will still save the same size image.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!