How do I find the mean of all the radius around a point in polar coordinates?

4 views (last 30 days)
I want to find the mean of all the pixels lying at R radius from a center point (x0,y0) in the polar image. Please help me with the code.
  2 Comments
Shubh Saxena
Shubh Saxena on 11 Jun 2018
The polar image is obtained by taking a seed point which is found out by another algorithm. Assuming that the seed point is center of the image on cartesian coordinates,can you please demonstrate me how to perform the mean. I have used cart2pol function to convert my cartesian coordinates in polar coordinates.

Sign in to comment.

Accepted Answer

John D'Errico
John D'Errico on 11 Jun 2018
Edited: John D'Errico on 11 Jun 2018
Are you asking how to find the mean of ALL pixels that lie WITHIN a radius of R, of some fixed point in the image?
If so, then that is most simply done by just using a find to locate all such pixels, then computing the mean of that set.
If that was deemed insufficiently accurate, you could write it as a numerical integration, of a function defined in polar coordinates. So now just use integral2, on a function that is computed using interp2 on the image at any location. At the end, divide the integral by the area of the indicated circle, thus pi*R^2. This turns the integral into a mean value over that domain.
Or are you asking how to find the mean value of all points that lie at exactly the radius R?
Again, this is open to interpretation as to your intent. Is the question to find the mean of all pixels that overlap by even some small amount with that circle? Again, if this is the question, just do a find against an appropriate test. Easy, peasy.
You might also get tricky, and perform a numerical integration, in this case, of a function defined on a circular path around the center point. Thus, a 1-d integration of a function defined on a circle, so integrate from 0 to 2*pi. Again, evaluate the function using interp2 at any value of theta, at a fixed R. Use pol2cart to convert the polar coordinates to cartesian pixel coordinates. At the end, divide by 2*pi to compute an effective mean value.
Or, are you asking how to compute a local, moving mean for a circular region over the entire image? This is most simply done using conv, with a unit convolution kernel. The trick is to use conv2 TWICE, applied first to your original array, and then to an array of ones. This solves the problem of what happens near the edges.
So, there are many possible questions you MIGHT be asking here. I can even think of at least one more, and at least two ways to solve that. Which is it?
Note: If I had to guess at what you are asking, I think you have a given point in an array, call it (x0,y0). Then you want to compute the mean of that array at exactly a distance R from (x0,y0). As I said, I would view this as a numerical integration of the function defined by interp2. Just integrate from 0 to 2*pi, then divide by 2*pi at the end. If this is something you will do very frequently, then there are ways to optimize the code, but that would be silly if you were to do it only once.
  5 Comments
Walter Roberson
Walter Roberson on 12 Jun 2018
Edited: Walter Roberson on 12 Jun 2018
You talk about radius "exactly" 1, and you list the four-connected points, (x-1,y), (x,y-1), (x+1,y), (x,y+1), which are indeed exactly 1 away.
Then you talk about wanting to perform the step for all radius from 1 to min(256,180,512-256,360-180) . If the continuous numbers are to be included, like radius 1.23243, 1.23440459154, then you can never finish that task. That suggests that you are only interested in the integer radius, 1, 2, 3, .... min(256,180,512-256,360-180) .
But you were taking about "exactly" radius one, which suggests that you would want "exactly" radius 2. With (256,180) as the center, that would get you only the points (254, 180), (256, 178), (258, 180), (256, 182). If you extend this, then you can demonstrate that if you want "exactly" integer radius, then you can only be talking about four points, (x-r,y), (x,y-r), (x+r,y), (x,y+r), with no other point being exactly r away. (255,179) is, for example, sqrt(2) away from (256, 180)
There are a lot of circumstances in which it makes sense to talk about pixels being "at most" a particular distance away, but talking about being exactly a particular distance away is at best talking about a thin shell of pixels, and as indicated you can prove that the thin shell has only 4 pixels.
So you need to clarify for us what you want. Do you want all of the points that are at most a particular distance away (filled circle)? Do you want the set of points that would be the outer boundary of the filled circle -- and if so, then should the outer boundary be determined by 4-connection or by 8 connection?
4-connected version:
++
++
+
8-connected version:
++
+
+
In determining whether 50% of a pixel lies within the circle, then should the coordinates of any given pixel be considered to refer to the center of the pixel, or to refer to the bottom left corner of the pixel? And will you only be working with integer coordinates and integer radii ?
Shubh Saxena
Shubh Saxena on 13 Jun 2018
I want 8 connected points. For that, I have to make an algorithm which takes out the mean of all the pixels lying on that radii.

Sign in to comment.

More Answers (0)

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!