Search code examples
leptonica

Image pixels getting lost while rotation using leptonica


I want to extract text from an image for which I need to rotate it in steps of 90 degrees.When I rotate the image using

pixRotate(image, deg2rad * angle, L_ROTATE_AREA_MAP, L_BRING_IN_BLACK, 0, 0)

some pixels at the top and bottom are lost.The variations I have tried are

pixRotate(image, deg2rad * angle, L_ROTATE_AREA_MAP, L_BRING_IN_BLACK, w, h)

and also with L_ROTATE_SHEAR, L_ROTATE_SAMPLING.However The pixels near the boundary are getting lost in each case.Is there a way to do this rotation without loosing pixels?


Solution

  • You have specific functions for 90°, 180° and 270° rotations, that are defined in rotateorth.c, as detailed in the documentation :

      Top-level rotation by multiples of 90 degrees: PIX *pixRotateOrth()
      180-degree rotation: PIX *pixRotate180()
      90-degree rotation (both directions): PIX *pixRotate90()
      Left-right flip: PIX     *pixFlipLR()
      Top-bottom flip: PIX     *pixFlipTB()
    

    For those rotations (90° or 180°) you should only consider the functions above, since they don't make any approximation of pixel position in the destination image (and they are much faster): so you won't loose any pixels. The pixRotate function (and the ones alike) are for any other angle.