I am trying to find the rotation of a given set of digits from the image. For example: enter image description here

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?

  • $\begingroup$ You could also try a 2dim fft. $\endgroup$
    – 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:


enter image description here

Then extract edges, edges=edge(close)>0; enter image description here Then apply hough transform (the normal form):


enter image description here 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.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.