Leptonica 1.68
C Image Processing Library

rotateam.c File Reference

Interpolated image rotation. More...

#include <stdio.h>
#include <string.h>
#include "allheaders.h"

Go to the source code of this file.

Functions

PIXpixRotateAM (PIX *pixs, l_float32 angle, l_int32 incolor)
PIXpixRotateAMColor (PIX *pixs, l_float32 angle, l_uint32 colorval)
PIXpixRotateAMGray (PIX *pixs, l_float32 angle, l_uint8 grayval)
PIXpixRotateAMCorner (PIX *pixs, l_float32 angle, l_int32 incolor)
PIXpixRotateAMColorCorner (PIX *pixs, l_float32 angle, l_uint32 fillval)
PIXpixRotateAMGrayCorner (PIX *pixs, l_float32 angle, l_uint8 grayval)
PIXpixRotateAMColorFast (PIX *pixs, l_float32 angle, l_uint32 colorval)

Variables

static const l_float32 VERY_SMALL_ANGLE = 0.001

Detailed Description

Interpolated image rotation.

   Grayscale and color rotation for area mapping (== interpolation)

       Rotation about the image center
                PIX     *pixRotateAM()
                PIX     *pixRotateAMColor()
                PIX     *pixRotateAMGray()

       Rotation about the UL corner of the image
                PIX     *pixRotateAMCorner()
                PIX     *pixRotateAMColorCorner()
                PIX     *pixRotateAMGrayCorner()

       Faster color rotation about the image center
                PIX     *pixRotateAMColorFast()

   Rotations are measured in radians; clockwise is positive.

   The basic area mapping grayscale rotation works on 8 bpp images.
   For color, the same method is applied to each color separately.
   This can be done in two ways: (1) as here, computing each dest
   rgb pixel from the appropriate four src rgb pixels, or (2) separating
   the color image into three 8 bpp images, rotate each of these,
   and then combine the result.  Method (1) is about 2.5x faster.
   We have also implemented a fast approximation for color area-mapping
   rotation (pixRotateAMColorFast()), which is about 25% faster
   than the standard color rotator.  If you need the extra speed,
   use it.

   Area mapping works as follows.  For each dest
   pixel you find the 4 source pixels that it partially
   covers.  You then compute the dest pixel value as
   the area-weighted average of those 4 source pixels.
   We make two simplifying approximations:

     -  For simplicity, compute the areas as if the dest
        pixel were translated but not rotated.

     -  Compute area overlaps on a discrete sub-pixel grid.
        Because we are using 8 bpp images with 256 levels,
        it is convenient to break each pixel into a
        16x16 sub-pixel grid, and count the number of
        overlapped sub-pixels.

   It is interesting to note that the digital filter that
   implements the area mapping algorithm for rotation
   is identical to the digital filter used for linear
   interpolation when arbitrarily scaling grayscale images.

   The advantage of area mapping over pixel sampling
   in grayscale rotation is that the former naturally
   blurs sharp edges ("anti-aliasing"), so that stair-step
   artifacts are not introduced.  The disadvantage is that
   it is significantly slower.

   But it is still pretty fast.  With standard 3 GHz hardware,
   the anti-aliased (area-mapped) color rotation speed is
   about 15 million pixels/sec.

   The function pixRotateAMColorFast() is about 10-20% faster
   than pixRotateAMColor().  The quality is slightly worse,
   and if you make many successive small rotations, with a
   total angle of 360 degrees, it has been noted that the
   center wanders -- it seems to be doing a 1 pixel translation
   in addition to the rotation.

Definition in file rotateam.c.


Function Documentation

PIX* pixRotateAM ( PIX pixs,
l_float32  angle,
l_int32  incolor 
)

pixRotateAM()

Input: pixs (2, 4, 8 bpp gray or colormapped, or 32 bpp RGB) angle (radians; clockwise is positive) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) Return: pixd, or null on error

Notes: (1) Rotates about image center. (2) A positive angle gives a clockwise rotation. (3) Brings in either black or white pixels from the boundary.

Definition at line 110 of file rotateam.c.

References ERROR_PTR, FALSE, L_ABS, L_BRING_IN_WHITE, NULL, pixClone(), pixConvertTo8(), pixDestroy(), pixGetDepth(), pixRemoveColormap(), pixRotateAMColor(), pixRotateAMGray(), PROCNAME, REMOVE_CMAP_BASED_ON_SRC, and VERY_SMALL_ANGLE.

Referenced by main(), and pixRotateBinaryNice().

PIX* pixRotateAMColor ( PIX pixs,
l_float32  angle,
l_uint32  colorval 
)

pixRotateAMColor()

Input: pixs (32 bpp) angle (radians; clockwise is positive) colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE) Return: pixd, or null on error

Notes: (1) Rotates about image center. (2) A positive angle gives a clockwise rotation. (3) Specify the color to be brought in from outside the image.

Definition at line 171 of file rotateam.c.

References ERROR_PTR, L_ABS, NULL, pixClone(), pixCreateTemplate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, rotateAMColorLow(), and VERY_SMALL_ANGLE.

Referenced by main(), pixRotate(), and pixRotateAM().

PIX* pixRotateAMGray ( PIX pixs,
l_float32  angle,
l_uint8  grayval 
)

pixRotateAMGray()

Input: pixs (8 bpp) angle (radians; clockwise is positive) grayval (0 to bring in BLACK, 255 for WHITE) Return: pixd, or null on error

Notes: (1) Rotates about image center. (2) A positive angle gives a clockwise rotation. (3) Specify the grayvalue to be brought in from outside the image.

Definition at line 216 of file rotateam.c.

References ERROR_PTR, L_ABS, NULL, pixClone(), pixCreateTemplate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, rotateAMGrayLow(), and VERY_SMALL_ANGLE.

Referenced by main(), pixRotate(), and pixRotateAM().

PIX* pixRotateAMCorner ( PIX pixs,
l_float32  angle,
l_int32  incolor 
)

pixRotateAMCorner()

Input: pixs (1, 2, 4, 8 bpp gray or colormapped, or 32 bpp RGB) angle (radians; clockwise is positive) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) Return: pixd, or null on error

Notes: (1) Rotates about the UL corner of the image. (2) A positive angle gives a clockwise rotation. (3) Brings in either black or white pixels from the boundary.

Definition at line 264 of file rotateam.c.

References ERROR_PTR, FALSE, L_ABS, L_BRING_IN_WHITE, NULL, pixClone(), pixConvertTo8(), pixDestroy(), pixGetDepth(), pixRemoveColormap(), pixRotateAMColorCorner(), pixRotateAMGrayCorner(), PROCNAME, REMOVE_CMAP_BASED_ON_SRC, and VERY_SMALL_ANGLE.

Referenced by main(), and RotateTest().

PIX* pixRotateAMColorCorner ( PIX pixs,
l_float32  angle,
l_uint32  fillval 
)

pixRotateAMColorCorner()

Input: pixs angle (radians; clockwise is positive) colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE) Return: pixd, or null on error

Notes: (1) Rotates the image about the UL corner. (2) A positive angle gives a clockwise rotation. (3) Specify the color to be brought in from outside the image.

Definition at line 323 of file rotateam.c.

References ERROR_PTR, L_ABS, NULL, pixClone(), pixCreateTemplate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, rotateAMColorCornerLow(), and VERY_SMALL_ANGLE.

Referenced by pixRotateAMCorner().

PIX* pixRotateAMGrayCorner ( PIX pixs,
l_float32  angle,
l_uint8  grayval 
)

pixRotateAMGrayCorner()

Input: pixs angle (radians; clockwise is positive) grayval (0 to bring in BLACK, 255 for WHITE) Return: pixd, or null on error

Notes: (1) Rotates the image about the UL corner. (2) A positive angle gives a clockwise rotation. (3) Specify the grayvalue to be brought in from outside the image.

Definition at line 368 of file rotateam.c.

References ERROR_PTR, L_ABS, NULL, pixClone(), pixCreateTemplate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, rotateAMGrayCornerLow(), and VERY_SMALL_ANGLE.

Referenced by pixRotateAMCorner().

PIX* pixRotateAMColorFast ( PIX pixs,
l_float32  angle,
l_uint32  colorval 
)

pixRotateAMColorFast()

Input: pixs angle (radians; clockwise is positive) colorval (e.g., 0 to bring in BLACK, 0xffffff00 for WHITE) Return: pixd, or null on error

Notes: (1) This rotates a color image about the image center. (2) A positive angle gives a clockwise rotation. (3) It uses area mapping, dividing each pixel into 16 subpixels. (4) It is about 10% to 20% faster than the more accurate linear interpolation function pixRotateAMColor(), which uses 256 subpixels.

*** Warning: implicit assumption about RGB component ordering ***

Definition at line 422 of file rotateam.c.

References ERROR_PTR, L_ABS, NULL, pixClone(), pixCreateTemplate(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), PROCNAME, rotateAMColorFastLow(), and VERY_SMALL_ANGLE.

Referenced by main(), and RotateTest().


Variable Documentation

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines