Find distance from centroids to a specific point and remove objects that are having greater distance than the threshold

3 visualizzazioni (ultimi 30 giorni)
Remove objects having computed centroid distance greated than the threshold value. ECR point which is a point that crossing the 100th row from the bottom of the image and centre of the image. Find distance from each centroid to ECR and remove if any one object is having greater distance than the threshold.
Step1: Find threshold of the image using OSTU method
Step2: Find and locate the centroids that are present in each object and an ECR point which is a point that crossing the 100th row from the bottom of the image and centre of the image.
Step3: Draw a line from each centroid to ECR
Step4: Find a distance from each centroid to ECR
Step5: Remove objects having computed centroid distance greater than the threshold value
step6: Save the final image
function CentroidThresholding()
% input binary image file
I = 'D:\PRIVATE\Medical Image Processing\MedicalImageProcessing\Resources\RPE\SmallObjectsRemovedImages\SmallObjectsRemoved_GreenChannel_Rescaled_Cropped_NSB001.tif';
BW = imread(I);
%OTSU Threshold
T = graythresh(uint8(BW));
[r, c] = size(BW);
%Find centroids of objects
stat = regionprops(BW,'centroid');
centroids = cat(1,stat.Centroid);
% ECR is the point crossing the 100th row from the bottom and centre of the image
ECR = [r-100, c/2];
imshow(I);
hold on;
% mark centroids
plot(centroids(:, 1), centroids(:, 2), 'r.','LineWidth',2, 'MarkerSize', 15);
% mark ECR point
plot((r-100)/2, c, 'y.','MarkerSize', 15);
%Draw a line from each centroid to ECR point
% Find centroid distance to ECR point
CentroidDistances=pdist2(centroids,ECR,'euclidean');
%Remove objects having computed centroid distance greater than the threshold value
hold off;
end
Problem to solve
1. I want to draw a line from each centroid to ECR point.
2. I want to remove objects having computed centroid distance greater than the threshold value

Risposte (1)

Matt J
Matt J il 18 Gen 2023
Modificato: Matt J il 18 Gen 2023
stat = regionprops(BW,'centroid','PixelIdxList');
...
CentroidDistances=pdist2(centroids,ECR);
stat=stat(CentroidDistances > threshold);
for i=1:numel(stat)
BW(stat(i).PixelIdxList)=0;
end

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by