How can I delete data from my table if two centroids from regionprops are the same?

1 vue (au cours des 30 derniers jours)
I am analyzing spheroid formations on images of nerve tissue. My microscope saves multiple images from the same time, visualizing only some part of the tissue. Below is the code that is working for my images to identify the spheroids. However, since some images overlap with others, so does the regionprops. I want to be able to quantify the spheroid formation across all my images without counting some spheroids twice.
In the following code, I want my table "Testing" where I am saving all the information of regionprops to clear the data if two centroids are in the same position or relatively close to each other, and keep the largest spheroid.
%MATLAB CODE TO IMPORT FOR REGIONPROPS MULTIPLE IMAGES
clear;
clc;
n = 20; %assuming number of images is 20
stats = cell(n, 1);
for k = 15:n %Right now I am interested on starting on image #15-20 just for testing purposes
stats{k} = analyse(k);
end
Testing = [stats{15}.large_Stats;stats{16}.large_Stats;stats{17}.large_Stats;stats{18}.large_Stats;stats{19}.large_Stats;stats{20}.large_Stats];
%Here is where I want a code for my table to be take out double data based
%on centroid position
function out = analyse(k)
%MATLAB CODE FOR REGIONPROPS
filename = "45_min" + k + ".png";
A = imread(filename);
figure,imshow(A)
[~,BW,~] = imsplit(A);
%figure,imshow(BW);
BW = imsharpen(BW);
BW = imreducehaze(BW);
BW = im2bw(BW,0.85);
figure,imshow(BW)
stats = regionprops(BW,"all");
n=1;
for i = 1:length(stats)
out.area(i)= stats(i).Area;
out.perimeter(i) = stats(i).Perimeter;
out.circularity(i)= stats(i).Circularity;
out.centroid{i}= stats(i).Centroid;
out.majoraxislength(i) = stats(i).MajorAxisLength;
out.minoraxislength(i) = stats(i).MinorAxisLength;
if out.circularity(i)~=Inf && out.circularity(i)>0.44 && out.area(i)>120
out.large_areas(n) = out.area(i);
out.large_perimeter(n) = out.perimeter(i);
out.large_circularity(n) = out.circularity(i);
out.large_centroid(n) = out.centroid(i);
out.large_majoraxislength(n) = out.majoraxislength(i);
out.large_minoraxislength(n) = out.minoraxislength(i);
n= n+1;
end
end
out.centers = out.large_centroid';
out.centers = cell2mat(out.centers);
out.large_minoraxislength = out.large_minoraxislength';
out.large_majoraxislength = out.large_majoraxislength';
out.large_Stats = table(out.large_areas',out.large_perimeter', out.large_centroid', out.large_circularity', out.large_majoraxislength, out.large_minoraxislength);
out.large_Stats.Properties.VariableNames(1:4) = {'Area' 'Perimeter' 'Centroid' 'Circularity'};
out.diameters = mean([out.large_majoraxislength out.large_minoraxislength],2);
out.radii = out.diameters/2;
hold on
viscircles(out.centers,out.radii);
hold off
end

Réponses (2)

Shreeya
Shreeya le 11 Sep 2023
I understand that you want to delete the spheroid data in the table “stats” which have the same centroid values. Kindly use the “unique” function for this:
[~,idx] = unique(stats.centroid)
stats = stats(idx,:)
Please refer to the documentation to know more about the function: https://www.mathworks.com/help/images/ref/regionprops.html
I hope this resolves your problem!

Image Analyst
Image Analyst le 11 Sep 2023
Chances are low that you will ever have the same centroid location exactly, out to 16 decimal places. I suggest you use ismembertol to find locations that are within one pixel unit of each other.

Catégories

En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by