# Find centroids and average intensities of regions in an image

The image below shows an approximately triangular array of bright spots. The intensity falls off towards the edges (Gaussian decay). There are some defects (the elongated smudge and the sharper circles that look like ripples). I have three objectives:

(1) Remove the defects.

(2) Find the positions of the centre of the bright spots.

(3) Calculate the average intensity of each bright spot. This must use a circular region that is the same size for each spot.

I will update my progress in my own answer, but hope for some suggestions.

Towards objective (2) I have the following code:

image = Import["https://i.stack.imgur.com/By4cZ.png"];
markers = MaxDetect[image, 0.05];
circles = ComponentMeasurements[markers, {"Centroid"}];
Show[image, Graphics[{Red, Thick, Circle @@ # & /@ circles[[All, 2]]}]]


This works reasonably well as shown below. However there are still spots that we can clearly see by eye that are not being captured. In addition the defects are causing false detections.

Update 01

To combat the non-detection of low-intensity spots, I am using a low pass filter to extract the overall Gaussian-ish shape, and multiplying the original image by the inverse of this shape. Thus darkening the centre and brightening the sides. Here's the code

image = Import["https://i.stack.imgur.com/By4cZ.png"];
filter = ColorNegate@LowpassFilter[image, 0.01];
filter = ImageMultiply[image, filter];
markers = MaxDetect[filter, 0.02]
centres = ComponentMeasurements[markers, {"Centroid"}];
centres = Flatten[#[[2]]] & /@ centres;
circles = Graphics[{Red, Thick, Circle /@ centres}];
Show[image, circles]


Update 02

To stop the defects causing false 'spot' detection, I use the function TotalVariationFilter to get rid of the ripples.

image = Import["https://i.stack.imgur.com/By4cZ.png"];
filter = ColorNegate@LowpassFilter[image, 0.01];
filter = ImageMultiply[image, filter];
filter = TotalVariationFilter[filter]
markers = MaxDetect[filter, 0.01]
centres = ComponentMeasurements[markers, {"Centroid"}];
centres = Flatten[#[[2]]] & /@ centres;
circles = Graphics[{Red, Thick, Circle /@ centres}];
Show[image, circles]