0

I have a graph with a circular x-axis and some objects in it.

  1. I want to convert the graph and make its x-axis horizontal.
  2. I want to measure the height (pixel distance) of each object above the x-axis.

I tried this with numpy arrays but was only able to get the vertical pixel difference between axis and object, not the true minimum pixel difference. I think I should make an iteration over all circular x-axis points and measure the distance to one object but how would I do that?

enter image description here

Edit: This is the original Image

enter image description here

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Artur Müller Romanov
  • 4,417
  • 10
  • 73
  • 132
  • 4
    I think if you know the circle center you can use polar coordinates to transform the graph and/or to measure the distance – Micka Oct 09 '18 at 07:49
  • First I convert the image into numpy arrays. But how do I convert a numpy array into polar coordinates? – Artur Müller Romanov Oct 09 '18 at 08:28
  • Is this graph created by yourself, i.e. are you working with a matplotlib figure? Or do you have a pixel image of a graph? – ImportanceOfBeingErnest Oct 09 '18 at 08:35
  • Please take a look at the Edit-section. I have an image of a pipe. I need to measure the distance to the wall (lower red line). So I need the minimum distance to the wall. Problem is the object can move freely in there, so I really need the minimum distance to the wall at a given time. I added the red circles with `cv2.circle()` function. In the end I want to plot a x,y-graph that shows the position of the object relative to the outer wall (lower red line) and inner wall (upper red line). – Artur Müller Romanov Oct 09 '18 at 08:41
  • Take a look at [warpPolar](https://docs.opencv.org/3.4.2/da/d54/group__imgproc__transform.html#ga49481ab24fdaa0ffa4d3e63d14c0d5e4) function – Gopiraj Oct 10 '18 at 05:38

1 Answers1

1

I think there are several potential solutions to your problem.

1 - Converting back to a cartesian image

This is a straightforward solution : convert your polar image back to cartesian coordinates, and compute the distance to your two horizontal lines. You will need, for that, the center and radii of your two circles, which I assume you have already since you have plotted them on the image. Technical solutions for the warping are discussed in this SO question : Reprojecting polar to cartesian grid

2 - Direct geometrical computation

This is even simpler than the first point, and a solution you might implement directly if you don't need further processing.

Again, assuming that for each circle you know the position (X,Y) of its center, as well as its radius R. If you have a point of coordinates (x,y) in the image you can compute the distance to the circle center using a simple Euclidean distance computation : d = sqrt( (X-x)**2 + (Y-y)**2 ). The distance to the circle is then simply R-d. Written in python using numpy, that would give something like :

def distToCircle(pt, center, R):
    d = np.linalg.norm(center-pt)
    return R-d
Ben
  • 441
  • 3
  • 10