Leptonica 1.68
C Image Processing Library

fpix2.c File Reference

FPix operations: interconversion FPix <-> Pix; borders; rasterop; arithmetic. More...

#include "allheaders.h"

Go to the source code of this file.

Functions

FPIXpixConvertToFPix (PIX *pixs, l_int32 ncomps)
PIXfpixConvertToPix (FPIX *fpixs, l_int32 outdepth, l_int32 negvals, l_int32 errorflag)
PIXfpixDisplayMaxDynamicRange (FPIX *fpixs)
DPIXfpixConvertToDPix (FPIX *fpix)
FPIXdpixConvertToFPix (DPIX *dpix)
l_int32 fpixGetMin (FPIX *fpix, l_float32 *pminval, l_int32 *pxminloc, l_int32 *pyminloc)
l_int32 fpixGetMax (FPIX *fpix, l_float32 *pmaxval, l_int32 *pxmaxloc, l_int32 *pymaxloc)
FPIXfpixAddBorder (FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
FPIXfpixRemoveBorder (FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
FPIXfpixAddMirroredBorder (FPIX *fpixs, l_int32 left, l_int32 right, l_int32 top, l_int32 bot)
l_int32 fpixRasterop (FPIX *fpixd, l_int32 dx, l_int32 dy, l_int32 dw, l_int32 dh, FPIX *fpixs, l_int32 sx, l_int32 sy)
FPIXfpixScaleByInteger (FPIX *fpixs, l_int32 factor)
DPIXdpixScaleByInteger (DPIX *dpixs, l_int32 factor)
FPIXfpixLinearCombination (FPIX *fpixd, FPIX *fpixs1, FPIX *fpixs2, l_float32 a, l_float32 b)
l_int32 fpixAddMultConstant (FPIX *fpix, l_float32 addc, l_float32 multc)

Detailed Description

FPix operations: interconversion FPix <-> Pix; borders; rasterop; arithmetic.

  This file has these FPix utilities:
     - interconversion with pix
     - interconversion with dpix
     - min and max values
     - border functions
     - simple rasterop (source --> dest)
     - integer scaling
     - arithmetic operations

  Interconversions between Pix and FPix
        FPIX          *pixConvertToFPix()
        PIX           *fpixConvertToPix()
        PIX           *fpixDisplayMaxDynamicRange()  [useful for debugging]

  Interconversions between FPix and DPix
        DPIX          *fpixConvertToDPix()
        FPIX          *dpixConvertToFPix()

  FPix min/max value
        l_int32        fpixGetMin()
        l_int32        fpixGetMax()

  FPix border functions
        FPIX          *fpixAddBorder()
        FPIX          *fpixRemoveBorder()
        FPIX          *fpixAddMirroredBorder()

  FPix simple rasterop
        l_int32        fpixRasterop()

  Integer scaling
        FPIX          *fpixScaleByInteger()
        DPIX          *dpixScaleByInteger()

  FPix arithmetic operations
        FPIX          *fpixLinearCombination()
        l_int32        fpixAddMultConstant()

Definition in file fpix2.c.


Function Documentation

FPIX* pixConvertToFPix ( PIX pixs,
l_int32  ncomps 
)

pixConvertToFPix()

Input: pix (1, 2, 4, 8, 16 or 32 bpp) ncomps (number of components: 3 for RGB, 1 otherwise) Return: fpix, or null on error

Notes: (1) If colormapped, remove to grayscale. (2) If 32 bpp and == 3, this is RGB; convert to luminance. In all other cases the src image is treated as having a single component of pixel values.

Definition at line 77 of file fpix2.c.

References ERROR_PTR, fpixCreate(), fpixGetData(), fpixGetWpl(), GET_DATA_BIT, GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_FOUR_BYTES, GET_DATA_QBIT, GET_DATA_TWO_BYTES, NULL, pixClone(), pixConvertRGBToLuminance(), pixDestroy(), pixGetColormap(), pixGetData(), pixGetDepth(), pixGetDimensions(), pixGetWpl(), pixRemoveColormap(), PROCNAME, and REMOVE_CMAP_TO_GRAYSCALE.

Referenced by main().

PIX* fpixConvertToPix ( FPIX fpixs,
l_int32  outdepth,
l_int32  negvals,
l_int32  errorflag 
)

fpixConvertToPix()

Input: fpixs outdepth (0, 8, 16 or 32 bpp) negvals (L_CLIP_TO_ZERO, L_TAKE_ABSVAL) errorflag (1 to output error stats; 0 otherwise) Return: pixd, or null on error

Notes: (1) Use = 0 to programmatically determine the output depth. If no values are greater than 255, it will set outdepth = 8; otherwise to 16 or 32. (2) Because we are converting a float to an unsigned int with a specified dynamic range (8, 16 or 32 bits), errors can occur. If errorflag == TRUE, output the number of values out of range, both negative and positive. (3) If a pixel value is positive and out of range, clip to the maximum value represented at the outdepth of 8, 16 or 32 bits.

Definition at line 174 of file fpix2.c.

References ERROR_PTR, fpixGetData(), fpixGetDimensions(), fpixGetWpl(), L_CLIP_TO_ZERO, L_ERROR_INT, L_TAKE_ABSVAL, NULL, pixCreate(), L_Dewarp::pixd, pixGetData(), pixGetWpl(), PROCNAME, SET_DATA_BYTE, SET_DATA_FOUR_BYTES, and SET_DATA_TWO_BYTES.

Referenced by fpixaDisplayQuadtree(), and main().

PIX* fpixDisplayMaxDynamicRange ( FPIX fpixs)

fpixDisplayMaxDynamicRange()

Input: fpixs Return: pixd (8 bpp), or null on error

Definition at line 277 of file fpix2.c.

References ERROR_PTR, fpixGetData(), fpixGetDimensions(), fpixGetWpl(), NULL, pixCreate(), L_Dewarp::pixd, pixGetData(), pixGetWpl(), PROCNAME, and SET_DATA_BYTE.

Referenced by main().

DPIX* fpixConvertToDPix ( FPIX fpix)

fpixConvertToDPix()

Input: fpix Return: dpix, or null on error

Definition at line 337 of file fpix2.c.

References dpixCreate(), dpixGetData(), dpixGetWpl(), ERROR_PTR, fpixGetData(), fpixGetDimensions(), fpixGetWpl(), NULL, and PROCNAME.

Referenced by main().

FPIX* dpixConvertToFPix ( DPIX dpix)

dpixConvertToFPix()

Input: dpix Return: fpix, or null on error

Definition at line 378 of file fpix2.c.

References dpixGetData(), dpixGetDimensions(), dpixGetWpl(), ERROR_PTR, fpixCreate(), fpixGetData(), fpixGetWpl(), NULL, and PROCNAME.

Referenced by main().

l_int32 fpixGetMin ( FPIX fpix,
l_float32 pminval,
l_int32 pxminloc,
l_int32 pyminloc 
)

fpixGetMin()

Input: fpix &minval (<optional return>=""> min value) &xminloc (<optional return>=""> x location of min) &yminloc (<optional return>=""> y location of min) Return: 0 if OK; 1 on error

Definition at line 426 of file fpix2.c.

References ERROR_INT, fpixGetData(), fpixGetDimensions(), fpixGetWpl(), and PROCNAME.

l_int32 fpixGetMax ( FPIX fpix,
l_float32 pmaxval,
l_int32 pxmaxloc,
l_int32 pymaxloc 
)

fpixGetMax()

Input: fpix &maxval (<optional return>=""> max value) &xmaxloc (<optional return>=""> x location of max) &ymaxloc (<optional return>=""> y location of max) Return: 0 if OK; 1 on error

Definition at line 479 of file fpix2.c.

References ERROR_INT, fpixGetData(), fpixGetDimensions(), fpixGetWpl(), and PROCNAME.

FPIX* fpixAddBorder ( FPIX fpixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

fpixAddBorder()

Input: fpixs left, right, top, bot (pixels on each side to be added) Return: fpixd, or null on error

Notes: (1) Adds border of '0' 32-bit pixels

Definition at line 536 of file fpix2.c.

References ERROR_PTR, fpixCopy(), fpixCopyResolution(), fpixCreate(), fpixGetDimensions(), fpixRasterop(), NULL, and PROCNAME.

Referenced by fpixAddMirroredBorder().

FPIX* fpixRemoveBorder ( FPIX fpixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

fpixRemoveBorder()

Input: fpixs left, right, top, bot (pixels on each side to be removed) Return: fpixd, or null on error

Definition at line 572 of file fpix2.c.

References ERROR_PTR, fpixCopy(), fpixCopyResolution(), fpixCreate(), fpixGetDimensions(), fpixRasterop(), NULL, and PROCNAME.

FPIX* fpixAddMirroredBorder ( FPIX fpixs,
l_int32  left,
l_int32  right,
l_int32  top,
l_int32  bot 
)

fpixAddMirroredBorder()

Input: fpixs left, right, top, bot (pixels on each side to be added) Return: fpixd, or null on error

Notes: (1) See pixAddMirroredBorder() for situations of usage.

Definition at line 614 of file fpix2.c.

References ERROR_PTR, fpixAddBorder(), fpixGetDimensions(), fpixRasterop(), NULL, and PROCNAME.

Referenced by fpixConvolve().

l_int32 fpixRasterop ( FPIX fpixd,
l_int32  dx,
l_int32  dy,
l_int32  dw,
l_int32  dh,
FPIX fpixs,
l_int32  sx,
l_int32  sy 
)

fpixRasterop()

Input: fpixd (dest fpix) dx (x val of UL corner of dest rectangle) dy (y val of UL corner of dest rectangle) dw (width of dest rectangle) dh (height of dest rectangle) fpixs (src fpix) sx (x val of UL corner of src rectangle) sy (y val of UL corner of src rectangle) Return: 0 if OK; 1 on error.

Notes: (1) This is similiar in structure to pixRasterop(), except it only allows copying from the source into the destination. For that reason, no op code is necessary. Additionally, all pixels are 32 bit words (float values), which makes the copy very simple. (2) Clipping of both src and dest fpix are done automatically. (3) This allows in-place copying, without checking to see if the result is valid: use for in-place with caution!

Definition at line 674 of file fpix2.c.

References ERROR_INT, fpixGetData(), fpixGetDimensions(), fpixGetWpl(), and PROCNAME.

Referenced by fpixAddBorder(), fpixAddMirroredBorder(), fpixRemoveBorder(), and main().

FPIX* fpixScaleByInteger ( FPIX fpixs,
l_int32  factor 
)

fpixScaleByInteger()

Input: fpixs (low resolution, subsampled) factor (scaling factor) Return: fpixd (interpolated result), or null on error

Notes: (1) The width wd of fpixd is related to ws of fpixs by: wd = factor * (ws - 1) + 1 (and ditto for the height) We avoid special-casing boundary pixels in the interpolation by constructing fpixd by inserting (factor - 1) interpolated pixels between each pixel in fpixs. Then wd = ws + (ws - 1) * (factor - 1) (same as above) This also has the advantage that if we subsample by , throwing out all the interpolated pixels, we regain the original low resolution fpix.

Definition at line 785 of file fpix2.c.

References CALLOC, ERROR_PTR, fpixCreate(), fpixGetData(), fpixGetDimensions(), fpixGetWpl(), FREE, NULL, and PROCNAME.

Referenced by dewarpBuildModel(), dewarpPopulateFullRes(), and main().

DPIX* dpixScaleByInteger ( DPIX dpixs,
l_int32  factor 
)

dpixScaleByInteger()

Input: dpixs (low resolution, subsampled) factor (scaling factor) Return: dpixd (interpolated result), or null on error

Notes: (1) The width wd of dpixd is related to ws of dpixs by: wd = factor * (ws - 1) + 1 (and ditto for the height) We avoid special-casing boundary pixels in the interpolation by constructing fpixd by inserting (factor - 1) interpolated pixels between each pixel in fpixs. Then wd = ws + (ws - 1) * (factor - 1) (same as above) This also has the advantage that if we subsample by , throwing out all the interpolated pixels, we regain the original low resolution dpix.

Definition at line 875 of file fpix2.c.

References CALLOC, dpixCreate(), dpixGetData(), dpixGetDimensions(), dpixGetWpl(), ERROR_PTR, FREE, NULL, and PROCNAME.

Referenced by main().

FPIX* fpixLinearCombination ( FPIX fpixd,
FPIX fpixs1,
FPIX fpixs2,
l_float32  a,
l_float32  b 
)

fpixLinearCombo()

Input: fpixd (<optional>; this can be null, equal to fpixs1, or different from fpixs1) fpixs1 (can be == to fpixd) fpixs2 Return: pixd always

Notes: (1) Computes pixelwise linear combination: a * src1 + b * src2 (2) Alignment is to UL corner. (3) There are 3 cases. The result can go to a new dest, in-place to fpixs1, or to an existing input dest: * fpixd == null: (src1 + src2) --> new fpixd * fpixd == fpixs1: (src1 + src2) --> src1 (in-place) * fpixd != fpixs1: (src1 + src2) --> input fpixd (4) fpixs2 must be different from both fpixd and fpixs1.

Definition at line 969 of file fpix2.c.

References ERROR_PTR, fpixCopy(), fpixGetData(), fpixGetDimensions(), fpixGetWpl(), L_MIN, and PROCNAME.

Referenced by main().

l_int32 fpixAddMultConstant ( FPIX fpix,
l_float32  addc,
l_float32  multc 
)

fpixAddMultConstant()

Input: fpix addc (use 0.0 to skip the operation) multc (use 1.0 to skip the operation) Return: 0 if OK, 1 on error

Notes: (1) This is an in-place operation. (2) It can be used to multiply each pixel by a constant, and also to add a constant to each pixel. Multiplication is done first.

Definition at line 1049 of file fpix2.c.

References ERROR_INT, fpixGetData(), fpixGetDimensions(), fpixGetWpl(), and PROCNAME.

Referenced by main().

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines