This seems to solve your problem:
[B,L,N,A] = bwboundaries(BBinEro);
for k=1:length(B)
text(BlueProps(k).Centroid(1),BlueProps(k).Centroid(2),num2str(score(k)),'color','red');
if(~sum(A(k,:))) & score(k) >= 0.98
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);
end
end
I just added the condition & score(k) >= 0.98
to an example in the matlab documentation here. This assumes that the score array is ordered in the same way as the objects array generated by bwboundaries
. If objects in score
are ordered in the same way as the objects generated by regionprops
then this is ok, since regionprops
and bwboundaries
index objects in the same order.
The error in your code lies in that you recalculate bwboundaries(BBinEro)
with each iteration of your outer loop. Presumably you are trying to compute boundaries for each new object with each new iteration, but instead you are computing over the entire image (which I guess is BBinEro
). Hope this solves your problem.