Cross Validated
2026-11-01 20:15 UTC
By Daniil Zuev
AI-113-20261101-social-media-0db02e92
How to estimate density of a spot pattern?
I have a binary mask for an image of biological cells, the cells have fairly arbitrary areas and distances between them. I'm interested in finding some way to describe the distribution of these cells on the image. One of my ideas has been to convert image to floats and do a 2D KDE on it. However, i'm not sure how to choose kernel, or how to convert the resulting density map to some sensible units (e.g. percentage of image occupied by cells), and whether it's a good solution at all. My another idea was to just divide areas of cells by square of distance to the N nearest neighbors, as it will be roughly proportional to the density. However this approach can fail on boundaries between regions where cell density is very different (I have a fair amount of those cases, as cells like to form layers, spheres, etc). References to papers and books are welcome. Here is some python code that can generate an artificial image resembling ones i'm dealing with: import numpy as np from skimage import draw import matplotlib.pyplot as plt np.random.seed(42) img_shape = (500, 500) img = np.zeros(img_shape, dtype=bool) # empty binary mask 500x500 px N_spots = 100 spot_centers = np.random.randint(low=0, high=500, size=(N_spots, 2)) spot_radii = np.random.randint(low=3, high=10, size=(N_spots, 2)) for (cx, cy), (rx, ry) in zip(spot_centers, spot_radii): img[draw.ellipse(cy, cx, ry, rx, shape=img_shape)] = 1 plt.imshow(img, cmap="gray") Clarification suggested by comments My goal is to obtain for e…
I have a binary mask for an image of biological cells, the cells have fairly arbitrary areas and distances between them. I'm interested in finding some way to describe the distribution of these cells on the image. One of my ideas has been to convert image to floats and do a 2D KDE on it. However, i'm not sure how to choose kernel, or how to convert the resulting density map to some sensible units (e.g. percentage of image occupied by cells), and whether it's a good solution at all. My another idea was to just divide areas of cells by square of distance to the N nearest neighbors, as it will be roughly proportional to the density. However this approach can fail on boundaries between regions where cell density is very different (I have a fair amount of those cases, as cells like to form layers, spheres, etc). References to papers and books are welcome. Here is some python code that can generate an artificial image resembling ones i'm dealing with: import numpy as np from skimage import draw import matplotlib.pyplot as plt np.random.seed(42) img_shape = (500, 500) img = np.zeros(img_shape, dtype=bool) # empty binary mask 500x500 px N_spots = 100 spot_centers = np.random.randint(low=0, high=500, size=(N_spots, 2)) spot_radii = np.random.randint(low=3, high=10, size=(N_spots, 2)) for (cx, cy), (rx, ry) in zip(spot_centers, spot_radii): img[draw.ellipse(cy, cx, ry, rx, shape=img_shape)] = 1 plt.imshow(img, cmap="gray") Clarification suggested by comments My goal is to obtain for e…
Full article content could not be extracted automatically. Read the original below.
Source:
Cross Validated
· stats.stackexchange.com