Detecting the rotation of digits in an image

I am trying to find the rotation of a given set of digits from the image. For example: There is no additional background information, only the digits are given in the input.

I have tried using methods as described: 1 , which uses the Tesseract library to solve for the rotation, but it does not work well in this case as there are no multiple lines (of text) involved in this scenario.

For this purpose, it can be assumed that the decimal point and the "mm" are always present in the inputs. Are there any other methods or any additional features that I can exploit to solve this problem?

• You could also try a 2dim fft. – Steffen Oct 21 '16 at 13:15

You can use Hough Transform to find dominant lines in the image and then based on rho & theta parameters of the Hough transform, align your text. First you need to remove unnecessary details from your image through closing as below:

binTextImage=TextImage<30;
close=imclose(binTextImage,strel('disk',20)); Then extract edges, edges=edge(close)>0; Then apply hough transform (the normal form):

H=hough(edges);
imshow(H,[]) Then find the maximal point in the hough domain,

[X Y]=find(max(H(:))==H)

The rho and theta in the position X,Y represents parameters of the dominant line. Use the theta parameter to find out how much the image is rotated.

More details in MATLAB example in following links is given: https://www.mathworks.com/help/vision/examples/text-rotation-correction.html

The height of the axis aligned bounding box attains a minimum for the horizontal alignment of your digits. The height of the box volume is also easily measured. So you can use that simple criterium to find the horizontally aligned position.

The bounding box is also sufficiently close to the convex hull of your shape. That means finding the convex hull and minimising its height by rotation will work too.