2

I'm pretty new to numpy. I have been looking around how to do this but I can't find anything easy enough.

This is the problem. I'm identifying particles in red (it's ok and done) so I have an array with locations.

I make a new image with these locations with grey dilation and scipy.ndimage, having the dilated positions with a value and the rest 0.

Then I multiply this image with another image (green color), so that the new color only has signals where you have particles in red. What I want to do is to detect the mean of intensities in this other color per given point, in a given radius or square for example.

How can I do this? Do I make scipy.ndimage.measurements.label in the initial color and then use the same array indexes to have the means? Or I can just have x,y coordinates and do the mean() over a given radius?

Diego C Nascimento
  • 2,801
  • 1
  • 17
  • 23
João Mamede
  • 129
  • 12
  • Are you essentially wanting to perform a 2D moving average over your image? – bheklilr Oct 11 '13 at 21:15
  • If I understand correctly a 2D moving average is to smooth the image (or do convolutions). If that's the case, no. What I want to know are the values around multiple given x,y 's (giving a radius or the area of a square) and obtain a mean value of these positions. Is there an easy callable function for this? – João Mamede Oct 11 '13 at 21:25
  • Ok, I would tone it down a little bit. You have a 2D array (the red image) where only some of the positions are different from zero. You multiply it by another 2D array, so the result is a 2D array where only the points different from zero in the first one is itself different from zero. Now, where do you want to meassure those averages you are talking about? – Jblasco Oct 11 '13 at 21:28
  • Exactly Jblasco. That's what I am doing. But now I want to measure the averages of each point around a given x and y. For example a = np.ones((10,10)) ; a[5,5] = 1 I want to know all the values around 5,5 with a given radius (structuring element of size (2,2 or 3,3)?) and calculate the mean. This, in the output array from the multiplication – João Mamede Oct 11 '13 at 21:32
  • So you want to specify coordinates around which to collect the mean? – bheklilr Oct 11 '13 at 21:33
  • 2
    This question should help you out. You can create a "circular" mask using `ogrid`, then use it to select the data you want to take the average of: http://stackoverflow.com/questions/8647024/how-to-apply-a-disc-shaped-mask-to-a-numpy-array – bheklilr Oct 11 '13 at 21:41
  • Yes that's want I want, thanks. So basically I have to do a new mask for every coordinate and measure the mean. I guess that's easy!! thanks a bunch. I guess I could use slicing around x and y as well if I want a square mask. – João Mamede Oct 11 '13 at 21:59
  • http://scipy-lectures.github.io/advanced/image_processing/#measuring-objects-properties-ndimage-measurements <- good tutorial – tacaswell Oct 18 '13 at 03:08

0 Answers0