How can I find the density of an object in an image?
4 views (last 30 days)
Show older comments
Noy Danino
on 28 May 2017
Commented: Image Analyst
on 21 Nov 2020
I have an image of a cell. Inside it there are a lot of small organelles. I want to find out how close are they to each other, some kind of density measure but not exactly. I want to find the nearest neighbor to every organelle. I tried to use BWdist but it measure distance between pixels and in my image - not every organelle equals one pixel. do you have any ideas how to measure this? in the attached image - I want to look only at the small black dots and to find out how far are they from each other
thank you for your help!
0 Comments
Accepted Answer
Image Analyst
on 29 May 2017
Use regionprops to get centroid, then pdist2 to get nearest neighbor distances.
2 Comments
Image Analyst
on 31 May 2017
I think this code should work, but it's just off the top of my head, untested:
props = regionprops(labeledImage, 'Centroid');
% Get centroids in an N by 2 array. X in column 1, Y in column 2.
xy = reshape([props.Centroid], [], 2);
% Get distances. X and Y in pdist2() are not x and y - bad choice of names on the Mathworks part.
% They're really like xy1 and xy2, which in your case will be the same:
distances = pdist2(xy, xy);
More Answers (1)
uday E
on 21 Nov 2020
density of an object can be imaged using as
1 Comment
Image Analyst
on 21 Nov 2020
uday E, your answer was accidentally posted before you finished it. Maybe you were going to show him how to use conv2() or imfilter() to get an image that is related to the spatial density of the blobs????
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!