How to calculate Precision and recall for segmentation algorithm. Please help

2 views (last 30 days)
I am applying the following code :
num_thresh = -1; instance_count = -1; [nx,ny]=size(score);
if (nx~=1 && ny~=1) error('first argument must be a vector'); end
[mx,my]=size(target); if (mx~=1 && my~=1) error('second argument must be a vector'); end
score = score(:); target = target(:);
if (length(target) ~= length(score)) error('score and target must have same length'); end
if (instance_count == -1) % set default for total instances instance_count = ones(length(score),1); target = max(min(target(:),1),0); % ensure binary target else if numel(instance_count)==1 % scalar instance_count = instance_count * ones(length(target), 1); end [px,py] = size(instance_count); if (px~=1 && py~=1) error('instance count must be a vector'); end instance_count = instance_count(:); if (length(target) ~= length(instance_count)) error('instance count must have same length as target'); end target = min(instance_count, target); end
if num_thresh < 0 % set default for number of thresholds score_uniq = unique(score); num_thresh = min(length(score_uniq), 100); end
qvals = (1:(num_thresh-1))/num_thresh; thresh = [min(score) quantile(score,qvals)]; % remove identical bins thresh = sort(unique(thresh),2,'descend'); total_target = sum(target); total_neg = sum(instance_count - target);
prec = zeros(length(thresh),1); tpr = zeros(length(thresh),1); fpr = zeros(length(thresh),1); for i = 1:length(thresh) idx = (score >= thresh(i)); fpr(i) = sum(instance_count(idx) - target(idx)); tpr(i) = sum(target(idx)) / total_target; prec(i) = sum(target(idx)) / sum(instance_count(idx)); end fpr = fpr / total_neg;
But this code works only for vectors. As i want to apply on image.What should i do? Please help

Answers (0)

Community Treasure Hunt

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

Start Hunting!