counting blobs in regions using their centroid index and plot the result

2 Ansichten (letzte 30 Tage)
giacomo
giacomo am 6 Nov. 2017
Kommentiert: giacomo am 9 Nov. 2017
Hi everyone. I'm following the BlobsDemo() by Image Analyst for my personal project. I counted all the blobs and now I want to count the blobs in an image region by using centroids infos. Then, I'd like to display the number of blobs for each image region. So far, after getting the blobs properties, what I did is this:
>> % We can get the centroids of ALL the blobs into 2 arrays,
% one for the centroid x values and one for the centroid y values.
allBlobCentroids = [blobMeasurements.Centroid];
centroidsX = allBlobCentroids(1:2:end-1);
centroidsY = allBlobCentroids(2:2:end);
Blobs1 = 0;
Blobs2 = 0;
Blobs3 = 0;
Blobs4 = 0;
for k1 = 1 : numberOfBlobs
for j = 1:length(centroidsY)
if 1 < centroidsY(j) < rows/4
Blobs1 = Blobs1 + 1;
else if rows/4+1 < centroidsY(j) < rows/2
Blobs2 = Blobs2 + 1;
else if rows/2 + 1 < centroidsY(j) < 3*rows/4
Blobs3 = Blobs3 + 1;
else if 3*rows/4 + 1 < centroidsY(j) < rows
Blobs4 = Blobs4 + 1;
end
end
end
end
end
end
disp([Blobs1, Blobs2, Blobs3, Blobs4]);
I tried to loop on all the blobs contained in the image and then based on the Y centroid coordinate I tried to count them if inside of the region (4 equal horizontal strips). How to get this to work? Once I get this done the next step will be plotting the centroids on the original image, using different indexes for different regions. I'd be relieved if you can help me with this. Thanks.
  1 Kommentar
giacomo
giacomo am 9 Nov. 2017
The output is like:
  • blobs1 = all of the blobs
  • blobs2 = 0
  • blobs3 = 0
  • blobs4 = 0
What am I doing wrong? Why doesn't the algorithm take the centroid Y coordinate to count them in the right horizontal subset of the image?

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by