How can I find the density of an object in an image?

4 views (last 30 days)
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!

Accepted Answer

Image Analyst
Image Analyst on 29 May 2017
Use regionprops to get centroid, then pdist2 to get nearest neighbor distances.
  2 Comments
Noy Danino
Noy Danino on 31 May 2017
thank you! I used regionprops and now I see all the centroids. I've read about the function pdist2 and I don't understand who are X,Y in my case - D = pdist2(X,Y) can you help me?
Image Analyst
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);

Sign in to comment.

More Answers (1)

uday E
uday E on 21 Nov 2020
density of an object can be imaged using as
  1 Comment
Image Analyst
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????

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!