Im = [0 1 1 0 0 0 0 0 0 0;
0 1 1 0 1 1 0 0 0 1;
0 1 1 0 1 1 0 1 0 1;
0 0 0 0 0 0 0 1 0 1;
0 1 1 1 0 1 1 1 0 1;
0 0 0 0 0 0 1 1 0 1;
0 1 0 0 0 0 0 0 0 1;
0 1 0 0 0 0 1 1 0 0;
0 0 0 0 0 0 1 0 0 0;
0 0 0 0 0 0 0 0 0 0];
bw = bwlabel(Im,4);
blob = regionprops(bw, 'All');
GN = [0 1 0 0 1 0 1] % white Blobs
ground_truth = [1 0 1 1 0 1 0] % Orange Blobs
all = [blob(:).Area];
test_data = (all < 5 )
% Negative = (all > 5 )
% FP Negative in ground truth, but positive in test
false_positives = ~ground_truth & test_data;
false_positive_rate = sum(false_positives(:)) / numel(false_positives);
% FN Positive in ground truth data but negative in your test
false_negatives = ground_truth & ~test_data;
false_negative_rate = sum(false_negatives(:)) / numel(false_negatives);
% TP Positive in both
true_positives = ground_truth & test_data;
true_positive_rate = sum(true_positives(:)) / numel(true_positives);
% TN Negative in both
true_negatives = ~ground_truth & ~test_data;
true_negative_rate = sum(true_negatives(:)) / numel(true_negatives);
% N = TN + TP + FP + FN
N = true_negative_rate + true_positive_rate + false_positive_rate + false_negative_rate;
% Acc = (TP + TN)/N
Acc = (true_positive_rate + true_negative_rate )/N