lundi 4 décembre 2017

MATLAB: how can I plot centroids of different colors in this loop

This code correctly counts the number of object for each horizontal band I previously divided my image in.

barray is a vector in which I store the 'height' of each band.

n = zeros(1,bandlength);    % preallocate space for counting objects in 
                              each band, with bandlength = total number 
                              of bands in which the image is 
                              partitioned

 for j = 1:bandlength   
        if j == 1
        n(j) = sum(centroidsY<(barray(j)));  % case for when j=1 for 
                                               indexing reasons

        else
        n(j) = sum(centroidsY>sum(barray(1:j-1)) & centroidsY<sum(barray(1:j)));
        end
 end
end
disp(n);

I also want to plot the centroids with different color in the loop, so that I can display visually which object belongs to which band.

I thought about simply put a 'k' for loop before the 'j' for loop like:

for k = 1:numberOfBlobs

And then indexing every centroidsY in the previous code block like centroidsY(k), then plot the results.

I don't know:

1) why if I try to use the 'k' for loop the object count array 'n' gives 1 for a value, 0 for all of the others? No plot is visible as well.

2) how can I correct 1) and also plot the results with different colors? I need a different color for each different band. I looked for:

plot(centroidsX(k),centroidsY(k),'color',rand(1,3))

but it gives me lines and not points in the object's centroid.

Thanks.

Aucun commentaire:

Enregistrer un commentaire