Filter centroids to find only those of interest in binary image
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Lauren
am 18 Feb. 2021
Kommentiert: Image Analyst
am 19 Feb. 2021
I have defined the following centroids within a region of interest (blue rectangle) for my binary image. How can I remove or centroids within the red boxed region?
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 18 Feb. 2021
If you know the rows and columns outlining your box you can erase the image inside that box before computing the centroids
mask(row1:row2, col1:col2) = false;
props = regionprops(mask, 'Centroid');
Or you can keep the mask as-is, and just remove the measurements from the output of regionprops():
xy = vertcat(props.Centroid);
xCentroids = xy(:, 1);
yCentroids = xy(:, 2);
badIndexes = xCentroids >= col1 & xCentroids <= col2 & yCentroids >= row1 & yCentroids <= row2;
% Delete the bad ones.
prop(badIndexes) = [];
2 Kommentare
Image Analyst
am 19 Feb. 2021
Instead of that for loop, you could have just inverted the badIndexes and used that as a logical index to the centroids to plot only those good locations:
xCentroids = CentroidsInsideROI(:, 1);
yCentroids = CentroidsInsideROI(:, 2);
badIndexes = yCentroids >= 300 & yCentroids <= 600 ;
plot(xCentroids(~badIndexes), yCentroids(~badIndexes), 'm*')
Weitere Antworten (1)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!