0

I have many "grayscale" images i.e. 2d-arrays like the following:

image of a slightly tilted dark rectangle on bright background

i.e. dark rectangles which are tilted by an angle $\alpha \in [-3^\circ, 3^\circ]$ and a bright but noisy background. I have a (rather slow) method to determine the angle based on Hough transform, thus I have sufficient training data.

Question: Is there any machine learning based method to deduce the angle $\alpha$ efficiently and robustly? Precision should be at $\pm 0.3^\circ$.

Comment based update: Apart from solving the problem "somehow" analytically (e.g. by Fourier transform) I am mainly interested in how such a problem could in principle be solved by machine learning (e.g. which architecture to use).

cknoll
  • 133
  • 2
    It looks like ML is scarcely necessary: just run an edge detector over the image and go from there. Another technique would be to compute the 2D Fourier transform: it will have peaks at $\alpha$ plus integral multiples of 90°. BTW, in what sense is this color image "grayscale"? – whuber Sep 14 '23 at 14:23
  • @whuber edge detection will probably not work because I need sub-pixel precision. I will try Fourier transform. "Grayscale" is meant that it is only one channel (as opposed to RGB). In the shown image the value range is visualized with the viridis colormap of matplotlib. – cknoll Sep 14 '23 at 14:38
  • I don't understand how "sub-pixel precision" might be related to the angle of rotation or even of edge detectors. The image itself by definition has exactly one pixel of precision, but estimates derived from it--being aggregates of that information--can be very precise. – whuber Sep 14 '23 at 15:39
  • 1
    I would suggest edge detection (and thresholding) to get the outlines of the box, then image moments to get the orientation http://raphael.candelier.fr/?blog=Image%20Moments and see subpixel section of https://en.wikipedia.org/wiki/Edge_detection – seanv507 Sep 14 '23 at 15:40
  • 2
    The solution I posted at https://stats.stackexchange.com/a/581400/919 gives 89.6 degrees (equivalently, -0.4 degrees) for this image. – whuber Sep 14 '23 at 16:02
  • 1
    conv neural nets basically are adaptive forms of standard image processing algorithms. for your application, you could convert your existing alg into neural net. You have a bank of edge detection filters. then hough transform is a single filter that sums values in each rotation ("weight sharing"), rather than the typical cnn where the same filter repeated at constant shifts across the image – seanv507 Sep 15 '23 at 08:00
  • 1
    The method of image proposed by @seanv507 is very fast and works quite well (even without tresholding and edge detection). In opencv (which I use from Python) the relevant method is https://docs.opencv.org/3.4/d3/dc0/group__imgproc__shape.html#ga556a180f43cab22649c23ada36a8a139 – cknoll Sep 18 '23 at 13:00

0 Answers0