Reputation: 21
I have two binary images (ground truth and test image). Each one has objects as black pixels and all other area as white pixels. I want to check if my algorithm's output image complies with the ground truth image. For that, I want to find area of overlap in these two.
How can I find the area of overlap in two images?
Upvotes: 2
Views: 4236
Reputation: 221674
Assuming BW1
and BW2
to be the two binary images, you can calculate the "overlapping area" in pixels with this -
ovlp_area = nnz(BW1 & BW2);
&
gets us the binary image with white pixels for the overlapping area.nnz
counts the number of true values, which is the count of pixels in the overlapping region.You can do the same with sum
:
ovlp_area = sum(sum(a1 & a2))
or
ovlp_area = sum(reshape((a1 & a2),[],1))
But I doubt if these will be more efficient in terms of runtime when compared against the nnz
approach.
Upvotes: 2