![]() |
Leptonica 1.85.0
Image processing and image analysis suite
|
#include <string.h>#include "allheaders.h"Go to the source code of this file.
Macros | |
| #define | DEBUG_OVERFLOW 0 |
| #define | DEBUG_UNROLLING 0 |
Functions | |
| static void | scaleColorLILow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
| static void | scaleGrayLILow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
| static void | scaleColor2xLILow (l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
| static void | scaleColor2xLILineLow (l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag) |
| static void | scaleGray2xLILow (l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
| static void | scaleGray2xLILineLow (l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag) |
| static void | scaleGray4xLILow (l_uint32 *datad, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
| static void | scaleGray4xLILineLow (l_uint32 *lined, l_int32 wpld, l_uint32 *lines, l_int32 ws, l_int32 wpls, l_int32 lastlineflag) |
| static l_int32 | scaleBySamplingLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 d, l_int32 wpls, l_float32 shiftx, l_float32 shifty) |
| static l_int32 | scaleSmoothLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 d, l_int32 wpls, l_int32 size) |
| static void | scaleRGBToGray2Low (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 wpls, l_float32 rwt, l_float32 gwt, l_float32 bwt) |
| static void | scaleColorAreaMapLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
| static void | scaleGrayAreaMapLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls) |
| static void | scaleAreaMapLow2 (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 d, l_int32 wpls) |
| static l_int32 | scaleBinaryLow (l_uint32 *datad, l_int32 wd, l_int32 hd, l_int32 wpld, l_uint32 *datas, l_int32 ws, l_int32 hs, l_int32 wpls, l_float32 shiftx, l_float32 shifty) |
| PIX * | pixScale (PIX *pixs, l_float32 scalex, l_float32 scaley) |
| PIX * | pixScaleToSizeRel (PIX *pixs, l_int32 delw, l_int32 delh) |
| PIX * | pixScaleToSize (PIX *pixs, l_int32 wd, l_int32 hd) |
| PIX * | pixScaleToResolution (PIX *pixs, l_float32 target, l_float32 assumed, l_float32 *pscalefact) |
| PIX * | pixScaleGeneral (PIX *pixs, l_float32 scalex, l_float32 scaley, l_float32 sharpfract, l_int32 sharpwidth) |
| PIX * | pixScaleLI (PIX *pixs, l_float32 scalex, l_float32 scaley) |
| PIX * | pixScaleColorLI (PIX *pixs, l_float32 scalex, l_float32 scaley) |
| PIX * | pixScaleColor2xLI (PIX *pixs) |
| PIX * | pixScaleColor4xLI (PIX *pixs) |
| PIX * | pixScaleGrayLI (PIX *pixs, l_float32 scalex, l_float32 scaley) |
| PIX * | pixScaleGray2xLI (PIX *pixs) |
| PIX * | pixScaleGray4xLI (PIX *pixs) |
| PIX * | pixScaleGray2xLIThresh (PIX *pixs, l_int32 thresh) |
| PIX * | pixScaleGray2xLIDither (PIX *pixs) |
| PIX * | pixScaleGray4xLIThresh (PIX *pixs, l_int32 thresh) |
| PIX * | pixScaleGray4xLIDither (PIX *pixs) |
| PIX * | pixScaleBySampling (PIX *pixs, l_float32 scalex, l_float32 scaley) |
| PIX * | pixScaleBySamplingWithShift (PIX *pixs, l_float32 scalex, l_float32 scaley, l_float32 shiftx, l_float32 shifty) |
| PIX * | pixScaleBySamplingToSize (PIX *pixs, l_int32 wd, l_int32 hd) |
| PIX * | pixScaleByIntSampling (PIX *pixs, l_int32 factor) |
| PIX * | pixScaleRGBToGrayFast (PIX *pixs, l_int32 factor, l_int32 color) |
| PIX * | pixScaleRGBToBinaryFast (PIX *pixs, l_int32 factor, l_int32 thresh) |
| PIX * | pixScaleGrayToBinaryFast (PIX *pixs, l_int32 factor, l_int32 thresh) |
| PIX * | pixScaleSmooth (PIX *pix, l_float32 scalex, l_float32 scaley) |
| PIX * | pixScaleSmoothToSize (PIX *pixs, l_int32 wd, l_int32 hd) |
| PIX * | pixScaleRGBToGray2 (PIX *pixs, l_float32 rwt, l_float32 gwt, l_float32 bwt) |
| PIX * | pixScaleAreaMap (PIX *pix, l_float32 scalex, l_float32 scaley) |
| PIX * | pixScaleAreaMap2 (PIX *pix) |
| PIX * | pixScaleAreaMapToSize (PIX *pixs, l_int32 wd, l_int32 hd) |
| PIX * | pixScaleBinary (PIX *pixs, l_float32 scalex, l_float32 scaley) |
| PIX * | pixScaleBinaryWithShift (PIX *pixs, l_float32 scalex, l_float32 scaley, l_float32 shiftx, l_float32 shifty) |
Top-level scaling
PIX *pixScale()
PIX *pixScaleToSizeRel()
PIX *pixScaleToSize()
PIX *pixScaleToResolution()
PIX *pixScaleGeneral()
Linearly interpreted (usually up-) scaling
PIX *pixScaleLI()
PIX *pixScaleColorLI()
PIX *pixScaleColor2xLI()
PIX *pixScaleColor4xLI()
PIX *pixScaleGrayLI()
PIX *pixScaleGray2xLI()
PIX *pixScaleGray4xLI()
Upscale 2x followed by binarization
PIX *pixScaleGray2xLIThresh()
PIX *pixScaleGray2xLIDither()
Upscale 4x followed by binarization
PIX *pixScaleGray4xLIThresh()
PIX *pixScaleGray4xLIDither()
Scaling by closest pixel sampling
PIX *pixScaleBySampling()
PIX *pixScaleBySamplingWithShift()
PIX *pixScaleBySamplingToSize()
PIX *pixScaleByIntSampling()
Fast integer factor subsampling RGB to gray and to binary
PIX *pixScaleRGBToGrayFast()
PIX *pixScaleRGBToBinaryFast()
PIX *pixScaleGrayToBinaryFast()
Downscaling with (antialias) smoothing
PIX *pixScaleSmooth()
PIX *pixScaleSmoothToSize()
PIX *pixScaleRGBToGray2() [special 2x reduction to gray]
Downscaling with (antialias) area mapping
PIX *pixScaleAreaMap()
PIX *pixScaleAreaMap2()
PIX *pixScaleAreaMapToSize()
Binary scaling by closest pixel sampling
PIX *pixScaleBinary()
PIX *pixScaleBinaryWithShift()
Low-level static functions:
Color (interpolated) scaling: general case
static void scaleColorLILow()
Grayscale (interpolated) scaling: general case
static void scaleGrayLILow()
Color (interpolated) scaling: 2x upscaling
static void scaleColor2xLILow()
static void scaleColor2xLILineLow()
Grayscale (interpolated) scaling: 2x upscaling
static void scaleGray2xLILow()
static void scaleGray2xLILineLow()
Grayscale (interpolated) scaling: 4x upscaling
static void scaleGray4xLILow()
static void scaleGray4xLILineLow()
Grayscale and color scaling by closest pixel sampling
static l_int32 scaleBySamplingLow()
Color and grayscale downsampling with (antialias) lowpass filter
static l_int32 scaleSmoothLow()
static void scaleRGBToGray2Low()
Color and grayscale downsampling with (antialias) area mapping
static l_int32 scaleColorAreaMapLow()
static l_int32 scaleGrayAreaMapLow()
static l_int32 scaleAreaMapLow2()
Binary scaling by closest pixel sampling
static l_int32 scaleBinaryLow()
Definition in file scale1.c.
| [in] | pixs | 1, 2, 4, 8, 16 and 32 bpp |
| [in] | scalex,scaley |
This function scales 32 bpp RGB; 2, 4 or 8 bpp palette color; 2, 4, 8 or 16 bpp gray; and binary images.
When the input has palette color, the colormap is removed and the result is either 8 bpp gray or 32 bpp RGB, depending on whether the colormap has color entries. Images with 2, 4 or 16 bpp are converted to 8 bpp.
Because pixScale is meant to be a very simple interface to a number of scaling functions, including the use of unsharp masking, the type of scaling and the sharpening parameters are chosen by default. Grayscale and color images are scaled using one of five methods, depending on the scale factors:
One could use subsampling for scale factors very close to 1.0, because it preserves sharp edges. Linear interpolation blurs edges because the dest pixels will typically straddle two src edge pixels. Subsmpling removes entire columns and rows, so the edge is not blurred. However, there are two reasons for not doing this. First, it moves edges, so that a straight line at a large angle to both horizontal and vertical will have noticeable kinks where horizontal and vertical rasters are removed. Second, although it is very fast, you get good results on sharp edges by applying a sharpening filter.
For images with sharp edges, sharpening substantially improves the image quality for scale factors between about 0.2 and about 2.0. pixScale uses a small amount of sharpening by default because it strengthens edge pixels that are weak due to anti-aliasing. The default sharpening factors are:
However, sharpening is computationally expensive, and one needs to consider the speed-quality tradeoff:
In many situations you will get a satisfactory result by scaling without sharpening: call pixScaleGeneral with sharpfract = 0.0. Alternatively, if you wish to sharpen but not use the default value, first call pixScaleGeneral with sharpfract = 0.0, and then sharpen explicitly using pixUnsharpMasking.
Binary images are scaled to binary by sampling the closest pixel, without any low-pass filtering averaging of neighboring pixels. This will introduce aliasing for reductions. Aliasing can be prevented by using pixScaleToGray instead.
Definition at line 254 of file scale1.c.
References pixScaleGeneral().
Referenced by pixScaleToResolution(), and pixScaleToSize().
| [in] | pix | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
| [in] | scalex | must be < 0.7; minimum is 0.02 |
| [in] | scaley | must be < 0.7; minimum is 0.02 |
Notes:
(1) This is a low-pass filter that averages over fractional pixels.
It should only be used when the scale factors are less than 0.7.
If either scale factor is greater than or equal to 0.7, we
issue a warning and call pixScaleGeneral(), which will invoke
linear interpolation without sharpening.
(2) The minimum scale factor allowed for area mapping reduction
is 0.02. Various overflows will occur when scale factors are
less than about 1/256. If a scale factor smaller than 0.02
is given, we use pixScaleSmooth(), which is a low-pass filter
that averages over entire pixels.
(3) This works only on 2, 4, 8 and 32 bpp images. If there is
a colormap, it is removed by converting to RGB. In other
cases, we issue a warning and call pixScaleGeneral().
(4) This is faster than pixScale() because it does not do sharpening.
(5) It does a relatively expensive area mapping computation, to
avoid antialiasing. It is about 2x slower than pixScaleSmooth(),
but the results are much better on fine text.
(6) pixScaleAreaMap2() is typically about 7x faster for the special
case of 2x reduction for color images, and about 9x faster
for grayscale images. Surprisingly, the improvement in speed
when using a cascade of 2x reductions for small scale factors is
less than one might expect, and in most situations gives
poorer image quality. But see (6).
(7) For reductions between 0.35 and 0.5, a 2x area map reduction
followed by using pixScaleGeneral() on a 2x larger scalefactor
(which further reduces the image size using bilinear interpolation)
would give a significant speed increase, with little loss of
quality, but this is not enabled as it would break too many tests.
For scaling factors below 0.35, scaling atomically is nearly
as fast as using a cascade of 2x scalings, and gives
better results.
Definition at line 1910 of file scale1.c.
References pixScaleAreaMap(), pixScaleAreaMap2(), pixScaleGeneral(), pixScaleSmooth(), REMOVE_CMAP_BASED_ON_SRC, scaleColorAreaMapLow(), and scaleGrayAreaMapLow().
Referenced by pixScaleAreaMap(), pixScaleAreaMapToSize(), and pixScaleGeneral().
| [in] | pix | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
Notes:
(1) This function does an area mapping (average) for 2x
reduction.
(2) This works only on 2, 4, 8 and 32 bpp images. If there is
a colormap, it is removed by converting to RGB.
(3) Compared to the general pixScaleAreaMap(), for this function
gray processing is about 14x faster and color processing
is about 4x faster. Consequently, pixScaleAreaMap2() is
incorporated into the general area map scaling function,
for the special cases of 2x, 4x, 8x and 16x reduction.
Definition at line 2041 of file scale1.c.
References REMOVE_CMAP_BASED_ON_SRC, and scaleAreaMapLow2().
Referenced by pixScaleAreaMap().
| [in] | pixs | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
| [in] | wd | target width; use 0 if using height as target |
| [in] | hd | target height; use 0 if using width as target |
Notes:
(1) See notes in pixScaleAreaMap().
(2) The output scaled image has the dimension(s) you specify:
- To specify the width with isotropic scaling, set hd = 0.
- To specify the height with isotropic scaling, set wd = 0.
- If both wd and hd are specified, the image is scaled
(in general, anisotropically) to that size.
- It is an error to set both wd and hd to 0.
Definition at line 2104 of file scale1.c.
References pixScaleAreaMap().
| [in] | pixs | 1 bpp |
| [in] | scalex | must be > 0.0 |
| [in] | scaley | must be > 0.0 |
Notes:
(1) This function samples from the source without
filtering. As a result, aliasing will occur for
subsampling (scalex and scaley < 1.0).
(2) By default, indexing for the sampled source pixel is done
by rounding. This shifts the source pixel sampling down
and to the right by half a pixel, which has the effect of
shifting the destination image up and to the left by a
number of pixels approximately equal to half the scaling
factor. To avoid this shift in the destination image,
call pixScalebySamplingWithShift() using 0 for both shifts.
Definition at line 2158 of file scale1.c.
References pixScaleBinaryWithShift().
Referenced by pixScaleGeneral().
| PIX * pixScaleBinaryWithShift | ( | PIX * | pixs, |
| l_float32 | scalex, | ||
| l_float32 | scaley, | ||
| l_float32 | shiftx, | ||
| l_float32 | shifty ) |
| [in] | pixs | 1 bpp |
| [in] | scalex | must be > 0.0 |
| [in] | scaley | must be > 0.0 |
| [in] | shiftx | 0.5 for default; 0.0 to mihimize edge effects |
| [in] | shifty | 0.5 for default; 0.0 to mihimize edge effects |
Notes:
(1) The @shiftx and @shifty parameters are usually unimportant.
Visible artifacts are minimized by using 0.0.
Allowed values are 0.0 and 0.5.
Definition at line 2188 of file scale1.c.
Referenced by pixScaleBinary(), and pixScaleBySamplingWithShift().
| [in] | pixs | 1, 2, 4, 8, 16, 32 bpp (all depths) |
| [in] | factor | integer subsampling; >= 1 |
Notes:
(1) Simple interface to pixScaleBySampling(), for isotropic
integer reduction. If factor == 1, returns a copy.
Definition at line 1454 of file scale1.c.
References pixScaleBySampling().
| [in] | pixs | 1, 2, 4, 8, 16, 32 bpp |
| [in] | scalex | must be > 0.0 |
| [in] | scaley | must be > 0.0 |
Notes:
(1) This function samples from the source without
filtering. As a result, aliasing will occur for
subsampling (scalex and/or scaley < 1.0).
(2) If scalex == 1.0 and scaley == 1.0, returns a copy.
(3) For upscaling by an integer, use pixExpandReplicate().
(4) By default, indexing for the sampled source pixel is done
by rounding. This shifts the source pixel sampling down
and to the right by half a pixel, which has the effect of
shifting the destination image up and to the left by a
number of pixels approximately equal to half the scaling
factor. To avoid this shift in the destination image,
call pixScalebySamplingWithShift() using 0 for both shifts.
Definition at line 1317 of file scale1.c.
References pixScaleBySamplingWithShift().
Referenced by pixScaleByIntSampling(), and pixScaleBySamplingToSize().
| [in] | pixs | 1, 2, 4, 8, 16 and 32 bpp |
| [in] | wd | target width; use 0 if using height as target |
| [in] | hd | target height; use 0 if using width as target |
Notes:
(1) This guarantees that the output scaled image has the
dimension(s) you specify.
~ To specify the width with isotropic scaling, set hd = 0.
~ To specify the height with isotropic scaling, set wd = 0.
~ If both wd and hd are specified, the image is scaled
(in general, anisotropically) to that size.
~ It is an error to set both wd and hd to 0.
Definition at line 1412 of file scale1.c.
References pixScaleBySampling().
| PIX * pixScaleBySamplingWithShift | ( | PIX * | pixs, |
| l_float32 | scalex, | ||
| l_float32 | scaley, | ||
| l_float32 | shiftx, | ||
| l_float32 | shifty ) |
| [in] | pixs | 1, 2, 4, 8, 16, 32 bpp |
| [in] | scalex | must be > 0.0 |
| [in] | scaley | must be > 0.0 |
| [in] | shiftx | 0.5 for default; 0.0 to mihimize edge effects |
| [in] | shifty | 0.5 for default; 0.0 to mihimize edge effects |
Notes:
(1) The @shiftx and @shifty parameters are usually unimportant.
Visible artifacts are minimized by using 0.0.
Allowed values are 0.0 and 0.5.
Definition at line 1345 of file scale1.c.
References pixScaleBinaryWithShift(), and scaleBySamplingLow().
Referenced by pixScaleBySampling().
| [in] | pixs | 32 bpp, representing rgb |
Notes:
(1) This is a special case of linear interpolated scaling,
for 2x upscaling. It is about 8x faster than using
the generic pixScaleColorLI(), and about 4x faster than
using the special 2x scale function pixScaleGray2xLI()
on each of the three components separately.
Definition at line 629 of file scale1.c.
References scaleColor2xLILow().
Referenced by pixScaleColorLI().
| [in] | pixs | 32 bpp, representing rgb |
Notes:
(1) This is a special case of color linear interpolated scaling,
for 4x upscaling. It is about 3x faster than using
the generic pixScaleColorLI().
(2) This scales each component separately, using pixScaleGray4xLI().
It would be about 4x faster to inline the color code properly,
in analogy to scaleColor4xLILow(), and I leave this as
an exercise for someone who really needs it.
Definition at line 674 of file scale1.c.
References COLOR_BLUE, COLOR_GREEN, COLOR_RED, and pixScaleGray4xLI().
Referenced by pixScaleColorLI().
| [in] | pixs | 32 bpp, representing rgb |
| [in] | scalex | must be >= 0.7 |
| [in] | scaley | must be >= 0.7 |
Notes:
(1) If both scale factors are smaller than 0.7, we issue a warning
and call pixScaleGeneral(), which will invoke area mapping
without sharpening. This is particularly important for
document images with sharp edges.
(2) For the general case, it's about 4x faster to manipulate
the color pixels directly, rather than to make images
out of each of the 3 components, scale each component
using the pixScaleGrayLI(), and combine the results back
into an rgb image.
Definition at line 567 of file scale1.c.
References pixScaleColor2xLI(), pixScaleColor4xLI(), pixScaleGeneral(), and scaleColorLILow().
Referenced by pixScaleGeneral(), and pixScaleLI().
| PIX * pixScaleGeneral | ( | PIX * | pixs, |
| l_float32 | scalex, | ||
| l_float32 | scaley, | ||
| l_float32 | sharpfract, | ||
| l_int32 | sharpwidth ) |
| [in] | pixs | 1, 2, 4, 8, 16 and 32 bpp |
| [in] | scalex | must be > 0.0 |
| [in] | scaley | must be > 0.0 |
| [in] | sharpfract | use 0.0 to skip sharpening |
| [in] | sharpwidth | halfwidth of low-pass filter; typ. 1 or 2 |
Notes:
(1) See pixScale() for usage.
(2) This interface may change in the future, as other special
cases are added.
(3) For tiny scaling factors
minscale < 0.02: use a simple lowpass filter
(4) The actual sharpening factors used depend on the maximum
of the two scale factors (maxscale):
maxscale <= 0.2: no sharpening
0.2 < maxscale < 1.4: uses the input parameters
maxscale >= 1.4: no sharpening
(5) To avoid sharpening for grayscale and color images with
scaling factors between 0.2 and 1.4, call this function
with sharpfract == 0.0.
(6) To use arbitrary sharpening in conjunction with scaling,
call this function with sharpfract = 0.0, and follow this
with a call to pixUnsharpMasking() with your chosen parameters.
Definition at line 419 of file scale1.c.
References L_CLONE, pixScaleAreaMap(), pixScaleBinary(), pixScaleColorLI(), pixScaleGrayLI(), and pixScaleSmooth().
Referenced by pixScale(), pixScaleAreaMap(), pixScaleColorLI(), pixScaleGrayLI(), pixScaleLI(), and pixScaleSmooth().
| [in] | pixs | 8 bpp grayscale, not cmapped |
Notes:
(1) This is a special case of gray linear interpolated scaling,
for 2x upscaling. It is about 6x faster than using
the generic pixScaleGrayLI().
Definition at line 825 of file scale1.c.
References scaleGray2xLILow().
Referenced by pixScaleGrayLI().
| [in] | pixs | 8 bpp, not cmapped |
Notes:
(1) This does 2x upscale on pixs, using linear interpolation,
followed by Floyd-Steinberg dithering to binary.
(2) Buffers are used to avoid making a large grayscale image.
~ Two line buffers are used for the src, required for the 2x
LI upscale.
~ Three line buffers are used for the intermediate image.
Two are filled with each 2xLI row operation; the third is
needed because the upscale and dithering ops are out of sync.
Definition at line 984 of file scale1.c.
References DEFAULT_CLIP_LOWER_1, DEFAULT_CLIP_UPPER_1, and scaleGray2xLILineLow().
| [in] | pixs | 8 bpp, not cmapped |
| [in] | thresh | between 0 and 256 |
Notes:
(1) This does 2x upscale on pixs, using linear interpolation,
followed by thresholding to binary.
(2) Buffers are used to avoid making a large grayscale image.
Definition at line 907 of file scale1.c.
References scaleGray2xLILineLow().
| [in] | pixs | 8 bpp grayscale, not cmapped |
Notes:
(1) This is a special case of gray linear interpolated scaling,
for 4x upscaling. It is about 12x faster than using
the generic pixScaleGrayLI().
Definition at line 864 of file scale1.c.
References scaleGray4xLILow().
Referenced by pixScaleColor4xLI(), and pixScaleGrayLI().
| [in] | pixs | 8 bpp, not cmapped |
Notes:
(1) This does 4x upscale on pixs, using linear interpolation,
followed by Floyd-Steinberg dithering to binary.
(2) Buffers are used to avoid making a large grayscale image.
~ Two line buffers are used for the src, required for the
4xLI upscale.
~ Five line buffers are used for the intermediate image.
Four are filled with each 4xLI row operation; the fifth
is needed because the upscale and dithering ops are
out of sync.
(3) If a full 4x expanded grayscale image can be kept in memory,
this function is only about 5% faster than separately doing
a linear interpolation to a large grayscale image, followed
by error-diffusion dithering to binary.
Definition at line 1187 of file scale1.c.
References DEFAULT_CLIP_LOWER_1, DEFAULT_CLIP_UPPER_1, and scaleGray4xLILineLow().
| [in] | pixs | 8 bpp |
| [in] | thresh | between 0 and 256 |
Notes:
(1) This does 4x upscale on pixs, using linear interpolation,
followed by thresholding to binary.
(2) Buffers are used to avoid making a large grayscale image.
(3) If a full 4x expanded grayscale image can be kept in memory,
this function is only about 10% faster than separately doing
a linear interpolation to a large grayscale image, followed
by thresholding to binary.
Definition at line 1101 of file scale1.c.
References scaleGray4xLILineLow().
| [in] | pixs | 8 bpp grayscale, no cmap |
| [in] | scalex | must be >= 0.7 |
| [in] | scaley | must be >= 0.7 |
Notes:
(1) This function is appropriate for upscaling magnification, where the
scale factor is > 1, as well as for a small amount of downscaling
reduction, with scale factor >= 0.7. If the scale factor is < 0.7,
the best result is obtained by area mapping.
(2) Here are some details:
- For each pixel in the dest, this does a linear
interpolation of 4 neighboring pixels in the src.
Specifically, consider the UL corner of src and
dest pixels. The UL corner of the dest falls within
a src pixel, whose four corners are the UL corners
of 4 adjacent src pixels. The value of the dest
is taken by linear interpolation using the values of
the four src pixels and the distance of the UL corner
of the dest from each corner.
- If the image is expanded so that the dest pixel is
smaller than the src pixel, such interpolation
is a reasonable approach. This interpolation is
also good for a small image reduction factor that
is not more than a 2x reduction.
- The linear interpolation algorithm for scaling is
identical in form to the area-mapping algorithm
for grayscale rotation. The latter corresponds to a
translation of each pixel without scaling.
- This function is NOT optimal if the scaling involves
a large reduction. If the image is significantly
reduced, so that the dest pixel is much larger than
the src pixels, this interpolation, which is over src
pixels only near the UL corner of the dest pixel,
is not going to give a good area-mapping average.
Because area mapping for image scaling is considerably
more computationally intensive than linear interpolation,
we choose not to use it. For large image reduction,
linear interpolation over adjacent src pixels
degenerates asymptotically to subsampling. But
subsampling without a low-pass pre-filter causes
aliasing by the nyquist theorem. To avoid aliasing,
a low-pass filter e.g., an averaging filter of
size roughly equal to the dest pixel i.e., the reduction
factor should be applied to the src before subsampling.
- As an alternative to low-pass filtering and subsampling
for large reduction factors, linear interpolation can
also be done between the widely separated src pixels in
which the corners of the dest pixel lie. This also is
not optimal, as it samples src pixels only near the
corners of the dest pixel, and it is not implemented.
Definition at line 766 of file scale1.c.
References pixScaleGeneral(), pixScaleGray2xLI(), pixScaleGray4xLI(), and scaleGrayLILow().
Referenced by pixScaleGeneral(), and pixScaleLI().
| [in] | pixs | 8 bpp grayscale |
| [in] | factor | integer reduction factor >= 1 |
| [in] | thresh | binarization threshold |
Notes:
(1) This does simultaneous subsampling by an integer factor and
thresholding from gray to binary.
(2) It is designed for maximum speed, and is used for quickly
generating a downsized binary image from a higher resolution
gray image. This would typically be used for image analysis.
Definition at line 1631 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BIT.
| [in] | pixs | 2, 4, 8 or 32 bpp; with or without colormap |
| [in] | scalex | must be >= 0.7 |
| [in] | scaley | must be >= 0.7 |
Notes:
(1) This function should only be used when the scale factors are
greater than or equal to 0.7, and typically greater than 1.
If both scale factors are smaller than 0.7, we issue a warning
and call pixScaleGeneral(), which will invoke area mapping
without sharpening.
(2) This works on 2, 4, 8, 16 and 32 bpp images, as well as on
2, 4 and 8 bpp images that have a colormap. If there is a
colormap, it is removed to either gray or RGB, depending
on the colormap.
(3) This does a linear interpolation on the src image.
(4) It dispatches to much faster implementations for
the special cases of 2x and 4x expansion.
Definition at line 510 of file scale1.c.
References L_CLONE, pixScaleColorLI(), pixScaleGeneral(), and pixScaleGrayLI().
| [in] | pixs | 32 bpp RGB |
| [in] | factor | integer reduction factor >= 1 |
| [in] | thresh | binarization threshold |
Notes:
(1) This does simultaneous subsampling by an integer factor and
conversion from RGB to gray to binary.
(2) It is designed for maximum speed, and is used for quickly
generating a downsized binary image from a higher resolution
RGB image. This would typically be used for image analysis.
(3) It uses the green channel to represent the RGB pixel intensity.
Definition at line 1567 of file scale1.c.
References SET_DATA_BIT.
| [in] | pixs | 32 bpp rgb |
| [in] | rwt,gwt,bwt | must sum to 1.0 |
Definition at line 1831 of file scale1.c.
References scaleRGBToGray2Low().
| [in] | pixs | 32 bpp rgb |
| [in] | factor | integer reduction factor >= 1 |
| [in] | color | one of COLOR_RED, COLOR_GREEN, COLOR_BLUE |
Notes:
(1) This does simultaneous subsampling by an integer factor and
extraction of the color from the RGB pix.
(2) It is designed for maximum speed, and is used for quickly
generating a downsized grayscale image from a higher resolution
RGB image. This would typically be used for image analysis.
(3) The standard color byte order (RGBA) is assumed.
Definition at line 1494 of file scale1.c.
References COLOR_BLUE, COLOR_GREEN, COLOR_RED, and SET_DATA_BYTE.
| [in] | pix | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
| [in] | scalex | must be < 0.7 |
| [in] | scaley | must be < 0.7 |
Notes:
(1) This function should only be used when the scale factors are less
than 0.7. If either scale factor is >= 0.7, issue a warning
and call pixScaleGeneral(), which will invoke linear interpolation
without sharpening.
(2) This works only on 2, 4, 8 and 32 bpp images, and if there is
a colormap, it is removed by converting to RGB.
(3) It does simple (flat filter) convolution, with a filter size
commensurate with the amount of reduction, to avoid antialiasing.
(4) It does simple subsampling after smoothing, which is appropriate
for this range of scaling. Linear interpolation gives essentially
the same result with more computation for these scale factors,
so we don't use it.
(5) The result is the same as doing a full block convolution followed by
subsampling, but this is faster because the results of the block
convolution are only computed at the subsampling locations.
In fact, the computation time is approximately independent of
the scale factor, because the convolution kernel is adjusted
so that each source pixel is summed approximately once.
Definition at line 1711 of file scale1.c.
References L_CLONE, pixScaleGeneral(), and scaleSmoothLow().
Referenced by pixScaleAreaMap(), pixScaleGeneral(), and pixScaleSmoothToSize().
| [in] | pixs | 2, 4, 8 or 32 bpp; and 2, 4, 8 bpp with colormap |
| [in] | wd | target width; use 0 if using height as target |
| [in] | hd | target height; use 0 if using width as target |
Notes:
(1) See notes in pixScaleSmooth().
(2) The output scaled image has the dimension(s) you specify:
- To specify the width with isotropic scaling, set hd = 0.
- To specify the height with isotropic scaling, set wd = 0.
- If both wd and hd are specified, the image is scaled
(in general, anisotropically) to that size.
- It is an error to set both wd and hd to 0.
Definition at line 1795 of file scale1.c.
References pixScaleSmooth().
| PIX * pixScaleToResolution | ( | PIX * | pixs, |
| l_float32 | target, | ||
| l_float32 | assumed, | ||
| l_float32 * | pscalefact ) |
| [in] | pixs | |
| [in] | target | desired resolution |
| [in] | assumed | assumed resolution if not defined; typ. 300. |
| [out] | pscalefact | [optional] actual scaling factor used |
Definition at line 361 of file scale1.c.
References pixScale().
| [in] | pixs | 1, 2, 4, 8, 16 and 32 bpp |
| [in] | wd | target width; use 0 if using height as target |
| [in] | hd | target height; use 0 if using width as target |
Notes:
(1) The output scaled image has the dimension(s) you specify:
* To specify the width with isotropic scaling, set hd = 0.
* To specify the height with isotropic scaling, set wd = 0.
* If both wd and hd are specified, the image is scaled
(in general, anisotropically) to that size.
* It is an error to set both wd and hd to 0.
Definition at line 323 of file scale1.c.
References pixScale().
Referenced by pixScaleToSizeRel().
| [in] | pixs | |
| [in] | delw | change in width, in pixels; 0 means no change |
| [in] | delh | change in height, in pixels; 0 means no change |
Definition at line 282 of file scale1.c.
References pixScaleToSize().
|
static |
Notes:
(1) This function is called with either 8 bpp gray or 32 bpp RGB.
The result is a 2x reduced dest.
Definition at line 3657 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
Referenced by pixScaleAreaMap2().
|
static |
|
static |
Notes:
(1) The dest must be cleared prior to this operation,
and we clear it here in the low-level code.
(2) We reuse dest pixels and dest pixel rows whenever
possible. This speeds the upscaling; downscaling
is done by strict subsampling and is unaffected.
(3) Because we are sampling and not interpolating, this
routine works directly, without conversion to full
RGB color, for 2, 4 or 8 bpp palette color images.
Definition at line 3095 of file scale1.c.
References GET_DATA_BYTE, GET_DATA_DIBIT, GET_DATA_QBIT, GET_DATA_TWO_BYTES, SET_DATA_BYTE, SET_DATA_DIBIT, SET_DATA_QBIT, and SET_DATA_TWO_BYTES.
Referenced by pixScaleBySamplingWithShift().
|
static |
| [in] | lined | ptr to top destline, to be made from current src line |
| [in] | wpld | |
| [in] | lines | ptr to current src line |
| [in] | ws | |
| [in] | wpls | |
| [in] | lastlineflag | 1 if last src line; 0 otherwise |
Definition at line 2520 of file scale1.c.
Referenced by scaleColor2xLILow().
|
static |
Notes:
(1) This is a special case of 2x expansion by linear
interpolation. Each src pixel contains 4 dest pixels.
The 4 dest pixels in src pixel 1 are numbered at
their UL corners. The 4 dest pixels in src pixel 1
are related to that src pixel and its 3 neighboring
src pixels as follows:
1-----2-----|-----|-----|
| | | | |
| | | | |
src 1 --> 3-----4-----| | | <-- src 2
| | | | |
| | | | |
|-----|-----|-----|-----|
| | | | |
| | | | |
src 3 --> | | | | | <-- src 4
| | | | |
| | | | |
|-----|-----|-----|-----|
dest src
---- ---
dp1 = sp1
dp2 = (sp1 + sp2) / 2
dp3 = (sp1 + sp3) / 2
dp4 = (sp1 + sp2 + sp3 + sp4) / 4
(2) We iterate over the src pixels, and unroll the calculation
for each set of 4 dest pixels corresponding to that src
pixel, caching pixels for the next src pixel whenever possible.
The method is exactly analogous to the one we use for
scaleGray2xLILow() and its line version.
Definition at line 2472 of file scale1.c.
References scaleColor2xLILineLow().
Referenced by pixScaleColor2xLI().
|
static |
Notes:
(1) This should only be used for downscaling.
We choose to divide each pixel into 16 x 16 sub-pixels.
This is much slower than scaleSmoothLow(), but it gives a
better representation, esp. for downscaling factors between
1.5 and 5. All src pixels are subdivided into 256 sub-pixels,
and are weighted by the number of sub-pixels covered by
the dest pixel. This is about 2x slower than scaleSmoothLow(),
but the results are significantly better on small text.
Definition at line 3392 of file scale1.c.
Referenced by pixScaleAreaMap().
|
static |
Notes:
(1) We choose to divide each pixel into 16 x 16 sub-pixels.
Linear interpolation is equivalent to finding the
fractional area (i.e., number of sub-pixels divided
by 256) associated with each of the four nearest src pixels,
and weighting each pixel value by this fractional area.
Definition at line 2250 of file scale1.c.
Referenced by pixScaleColorLI().
|
static |
| [in] | lined | ptr to top destline, to be made from current src line |
| [in] | wpld | |
| [in] | lines | ptr to current src line |
| [in] | ws | |
| [in] | wpls | |
| [in] | lastlineflag | 1 if last src line; 0 otherwise |
Definition at line 2722 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
Referenced by pixScaleGray2xLIDither(), pixScaleGray2xLIThresh(), and scaleGray2xLILow().
|
static |
Notes:
(1) This is a special case of 2x expansion by linear
interpolation. Each src pixel contains 4 dest pixels.
The 4 dest pixels in src pixel 1 are numbered at
their UL corners. The 4 dest pixels in src pixel 1
are related to that src pixel and its 3 neighboring
src pixels as follows:
1-----2-----|-----|-----|
| | | | |
| | | | |
src 1 --> 3-----4-----| | | <-- src 2
| | | | |
| | | | |
|-----|-----|-----|-----|
| | | | |
| | | | |
src 3 --> | | | | | <-- src 4
| | | | |
| | | | |
|-----|-----|-----|-----|
dest src
---- ---
dp1 = sp1
dp2 = (sp1 + sp2) / 2
dp3 = (sp1 + sp3) / 2
dp4 = (sp1 + sp2 + sp3 + sp4) / 4
(2) We iterate over the src pixels, and unroll the calculation
for each set of 4 dest pixels corresponding to that src
pixel, caching pixels for the next src pixel whenever possible.
Definition at line 2674 of file scale1.c.
References scaleGray2xLILineLow().
Referenced by pixScaleGray2xLI().
|
static |
| [in] | lined | ptr to top destline, to be made from current src line |
| [in] | wpld | |
| [in] | lines | ptr to current src line |
| [in] | ws | |
| [in] | wpls | |
| [in] | lastlineflag | 1 if last src line; 0 otherwise |
Definition at line 2961 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
Referenced by pixScaleGray4xLIDither(), pixScaleGray4xLIThresh(), and scaleGray4xLILow().
|
static |
Notes:
(1) This is a special case of 4x expansion by linear
interpolation. Each src pixel contains 16 dest pixels.
The 16 dest pixels in src pixel 1 are numbered at
their UL corners. The 16 dest pixels in src pixel 1
are related to that src pixel and its 3 neighboring
src pixels as follows:
1---2---3---4---|---|---|---|---|
| | | | | | | | |
5---6---7---8---|---|---|---|---|
| | | | | | | | |
src 1 --> 9---a---b---c---|---|---|---|---| <-- src 2
| | | | | | | | |
d---e---f---g---|---|---|---|---|
| | | | | | | | |
|===|===|===|===|===|===|===|===|
| | | | | | | | |
|---|---|---|---|---|---|---|---|
| | | | | | | | |
src 3 --> |---|---|---|---|---|---|---|---| <-- src 4
| | | | | | | | |
|---|---|---|---|---|---|---|---|
| | | | | | | | |
|---|---|---|---|---|---|---|---|
dest src
---- ---
dp1 = sp1
dp2 = (3 * sp1 + sp2) / 4
dp3 = (sp1 + sp2) / 2
dp4 = (sp1 + 3 * sp2) / 4
dp5 = (3 * sp1 + sp3) / 4
dp6 = (9 * sp1 + 3 * sp2 + 3 * sp3 + sp4) / 16
dp7 = (3 * sp1 + 3 * sp2 + sp3 + sp4) / 8
dp8 = (3 * sp1 + 9 * sp2 + 1 * sp3 + 3 * sp4) / 16
dp9 = (sp1 + sp3) / 2
dp10 = (3 * sp1 + sp2 + 3 * sp3 + sp4) / 8
dp11 = (sp1 + sp2 + sp3 + sp4) / 4
dp12 = (sp1 + 3 * sp2 + sp3 + 3 * sp4) / 8
dp13 = (sp1 + 3 * sp3) / 4
dp14 = (3 * sp1 + sp2 + 9 * sp3 + 3 * sp4) / 16
dp15 = (sp1 + sp2 + 3 * sp3 + 3 * sp4) / 8
dp16 = (sp1 + 3 * sp2 + 3 * sp3 + 9 * sp4) / 16
(2) We iterate over the src pixels, and unroll the calculation
for each set of 16 dest pixels corresponding to that src
pixel, caching pixels for the next src pixel whenever possible.
Definition at line 2915 of file scale1.c.
References scaleGray4xLILineLow().
Referenced by pixScaleGray4xLI().
|
static |
Notes:
(1) This should only be used for downscaling.
We choose to divide each pixel into 16 x 16 sub-pixels.
This is about 2x slower than scaleSmoothLow(), but the results
are significantly better on small text, esp. for downscaling
factors between 1.5 and 5. All src pixels are subdivided
into 256 sub-pixels, and are weighted by the number of
sub-pixels covered by the dest pixel.
Definition at line 3550 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
Referenced by pixScaleAreaMap().
|
static |
Notes:
(1) We choose to divide each pixel into 16 x 16 sub-pixels.
Linear interpolation is equivalent to finding the
fractional area (i.e., number of sub-pixels divided
by 256) associated with each of the four nearest src pixels,
and weighting each pixel value by this fractional area.
Definition at line 2355 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
Referenced by pixScaleGrayLI().
|
static |
Notes:
(1) This function is called with 32 bpp RGB src and 8 bpp,
half-resolution dest. The weights should add to 1.0.
Definition at line 3327 of file scale1.c.
References SET_DATA_BYTE.
Referenced by pixScaleRGBToGray2().
|
static |
Notes:
(1) This function is called on 8 or 32 bpp src and dest images.
(2) size is the full width of the lowpass smoothing filter.
It is correlated with the reduction ratio, being the
nearest integer such that size is approximately equal to hs / hd.
Definition at line 3228 of file scale1.c.
References GET_DATA_BYTE, and SET_DATA_BYTE.
Referenced by pixScaleSmooth().