BW area and region props function not matching both.

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)

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

Hi, apologies for jumping here:
When using regionprops i got an area of 90 pixels
but when using bwarea i got around 290 pixels.
As just for double checking I did a manual area reconstruction by drawing multiple squares using imtool ruler and BWAREA seems to get a more closer ouptut of what i can get manually with Imtool.
Its a bit confusing, i though regionprop was more accurate, and I read that there might be some light mismatch, but the difference is too large.
attahced both files, the one i have fed into BWAREA and REGIONPROSP And the one with imtool manual calculation with rulers.
Regards
Since imtool is an interactive applet, I'm not sure what you did. Perhaps you can record it with PSR and upload the zip file. PSR is a windows app that takes snapshots of the screen whenever it changes. Hit the windows key and type psr.
There should not be that much of a difference between the different methods. Some, but not like 90 and 290, more like +/- 3 or 4 pixels or so.
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.
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.

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

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.

Asked:

on 8 Apr 2013

Commented:

on 1 Apr 2020

Community Treasure Hunt

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

Start Hunting!