Leptonica 1.68
C Image Processing Library

Toplevel image rotation by interpolation and sampling. More...
Go to the source code of this file.
Functions  
PIX *  pixRotate (PIX *pixs, l_float32 angle, l_int32 type, l_int32 incolor, l_int32 width, l_int32 height) 
PIX *  pixEmbedForRotation (PIX *pixs, l_float32 angle, l_int32 incolor, l_int32 width, l_int32 height) 
PIX *  pixRotateBySampling (PIX *pixs, l_int32 xcen, l_int32 ycen, l_float32 angle, l_int32 incolor) 
PIX *  pixRotateBinaryNice (PIX *pixs, l_float32 angle, l_int32 incolor) 
PIX *  pixRotateWithAlpha (PIX *pixs, l_float32 angle, PIX *pixg, l_float32 fract) 
PIX *  pixRotateGammaXform (PIX *pixs, l_float32 gamma, l_float32 angle, l_float32 fract) 
Variables  
l_float32  AlphaMaskBorderVals [2] 
static const l_float32  VERY_SMALL_ANGLE = 0.001 
Toplevel image rotation by interpolation and sampling.
General rotation about image center PIX *pixRotate() PIX *pixEmbedForRotation() General rotation by sampling PIX *pixRotateBySampling() Nice (slow) rotation of 1 bpp image PIX *pixRotateBinaryNice() Rotation including alpha (blend) component and gamma transform PIX *pixRotateWithAlpha() PIX *pixRotateGammaXform() Rotations are measured in radians; clockwise is positive. The general rotation pixRotate() does the best job for rotating about the image center. For 1 bpp, it uses shear; for others, it uses either shear or area mapping. If requested, it expands the output image so that no pixels are lost in the rotation, and this can be done on multiple successive shears without expanding beyond the maximum necessary size.
Definition in file rotate.c.
PIX* pixRotate  (  PIX *  pixs, 
l_float32  angle,  
l_int32  type,  
l_int32  incolor,  
l_int32  width,  
l_int32  height  
) 
Input: pixs (1, 2, 4, 8, 32 bpp rgb) angle (radians; clockwise is positive) type (L_ROTATE_AREA_MAP, L_ROTATE_SHEAR, L_ROTATE_SAMPLING) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) width (original width; use 0 to avoid embedding) height (original height; use 0 to avoid embedding) Return: pixd, or null on error
Notes: (1) Rotation is about the center of the image. (2) For very small rotations, just return a clone. (3) Rotation brings either white or black pixels in from outside the image. (4) Above 20 degrees, if rotation by shear is requested, we rotate by sampling. (5) Colormaps are removed for rotation by area map and shear. (6) The dest can be expanded so that no image pixels are lost. To invoke expansion, input the original width and height. For repeated rotation, use of the original width and height allows the expansion to stop at the maximum required size, which is a square with side = sqrt(w*w + h*h).
*** Warning: implicit assumption about RGB component ordering ***
Definition at line 83 of file rotate.c.
References ERROR_PTR, FALSE, L_ABS, L_BRING_IN_BLACK, L_BRING_IN_WHITE, L_ROTATE_AREA_MAP, L_ROTATE_SAMPLING, L_ROTATE_SHEAR, L_WARNING, NULL, pixClone(), pixcmapAddBlackOrWhite(), pixConvertTo8(), pixDestroy(), pixEmbedForRotation(), pixGetColormap(), pixGetDepth(), pixGetDimensions(), pixRemoveColormap(), pixRotateAMColor(), pixRotateAMGray(), pixRotateBySampling(), pixRotateShearCenter(), PROCNAME, REMOVE_CMAP_BASED_ON_SRC, and VERY_SMALL_ANGLE.
Referenced by main(), pixDeskewBarcode(), pixDeskewGeneral(), pixRotateWithAlpha(), rotateTest(), and RotateTest().
PIX* pixEmbedForRotation  (  PIX *  pixs, 
l_float32  angle,  
l_int32  incolor,  
l_int32  width,  
l_int32  height  
) 
Input: pixs (1, 2, 4, 8, 32 bpp rgb) angle (radians; clockwise is positive) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) width (original width; use 0 to avoid embedding) height (original height; use 0 to avoid embedding) Return: pixd, or null on error
Notes: (1) For very small rotations, just return a clone. (2) Generate larger image to embed pixs if necessary, and place in the center. (3) Rotation brings either white or black pixels in from outside the image. For colormapped images where there is no white or black, a new color is added if possible for these pixels; otherwise, either the lightest or darkest color is used. In most cases, the colormap will be removed prior to rotation. (4) The dest is to be expanded so that no image pixels are lost after rotation. Input of the original width and height allows the expansion to stop at the maximum required size, which is a square with side equal to sqrt(w*w + h*h). (5) For an arbitrary angle, the expansion can be found by considering the UL and UR corners. As the image is rotated, these move in an arc centered at the center of the image. Normalize to a unit circle by dividing by half the image diagonal. After a rotation of T radians, the UL and UR corners are at points T radians along the unit circle. Compute the x and y coordinates of both these points and take the max of absolute values; these represent the half width and half height of the containing rectangle. The arithmetic is done using formulas for sin(a+b) and cos(a+b), where b = T. For the UR corner, sin(a) = h/d and cos(a) = w/d. For the UL corner, replace a by (pi  a), and you have sin(pi  a) = h/d, cos(pi  a) = w/d. The equations given below follow directly.
Definition at line 217 of file rotate.c.
References ERROR_PTR, L_ABS, L_BRING_IN_BLACK, L_BRING_IN_WHITE, L_MAX, L_SET_BLACK, L_SET_WHITE, NULL, PIX_SRC, pixClone(), pixCopyColormap(), pixCopyResolution(), pixCopyText(), pixCreate(), pixGetDimensions(), pixRasterop(), pixSetBlackOrWhite(), PROCNAME, and VERY_SMALL_ANGLE.
Referenced by pixRotate().
PIX* pixRotateBySampling  (  PIX *  pixs, 
l_int32  xcen,  
l_int32  ycen,  
l_float32  angle,  
l_int32  incolor  
) 
Input: pixs (1, 2, 4, 8, 16, 32 bpp rgb; can be cmapped) xcen (x value of center of rotation) ycen (y value of center of rotation) angle (radians; clockwise is positive) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) Return: pixd, or null on error
Notes: (1) For very small rotations, just return a clone. (2) Rotation brings either white or black pixels in from outside the image. (3) Colormaps are retained.
Definition at line 292 of file rotate.c.
References CLEAR_DATA_BIT, ERROR_PTR, FREE, GET_DATA_BIT, GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_FOUR_BYTES, GET_DATA_QBIT, GET_DATA_TWO_BYTES, L_ABS, L_BRING_IN_BLACK, L_BRING_IN_WHITE, NULL, pixClone(), pixCreateTemplateNoInit(), pixGetData(), pixGetDimensions(), pixGetLinePtrs(), pixGetWpl(), pixSetBlackOrWhite(), PROCNAME, SET_DATA_BIT, SET_DATA_BYTE, SET_DATA_DIBIT, SET_DATA_FOUR_BYTES, SET_DATA_QBIT, SET_DATA_TWO_BYTES, and VERY_SMALL_ANGLE.
Referenced by main(), and pixRotate().
Input: pixs (1 bpp) angle (radians; clockwise is positive; about the center) incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK) Return: pixd, or null on error
Notes: (1) For very small rotations, just return a clone. (2) This does a computationally expensive rotation of 1 bpp images. The fastest rotators (using shears or subsampling) leave visible horizontal and vertical shear lines across which the image shear changes by one pixel. To ameliorate the visual effect one can introduce random dithering. One way to do this in a nottoorandom fashion is given here. We convert to 8 bpp, do a very small blur, rotate using linear interpolation (same as area mapping), do a small amount of sharpening to compensate for the initial blur, and threshold back to binary. The shear lines are magically removed. (3) This operation is about 5x slower than rotation by sampling.
Definition at line 424 of file rotate.c.
References ERROR_PTR, L_BRING_IN_BLACK, L_BRING_IN_WHITE, NULL, pixBlockconv(), pixConvertTo8(), pixDestroy(), pixGetDepth(), pixRotateAM(), pixThresholdToBinary(), pixUnsharpMasking(), and PROCNAME.
Input: pixs (32 bpp rgb) angle (radians; clockwise is positive) pixg (<optional> 8 bpp, can be null) fract (between 0.0 and 1.0, with 0.0 fully transparent and 1.0 fully opaque) Return: pixd, or null on error
Notes: (1) The alpha channel is transformed separately from pixs, and aligns with it, being fully transparent outside the boundary of the transformed pixs. For pixels that are fully transparent, a blending function like pixBlendWithGrayMask() will give zero weight to corresponding pixels in pixs. (2) Rotation is about the center of the image; for very small rotations, just return a clone. The dest is automatically expanded so that no image pixels are lost. (3) Rotation is by area mapping. It doesn't matter what color is brought in because the alpha channel will be transparent (black) there. (4) If pixg is NULL, it is generated as an alpha layer that is partially opaque, using . Otherwise, it is cropped to pixs if required and is ignored. The alpha channel in pixs is never used. (4) Colormaps are removed. (5) The default setting for the border values in the alpha channel is 0 (transparent) for the outermost ring of pixels and (0.5 * fract * 255) for the second ring. When blended over a second image, this (a) shrinks the visible image to make a clean overlap edge with an image below, and (b) softens the edges by weakening the aliasing there. Use l_setAlphaMaskBorder() to change these values.
*** Warning: implicit assumption about RGB component ordering ***
Definition at line 492 of file rotate.c.
References AlphaMaskBorderVals, ERROR_PTR, L_ALPHA_CHANNEL, L_BRING_IN_BLACK, L_BRING_IN_WHITE, L_ROTATE_AREA_MAP, L_WARNING, NULL, pixCreate(), pixDestroy(), pixGetColormap(), pixGetDepth(), pixGetDimensions(), pixResizeToMatch(), pixRotate(), pixSetAll(), pixSetAllArbitrary(), pixSetBorderRingVal(), pixSetRGBComponent(), and PROCNAME.
Referenced by main(), and pixRotateGammaXform().
Input: pixs (32 bpp rgb) gamma (gamma correction; must be > 0.0) angle (radians; clockwise is positive) fract (between 0.0 and 1.0, with 1.0 fully transparent) Return: pixd, or null on error
Notes: (1) This wraps a gamma/inversegamma photometric transform around pixRotateWithAlpha(). (2) For usage, see notes in pixRotateWithAlpha() and pixGammaTRCWithAlpha(). (3) The basic idea of a gamma/inversegamma transform is to remove gamma correction before rotating and restore it afterward. The effects can be subtle, but important for some applications. For example, using gamma > 1.0 will cause the dark areas to become somewhat lighter and slightly reduce aliasing effects when blending using the alpha channel.
Definition at line 567 of file rotate.c.
References ERROR_PTR, L_WARNING, NULL, pixDestroy(), pixGammaTRCWithAlpha(), pixGetDepth(), pixRotateWithAlpha(), and PROCNAME.
Referenced by main().
const l_float32 VERY_SMALL_ANGLE = 0.001 [static] 
Definition at line 48 of file rotate.c.
Referenced by pixEmbedForRotation(), pixRotate(), and pixRotateBySampling().