-1

I would like to calculate the angle of the tangent on a given white to black transition point on an image that consists entirely of black and white pixels and displays simple shapes such as squares, circles or triangles.

Zooming in on an image like that would look like this:

enter image description here

If you were to pick any of the black pixels next to a white one, my solution would be to follow the edge for a few pixels, then define a formula based on the curvature of the pixels and calculate the exact value of the defined point. Is there a simpler way of doing that? The resolution of the images is around 800x600 pixels so a fairly accurate estiamate of the angle of the provided point should be possible.

In my current approach I follow the edge line of the shape for about ten pixels, but I'm not sure where to go from there. Is there a library that already performs this kind of calculation for you? How many pixels would you need in order to be able to make an accurate judgement of the angle at that point?

Yes
  • 339
  • 3
  • 19
  • 1
    You have a coastline paradox here: If You try to measure with a different accuracy, You might get vastly different results. If the line were anti-aliased, *then* You could reconstruct it with the [Marching Squares](https://en.wikipedia.org/wiki/Marching_squares) algorithm, if that's an option – IWonderWhatThisAPIDoes Jan 29 '22 at 14:31
  • sobel filter in x and y direction gives you gradient components – Christoph Rackwitz Jan 29 '22 at 15:07
  • There is no relation between the curvature and the slope (which, presumably, is what you are after). –  Jan 29 '22 at 16:04
  • 1
    I suspect an XY problem. What exactly do you want to do ? –  Jan 29 '22 at 16:14

1 Answers1

0

Such a measurement is highly inaccurate on binary images, if not unusable.

If you measure on two neighboring pixels, the angle will be one of 0° or ±45°, so the angular resolution is very poor !

You can compute on several pixels to improve that resolution (five pixels correspond to like 11°), but now you are no more sure that the direction is the same, because the shape might be rounded.


If in your case the repertoire of shapes is known to be simple, you'd better perform fitting of the whole shapes before querying the tangents.