bwarea() does NOT give the same area as a simple count of pixels, like sum() and regionprops() give you. It weights the edge pixels according to their neighbors, so like an edge slanted at 45 degrees might give half a pixel instead of a full pixel. There are different weights for different edge orientations. The bwarea documentation explains it all.
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)
Keep in mind that each pixel is part of four different 2-by-2 neighborhoods. This means, for example, that a single on pixel surrounded by off pixels has a total area of 1.
You have to decide if you want that or if you want a simple count of pixels.