I have a list of points, which represent positions of peaks in an image. The nature of the image itself shouldn't matter, as I already have the peak positions.
As a simple example, consider the following code, which produces the image below.
points = {{27, 38}, {31, 50}, {33, 56}, {34, 38}, {39, 51}, {39,
63}, {40, 31}, {42, 45}, {42, 55}, {47, 27}, {47, 50}, {48,
35}, {48, 65}, {49, 43}, {52, 57}, {54, 50}};
img = ReplacePart[ConstantArray[0., {96, 96}], points -> 1.];
img = ImageAdjust@GaussianFilter[ImageRotate@Image@img, 3.];
Show[Image[img, ImageSize -> Large],
Graphics[{Red, Circle[#, 4] & /@ points}]]
I'm interested in extracting the region of the image around each point, which will be a ragged array. (I don't want square patches).
I'd like the result to be a list of the $(x,y)$ coordinates of the pixels contained within each region.
For example, I've added some red circles around each point.
- For the solitary circles, the part I'd like to extract is simply the coordinates of all the pixels within the circle.
- The tricky part is for the points where the circles overlap, particularly in the middle of the image. In this case I want to extract the pixels within the union of the overlapping circles. For example, these two circles overlap, so I want the coordinates of the pixels in the region below:
MorphologicalComponents
is one way to do it, as, of course, instead of drawing the points as Gaussians, I could draw them as circles. This can be extended to retrieve the pixel coordinates within each region.
dImg = ColorNegate@
Binarize@Rasterize[Graphics[{Disk[#, 3.5] & /@ points}]]
GraphicsRow[{dImg, MorphologicalComponents[dImg] // Colorize},
ImageSize -> Large]
Ideally, I'm looking for a non-image-based approach that uses two inputs.
- The list of points (e.g. as given at the top of the question)
- The radius of the circles, in pixels
Although if the graphical approach using MorphologicalComponents
is the most efficient, then so be it.