# Binning points in an image based on radius

What I'm trying to do is take an image,

and then make a list of intensities as a function of distance from some point. So I've used a clever algorithm I found here to detect the centre of these circles, it's the point {317.974, -136.362} (notice this is outside of the image). What I then want is a list where each element of the list is a list of the intensities at a given euclidean distance from the point {317.974, -136.362}. I'd like the binning on the radii to be fairly small as well, maybe adjustable?

My goal with this is that I then want to take the mean of each of these lists so that I have a mean intensity at a given radius and a standard deviation for that given intensity. I think I could do this procedurally but I'm wanting to do it with a more functional Mathematica style. Could anyone help me figure out the fest way to do this?

• Something involving ImageData, MapIndexed, and GatherBy I suppose? – Rahul Nov 24 '16 at 18:54
• In your post you pose a problem and a list of requirements, and simply ask for somebody to do all the work for you. Such a post typically does not garner much attention, as it boils down to unpaid consultant's work. Have you tried anything on your own? If you have, share your attempts. If you haven't, then give it a shot yourself. We will be happy to help with specific issues that might arise from the implementation. – MarcoB Nov 24 '16 at 20:38

You can basically use the same tools as in my answer you mentioned. Define:

img = Import["https://i.stack.imgur.com/dYnlY.png"];
center = {317.974, -136.362};
{w, h} = ImageDimensions[img];
xArr = Array[N[#2] &, {h, w}] - 1;
yArr = h - Array[N[#1] &, {h, w}];


Now xArr is an array with the same dimensions as img, containing the x-coordinate of each point, and yArr contains the y-coordinate of each point.

Using this we can easily calculate an array that contains the radius for each point:

radius = Sqrt[(xArr - center[[1]])^2 + (yArr - center[[2]])^2];


And then simply use Pick to get the pixel values for some radius value, so:

Flatten[Pick[ImageData[img], Round[radius], 200]]


returns the pixels with radius 199.5..200.5

Binning can also be included:

grayvaluesAtRadius[r_, bin_: 1] :=