Leptonica  1.82.0
Image processing and image analysis suite
quadtree.c File Reference
#include <math.h>
#include "allheaders.h"

Go to the source code of this file.

Macros

#define DEBUG_BOXES   0
 

Functions

l_ok pixQuadtreeMean (PIX *pixs, l_int32 nlevels, PIX *pix_ma, FPIXA **pfpixa)
 
l_ok pixQuadtreeVariance (PIX *pixs, l_int32 nlevels, PIX *pix_ma, DPIX *dpix_msa, FPIXA **pfpixa_v, FPIXA **pfpixa_rv)
 
l_ok pixMeanInRectangle (PIX *pixs, BOX *box, PIX *pixma, l_float32 *pval)
 
l_ok pixVarianceInRectangle (PIX *pixs, BOX *box, PIX *pix_ma, DPIX *dpix_msa, l_float32 *pvar, l_float32 *prvar)
 
BOXAAboxaaQuadtreeRegions (l_int32 w, l_int32 h, l_int32 nlevels)
 
l_ok quadtreeGetParent (FPIXA *fpixa, l_int32 level, l_int32 x, l_int32 y, l_float32 *pval)
 
l_ok quadtreeGetChildren (FPIXA *fpixa, l_int32 level, l_int32 x, l_int32 y, l_float32 *pval00, l_float32 *pval10, l_float32 *pval01, l_float32 *pval11)
 
l_int32 quadtreeMaxLevels (l_int32 w, l_int32 h)
 
PIXfpixaDisplayQuadtree (FPIXA *fpixa, l_int32 factor, l_int32 fontsize)
 

Detailed Description

     Top level quadtree linear statistics
         l_int32   pixQuadtreeMean()
         l_int32   pixQuadtreeVariance()
     Statistics in an arbitrary rectangle
         l_int32   pixMeanInRectangle()
         l_int32   pixVarianceInRectangle()
     Quadtree regions
         BOXAA    *boxaaQuadtreeRegions()
     Quadtree access
         l_int32   quadtreeGetParent()
         l_int32   quadtreeGetChildren()
         l_int32   quadtreeMaxLevels()
     Display quadtree
         PIX      *fpixaDisplayQuadtree()
 There are many other statistical quantities that can be computed
 in a quadtree, such as rank values, and these can be added as
 the need arises.
 Similar results that can approximate a single level of the quadtree
 can be generated by pixGetAverageTiled().  There we specify the
 tile size over which the mean, mean square, and root variance
 are generated; the results are saved in a (reduced size) pix.
 Because the tile dimensions are integers, it is usually not possible
 to obtain tilings that are a power of 2, as required for quadtrees.

Definition in file quadtree.c.

Function Documentation

◆ boxaaQuadtreeRegions()

BOXAA* boxaaQuadtreeRegions ( l_int32  w,
l_int32  h,
l_int32  nlevels 
)

boxaaQuadtreeRegions()

Parameters
[in]w,hsize of pix that is being quadtree-ized
[in]nlevelsnumber of levels in quadtree
Returns
baa for quadtree regions at each level, or NULL on error
Notes:
     (1) The returned boxaa has nlevels of boxa, each containing
         the set of rectangles at that level.  The rectangle at
         level 0 is the entire region; at level 1 the region is
         divided into 4 rectangles, and at level n there are n^4
         rectangles.
     (2) At each level, the rectangles in the boxa are in "raster"
         order, with LR (fast scan) and TB (slow scan).

Definition at line 453 of file quadtree.c.

References boxaaAddBoxa(), boxaaCreate(), boxaAddBox(), boxaCreate(), boxCreate(), L_INSERT, and lept_stderr().

◆ fpixaDisplayQuadtree()

PIX* fpixaDisplayQuadtree ( FPIXA fpixa,
l_int32  factor,
l_int32  fontsize 
)

fpixaDisplayQuadtree()

Parameters
[in]fpixamean, variance or root variance
[in]factorreplication factor at lowest level
[in]fontsize4, ... 20
Returns
pixd 8 bpp, mosaic of quadtree images, or NULL on error
Notes:
     (1) The mean and root variance fall naturally in the 8 bpp range,
         but the variance is typically outside the range.  This
         function displays 8 bpp pix clipped to 255, so the image
         pixels will mostly be 255 (white).

Definition at line 658 of file quadtree.c.

References bmfCreate(), fpixaGetCount(), fpixaGetFPix(), fpixConvertToPix(), fpixDestroy(), L_ADD_BELOW, L_CLIP_TO_ZERO, L_CLONE, L_INSERT, pixaAddPix(), pixaCreate(), pixAddSingleTextblock(), pixConvertTo32(), pixDestroy(), and pixExpandReplicate().

◆ pixMeanInRectangle()

l_ok pixMeanInRectangle ( PIX pixs,
BOX box,
PIX pixma,
l_float32 *  pval 
)

pixMeanInRectangle()

Parameters
[in]pixs8 bpp
[in]boxregion to compute mean value
[in]pixmamean accumulator
[out]pvalmean value
Returns
0 if OK, 1 on error
Notes:
     (1) This function is intended to be used for many rectangles
         on the same image.  It can find the mean within a
         rectangle in O(1), independent of the size of the rectangle.

Definition at line 269 of file quadtree.c.

◆ pixQuadtreeMean()

l_ok pixQuadtreeMean ( PIX pixs,
l_int32  nlevels,
PIX pix_ma,
FPIXA **  pfpixa 
)

pixQuadtreeMean()

Parameters
[in]pixs8 bpp, no colormap
[in]nlevelsin quadtree; max allowed depends on image size
[in]pix_mainput mean accumulator; can be null
[out]pfpixamean values in quadtree
Returns
0 if OK, 1 on error
Notes:
     (1) The returned fpixa has nlevels of fpix, each containing
         the mean values at its level.  Level 0 has a
         single value; level 1 has 4 values; level 2 has 16; etc.

Definition at line 96 of file quadtree.c.

◆ pixQuadtreeVariance()

l_ok pixQuadtreeVariance ( PIX pixs,
l_int32  nlevels,
PIX pix_ma,
DPIX dpix_msa,
FPIXA **  pfpixa_v,
FPIXA **  pfpixa_rv 
)

pixQuadtreeVariance()

Parameters
[in]pixs8 bpp, no colormap
[in]nlevelsin quadtree
[in]pix_mainput mean accumulator; can be null
[in]dpix_msainput mean square accumulator; can be null
[out]pfpixa_v[optional] variance values in quadtree
[out]pfpixa_rv[optional] root variance values in quadtree
Returns
0 if OK, 1 on error
Notes:
     (1) The returned fpixav and fpixarv have nlevels of fpix,
         each containing at the respective levels the variance
         and root variance values.

Definition at line 173 of file quadtree.c.

◆ pixVarianceInRectangle()

l_ok pixVarianceInRectangle ( PIX pixs,
BOX box,
PIX pix_ma,
DPIX dpix_msa,
l_float32 *  pvar,
l_float32 *  prvar 
)

pixVarianceInRectangle()

Parameters
[in]pixs8 bpp
[in]boxregion to compute variance and/or root variance
[in]pix_mamean accumulator
[in]dpix_msamean square accumulator
[out]pvar[optional] variance
[out]prvar[optional] root variance
Returns
0 if OK, 1 on error
Notes:
     (1) This function is intended to be used for many rectangles
         on the same image.  It can find the variance and/or the
         square root of the variance within a rectangle in O(1),
         independent of the size of the rectangle.

Definition at line 345 of file quadtree.c.

◆ quadtreeGetChildren()

l_ok quadtreeGetChildren ( FPIXA fpixa,
l_int32  level,
l_int32  x,
l_int32  y,
l_float32 *  pval00,
l_float32 *  pval10,
l_float32 *  pval01,
l_float32 *  pval11 
)

quadtreeGetChildren()

Parameters
[in]fpixamean, variance or root variance
[in]level,x,yof current pixel
[out]pval00,pval01,pval10,pval11four child pixel values
Returns
0 if OK, 1 on error
Notes:
     (1) Check return value for error.  On error, all return vals are 0.0.
     (2) The returned child pixels are located at:
            level + 1
            (2x, 2y), (2x+1, 2y), (2x, 2y+1), (2x+1, 2y+1)

Definition at line 577 of file quadtree.c.

References fpixaGetCount(), and fpixaGetPixel().

◆ quadtreeGetParent()

l_ok quadtreeGetParent ( FPIXA fpixa,
l_int32  level,
l_int32  x,
l_int32  y,
l_float32 *  pval 
)

quadtreeGetParent()

Parameters
[in]fpixamean, variance or root variance
[in]level,x,yof current pixel
[out]pvalparent pixel value, or 0.0 on error
Returns
0 if OK, 1 on error
Notes:
     (1) Check return value for error.  On error, val is returned as 0.0.
     (2) The parent is located at:
            level - 1
            (x/2, y/2)

Definition at line 534 of file quadtree.c.

References fpixaGetCount(), and fpixaGetPixel().

◆ quadtreeMaxLevels()

l_int32 quadtreeMaxLevels ( l_int32  w,
l_int32  h 
)

quadtreeMaxLevels()

Parameters
[in]w,hdimensions of image
Returns
maxlevels maximum number of levels allowed, or -1 on error
Notes:
     (1) The criterion for maxlevels is that the subdivision not
         go down below the single pixel level.  The 1.5 factor
         is intended to keep any rectangle from accidentally
         having zero dimension due to integer truncation.

Definition at line 623 of file quadtree.c.