MATLAB: How to get region of interest and calculate the hit rate and precision rate

imageImage Processing Toolbox

How to draw out the total object pixel of interest region in an image?
I want calculate the hit rate= correct pixel deteced/total object pixel
precision= correct pixel detect/total detected pixel
elephant is my original image and result is my segmentation which is very bad. I now want to calculate the hit rate and precision rate. How to do it?
How to superimpose(transparent) the result to elephant ?

Best Answer

Calculate the area of the elephant from the outline you traced around it using poly2mask, then sum.
elephantMask = poly2mask(x, y, rows, columns);
elephantArea = sum(elephantMask(:));
Then calculate the area of overlap between your segmentation and the true area
numSegmentationPixels = sum(segmentationMask(:))
overlapPixels = elephantMask & segmentationMask;
numOverlapPixels = sum(overlapPixels(:))
Then use your formula for precison:
precision = numOverlapPixels / numSegmentationPixels;
Related Question