1
$\begingroup$

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

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?

$\endgroup$
2
  • $\begingroup$ Something involving ImageData, MapIndexed, and GatherBy I suppose? $\endgroup$
    – user484
    Nov 24, 2016 at 18:54
  • 2
    $\begingroup$ 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. $\endgroup$
    – MarcoB
    Nov 24, 2016 at 20:38

1 Answer 1

2
$\begingroup$

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] := 
 Flatten[Pick[ImageData[img], Round[radius/bin], Round[r/bin]]]
$\endgroup$
1
  • $\begingroup$ Very nice, thanks. I was going to write up my attempt but you beat me to it. This makes a lot of sense and works nicely! $\endgroup$
    – Mason
    Nov 24, 2016 at 23:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.