本文整理汇总了C++中L_MIN函数的典型用法代码示例。如果您正苦于以下问题:C++ L_MIN函数的具体用法?C++ L_MIN怎么用?C++ L_MIN使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了L_MIN函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: pixErodeGray3h
/*!
* pixErodeGray3h()
*
* Input: pixs (8 bpp, not cmapped)
* Return: pixd, or null on error
*
* Notes:
* (1) Special case for horizontal 3x1 brick Sel;
* also used as the first step for the 3x3 brick Sel.
*/
static PIX *
pixErodeGray3h(PIX *pixs)
{
l_uint32 *datas, *datad, *lines, *lined;
l_int32 w, h, wpl, i, j;
l_int32 val0, val1, val2, val3, val4, val5, val6, val7, val8, val9, minval;
PIX *pixd;
PROCNAME("pixErodeGray3h");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) != 8)
return (PIX *)ERROR_PTR("pixs not 8 bpp", procName, NULL);
pixd = pixCreateTemplateNoInit(pixs);
pixSetBorderVal(pixd, 4, 8, 2, 8, 0); /* only to silence valgrind */
pixGetDimensions(pixs, &w, &h, NULL);
datas = pixGetData(pixs);
datad = pixGetData(pixd);
wpl = pixGetWpl(pixs);
for (i = 0; i < h; i++) {
lines = datas + i * wpl;
lined = datad + i * wpl;
for (j = 1; j < w - 8; j += 8) {
val0 = GET_DATA_BYTE(lines, j - 1);
val1 = GET_DATA_BYTE(lines, j);
val2 = GET_DATA_BYTE(lines, j + 1);
val3 = GET_DATA_BYTE(lines, j + 2);
val4 = GET_DATA_BYTE(lines, j + 3);
val5 = GET_DATA_BYTE(lines, j + 4);
val6 = GET_DATA_BYTE(lines, j + 5);
val7 = GET_DATA_BYTE(lines, j + 6);
val8 = GET_DATA_BYTE(lines, j + 7);
val9 = GET_DATA_BYTE(lines, j + 8);
minval = L_MIN(val1, val2);
SET_DATA_BYTE(lined, j, L_MIN(val0, minval));
SET_DATA_BYTE(lined, j + 1, L_MIN(minval, val3));
minval = L_MIN(val3, val4);
SET_DATA_BYTE(lined, j + 2, L_MIN(val2, minval));
SET_DATA_BYTE(lined, j + 3, L_MIN(minval, val5));
minval = L_MIN(val5, val6);
SET_DATA_BYTE(lined, j + 4, L_MIN(val4, minval));
SET_DATA_BYTE(lined, j + 5, L_MIN(minval, val7));
minval = L_MIN(val7, val8);
SET_DATA_BYTE(lined, j + 6, L_MIN(val6, minval));
SET_DATA_BYTE(lined, j + 7, L_MIN(minval, val9));
}
}
return pixd;
}
开发者ID:ansgri,项目名称:rsdt-students,代码行数:61,代码来源:graymorph.c
示例2: pixDisplayWithTitle
/*!
* pixDisplayWithTitle()
*
* Input: pix (1, 2, 4, 8, 16, 32 bpp)
* x, y (location of display frame)
* title (<optional> on frame; can be NULL);
* dispflag (1 to write, else disabled)
* Return: 0 if OK; 1 on error
*
* Notes:
* (1) See notes for pixDisplay().
* (2) This displays the image if dispflag == 1.
*/
l_int32
pixDisplayWithTitle(PIX *pixs,
l_int32 x,
l_int32 y,
const char *title,
l_int32 dispflag)
{
char *tempname;
char buffer[L_BUF_SIZE];
static l_int32 index = 0; /* caution: not .so or thread safe */
l_int32 w, h, d, spp, maxheight, opaque, threeviews, ignore;
l_float32 ratw, rath, ratmin;
PIX *pix0, *pix1, *pix2;
PIXCMAP *cmap;
#ifndef _WIN32
l_int32 wt, ht;
#else
char *pathname;
char fullpath[_MAX_PATH];
#endif /* _WIN32 */
PROCNAME("pixDisplayWithTitle");
if (dispflag != 1) return 0;
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
if (var_DISPLAY_PROG != L_DISPLAY_WITH_XZGV &&
var_DISPLAY_PROG != L_DISPLAY_WITH_XLI &&
var_DISPLAY_PROG != L_DISPLAY_WITH_XV &&
var_DISPLAY_PROG != L_DISPLAY_WITH_IV &&
var_DISPLAY_PROG != L_DISPLAY_WITH_OPEN) {
return ERROR_INT("no program chosen for display", procName, 1);
}
/* Display with three views if either spp = 4 or if colormapped
* and the alpha component is not fully opaque */
opaque = TRUE;
if ((cmap = pixGetColormap(pixs)) != NULL)
pixcmapIsOpaque(cmap, &opaque);
spp = pixGetSpp(pixs);
threeviews = (spp == 4 || !opaque) ? TRUE : FALSE;
/* If colormapped and not opaque, remove the colormap to RGBA */
if (!opaque)
pix0 = pixRemoveColormap(pixs, REMOVE_CMAP_WITH_ALPHA);
else
pix0 = pixClone(pixs);
/* Scale if necessary; this will also remove a colormap */
pixGetDimensions(pix0, &w, &h, &d);
maxheight = (threeviews) ? MAX_DISPLAY_HEIGHT / 3 : MAX_DISPLAY_HEIGHT;
if (w <= MAX_DISPLAY_WIDTH && h <= maxheight) {
if (d == 16) /* take MSB */
pix1 = pixConvert16To8(pix0, 1);
else
pix1 = pixClone(pix0);
} else {
ratw = (l_float32)MAX_DISPLAY_WIDTH / (l_float32)w;
rath = (l_float32)maxheight / (l_float32)h;
ratmin = L_MIN(ratw, rath);
if (ratmin < 0.125 && d == 1)
pix1 = pixScaleToGray8(pix0);
else if (ratmin < 0.25 && d == 1)
pix1 = pixScaleToGray4(pix0);
else if (ratmin < 0.33 && d == 1)
pix1 = pixScaleToGray3(pix0);
else if (ratmin < 0.5 && d == 1)
pix1 = pixScaleToGray2(pix0);
else
pix1 = pixScale(pix0, ratmin, ratmin);
}
pixDestroy(&pix0);
if (!pix1)
return ERROR_INT("pix1 not made", procName, 1);
/* Generate the three views if required */
if (threeviews)
pix2 = pixDisplayLayersRGBA(pix1, 0xffffff00, 0);
else
pix2 = pixClone(pix1);
if (index == 0) {
lept_rmdir("disp");
lept_mkdir("disp");
}
index++;
//.........这里部分代码省略.........
开发者ID:KevinSantos,项目名称:openalpr-windows,代码行数:101,代码来源:writefile.c
示例3: main
//.........这里部分代码省略.........
#if ALL
/* 1. Standard background normalization with a global threshold. */
pixg = pixConvertTo8(pixs, 0);
pix1 = pixBackgroundNorm(pixg, NULL, NULL, 10, 15, 100, 50, 255, 2, 2);
pix2 = pixThresholdToBinary(pix1, 160);
pixWrite("/tmp/binar1.png", pix2, IFF_PNG);
pixDisplay(pix2, 100, 0);
pixSaveTiled(pix2, pixa, 1.0, 1, 50, 32);
pixDestroy(&pixg);
pixDestroy(&pix1);
pixDestroy(&pix2);
#endif
#if ALL
/* 2. Background normalization followed by Otsu thresholding. Otsu
* binarization attempts to split the image into two roughly equal
* sets of pixels, and it does a very poor job when there are large
* amounts of dark background. By doing a background normalization
* first (to get the background near 255), we remove this problem.
* Then we use a modified Otsu to estimate the best global
* threshold on the normalized image. */
pixg = pixConvertTo8(pixs, 0);
pix1 = pixOtsuThreshOnBackgroundNorm(pixg, NULL, 10, 15, 100,
50, 255, 2, 2, 0.10, &threshval);
fprintf(stderr, "thresh val = %d\n", threshval);
pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32);
pixWrite("/tmp/binar2.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 200);
pixDestroy(&pixg);
pixDestroy(&pix1);
#endif
#if ALL
/* 3. Background normalization with Otsu threshold estimation and
* masking for threshold selection. */
pixg = pixConvertTo8(pixs, 0);
pix1 = pixMaskedThreshOnBackgroundNorm(pixg, NULL, 10, 15, 100,
50, 2, 2, 0.10, &threshval);
fprintf(stderr, "thresh val = %d\n", threshval);
pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32);
pixWrite("/tmp/binar3.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 400);
pixDestroy(&pixg);
pixDestroy(&pix1);
#endif
#if ALL
/* 4. Background normalization followed by Sauvola binarization */
if (d == 32)
pixg = pixConvertRGBToGray(pixs, 0.2, 0.7, 0.1);
else
pixg = pixConvertTo8(pixs, 0);
pixg2 = pixContrastNorm(NULL, pixg, 20, 20, 130, 2, 2);
pixSauvolaBinarizeTiled(pixg2, 25, 0.40, 1, 1, NULL, &pix1);
pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32);
pixWrite("/tmp/binar4.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 600);
pixDestroy(&pixg);
pixDestroy(&pixg2);
pixDestroy(&pix1);
#endif
#if ALL
/* 5. Contrast normalization followed by background normalization, and
* thresholding. */
if (d == 32)
pixg = pixConvertRGBToGray(pixs, 0.2, 0.7, 0.1);
else
pixg = pixConvertTo8(pixs, 0);
pixOtsuAdaptiveThreshold(pixg, 5000, 5000, 0, 0, 0.1, &pix1, NULL);
pixGetPixel(pix1, 0, 0, &val);
ival = (l_int32) val;
newval = ival + (l_int32)(0.6 * (110 - ival));
fprintf(stderr, "th1 = %d, th2 = %d\n", ival, newval);
pixDestroy(&pix1);
pixContrastNorm(pixg, pixg, 50, 50, 130, 2, 2);
pixg2 = pixBackgroundNorm(pixg, NULL, NULL, 20, 20, 70, 40, 200, 2, 2);
ival = L_MIN(ival, 110);
pix1 = pixThresholdToBinary(pixg2, ival);
pixSaveTiled(pix1, pixa, 1.0, 1, 50, 32);
pixWrite("/tmp/binar5.png", pix1, IFF_PNG);
pixDisplay(pix1, 100, 800);
pixDestroy(&pixg);
pixDestroy(&pixg2);
pixDestroy(&pix1);
#endif
pix1 = pixaDisplayTiledInRows(pixa, 32, w + 100, 1.0, 0, 30, 2);
pixWrite("/tmp/binar6.png", pix1, IFF_PNG);
pixDisplay(pix1, 1000, 0);
pixDestroy(&pix1);
pixaDestroy(&pixa);
pixDestroy(&pixs);
return 0;
}
开发者ID:mehulsbhatt,项目名称:MyOCRTEST,代码行数:101,代码来源:binarize_set.c
示例4: pixOtsuAdaptiveThreshold
/*!
* pixOtsuAdaptiveThreshold()
*
* Input: pixs (8 bpp)
* sx, sy (desired tile dimensions; actual size may vary)
* smoothx, smoothy (half-width of convolution kernel applied to
* threshold array: use 0 for no smoothing)
* scorefract (fraction of the max Otsu score; typ. 0.1;
* use 0.0 for standard Otsu)
* &pixth (<optional return> array of threshold values
* found for each tile)
* &pixd (<optional return> thresholded input pixs, based on
* the threshold array)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) The Otsu method finds a single global threshold for an image.
* This function allows a locally adapted threshold to be
* found for each tile into which the image is broken up.
* (2) The array of threshold values, one for each tile, constitutes
* a highly downscaled image. This array is optionally
* smoothed using a convolution. The full width and height of the
* convolution kernel are (2 * @smoothx + 1) and (2 * @smoothy + 1).
* (3) The minimum tile dimension allowed is 16. If such small
* tiles are used, it is recommended to use smoothing, because
* without smoothing, each small tile determines the splitting
* threshold independently. A tile that is entirely in the
* image bg will then hallucinate fg, resulting in a very noisy
* binarization. The smoothing should be large enough that no
* tile is only influenced by one type (fg or bg) of pixels,
* because it will force a split of its pixels.
* (4) To get a single global threshold for the entire image, use
* input values of @sx and @sy that are larger than the image.
* For this situation, the smoothing parameters are ignored.
* (5) The threshold values partition the image pixels into two classes:
* one whose values are less than the threshold and another
* whose values are greater than or equal to the threshold.
* This is the same use of 'threshold' as in pixThresholdToBinary().
* (6) The scorefract is the fraction of the maximum Otsu score, which
* is used to determine the range over which the histogram minimum
* is searched. See numaSplitDistribution() for details on the
* underlying method of choosing a threshold.
* (7) This uses enables a modified version of the Otsu criterion for
* splitting the distribution of pixels in each tile into a
* fg and bg part. The modification consists of searching for
* a minimum in the histogram over a range of pixel values where
* the Otsu score is within a defined fraction, @scorefract,
* of the max score. To get the original Otsu algorithm, set
* @scorefract == 0.
*/
l_int32
pixOtsuAdaptiveThreshold(PIX *pixs,
l_int32 sx,
l_int32 sy,
l_int32 smoothx,
l_int32 smoothy,
l_float32 scorefract,
PIX **ppixth,
PIX **ppixd)
{
l_int32 w, h, nx, ny, i, j, thresh;
l_uint32 val;
PIX *pixt, *pixb, *pixthresh, *pixth, *pixd;
PIXTILING *pt;
PROCNAME("pixOtsuAdaptiveThreshold");
if (!ppixth && !ppixd){
return ERROR_INT("neither &pixth nor &pixd defined", procName, 1);
LOGE("neither &pixth nor &pixd defined");
}
if (ppixth) *ppixth = NULL;
if (ppixd) *ppixd = NULL;
if (!pixs || pixGetDepth(pixs) != 8){
return ERROR_INT("pixs not defined or not 8 bpp", procName, 1);
LOGE("pixs not defined or not 8 bpp");
}
if (sx < 16 || sy < 16){
return ERROR_INT("sx and sy must be >= 16", procName, 1);
LOGE("sx and sy must be >= 16");
}
/* Compute the threshold array for the tiles */
pixGetDimensions(pixs, &w, &h, NULL);
nx = L_MAX(1, w / sx);
ny = L_MAX(1, h / sy);
smoothx = L_MIN(smoothx, (nx - 1) / 2);
smoothy = L_MIN(smoothy, (ny - 1) / 2);
pt = pixTilingCreate(pixs, nx, ny, 0, 0, 0, 0);
pixthresh = pixCreate(nx, ny, 8);
for (i = 0; i < ny; i++) {
for (j = 0; j < nx; j++) {
pixt = pixTilingGetTile(pt, i, j);
pixSplitDistributionFgBg(pixt, scorefract, 1, &thresh,
NULL, NULL, 0);
pixSetPixel(pixthresh, j, i, thresh); /* see note (4) */
pixDestroy(&pixt);
}
}
//.........这里部分代码省略.........
开发者ID:TigerZhag,项目名称:ScanTranslation,代码行数:101,代码来源:binarize.c
示例5: main
main(int argc,
char **argv)
{
l_int32 i, j, w1, h1, w2, h2, w, h, same;
BOX *box1, *box2;
PIX *pixs, *pixs1, *pixs2, *pix1, *pix2;
PIX *pixg, *pixg1, *pixg2, *pixc2, *pixbl, *pixd;
PIXA *pixa;
static char mainName[] = "blend2_reg";
/* --- Set up the 8 bpp blending image --- */
pixg = pixCreate(660, 500, 8);
for (i = 0; i < 500; i++)
for (j = 0; j < 660; j++)
pixSetPixel(pixg, j, i, (l_int32)(0.775 * j) % 256);
/* --- Set up the initial color images to be blended together --- */
pixs1 = pixRead("wyom.jpg");
pixs2 = pixRead("fish24.jpg");
pixGetDimensions(pixs1, &w1, &h1, NULL);
pixGetDimensions(pixs2, &w2, &h2, NULL);
h = L_MIN(h1, h2);
w = L_MIN(w1, w2);
box1 = boxCreate(0, 0, w1, h1);
box2 = boxCreate(0, 300, 660, 500);
pix1 = pixClipRectangle(pixs1, box1, NULL);
pix2 = pixClipRectangle(pixs2, box2, NULL);
pixDestroy(&pixs1);
pixDestroy(&pixs2);
boxDestroy(&box1);
boxDestroy(&box2);
/* --- Blend 2 rgb images --- */
pixa = pixaCreate(0);
pixSaveTiled(pixg, pixa, 1, 1, 40, 32);
pixd = pixBlendWithGrayMask(pix1, pix2, pixg, 50, 50);
pixSaveTiled(pix1, pixa, 1, 1, 40, 32);
pixSaveTiled(pix2, pixa, 1, 0, 40, 32);
pixSaveTiled(pixd, pixa, 1, 0, 40, 32);
pixDestroy(&pixd);
/* --- Blend 2 grayscale images --- */
pixg1 = pixConvertRGBToLuminance(pix1);
pixg2 = pixConvertRGBToLuminance(pix2);
pixd = pixBlendWithGrayMask(pixg1, pixg2, pixg, 50, 50);
pixSaveTiled(pixg1, pixa, 1, 1, 40, 32);
pixSaveTiled(pixg2, pixa, 1, 0, 40, 32);
pixSaveTiled(pixd, pixa, 1, 0, 40, 32);
pixDestroy(&pixg1);
pixDestroy(&pixg2);
pixDestroy(&pixd);
/* --- Blend a colormap image and an rgb image --- */
pixc2 = pixFixedOctcubeQuantGenRGB(pix2, 2);
pixd = pixBlendWithGrayMask(pix1, pixc2, pixg, 50, 50);
pixSaveTiled(pix1, pixa, 1, 1, 40, 32);
pixSaveTiled(pixc2, pixa, 1, 0, 40, 32);
pixSaveTiled(pixd, pixa, 1, 0, 40, 32);
pixDestroy(&pixc2);
pixDestroy(&pixd);
/* --- Blend a colormap image and a grayscale image --- */
pixg1 = pixConvertRGBToLuminance(pix1);
pixc2 = pixFixedOctcubeQuantGenRGB(pix2, 2);
pixd = pixBlendWithGrayMask(pixg1, pixc2, pixg, 50, 50);
pixSaveTiled(pixg1, pixa, 1, 1, 40, 32);
pixSaveTiled(pixc2, pixa, 1, 0, 40, 32);
pixSaveTiled(pixd, pixa, 1, 0, 40, 32);
pixDestroy(&pixd);
pixd = pixBlendWithGrayMask(pixg1, pixc2, pixg, -100, -100);
pixSaveTiled(pixg1, pixa, 1, 1, 40, 32);
pixSaveTiled(pixc2, pixa, 1, 0, 40, 32);
pixSaveTiled(pixd, pixa, 1, 0, 40, 32);
pixDestroy(&pixd);
pixDestroy(&pixg1);
pixDestroy(&pixc2);
/* --- Test png read/write with alpha channel --- */
/* First make pixs1, using pixg as the alpha channel */
pixs = pixRead("fish24.jpg");
box1 = boxCreate(0, 300, 660, 500);
pixs1 = pixClipRectangle(pixs, box1, NULL);
pixSaveTiled(pixs1, pixa, 1, 1, 40, 32);
pixSetRGBComponent(pixs1, pixg, L_ALPHA_CHANNEL);
/* To see the alpha channel, blend with a black image */
pixbl = pixCreate(660, 500, 32);
pixd = pixBlendWithGrayMask(pixbl, pixs1, NULL, 0, 0);
pixSaveTiled(pixd, pixa, 1, 0, 40, 32);
pixDestroy(&pixd);
/* Write out the RGBA image and read it back */
l_pngSetWriteAlpha(1);
pixWrite("/tmp/junkpixs1.png", pixs1, IFF_PNG);
l_pngSetStripAlpha(0);
pixs2 = pixRead("/tmp/junkpixs1.png");
/* Make sure that the alpha channel image hasn't changed */
pixg2 = pixGetRGBComponent(pixs2, L_ALPHA_CHANNEL);
pixEqual(pixg, pixg2, &same);
if (same)
fprintf(stderr, "PNG with alpha read/write OK\n");
else
//.........这里部分代码省略.........
开发者ID:0xkasun,项目名称:Dummy_Tes,代码行数:101,代码来源:blend2_reg.c
示例6: ComputePairWidthRatio
l_float32 ComputePairWidthRatio(BOX *b1, BOX *b2) {
l_float32 ratio = L_MIN(b1->w, b2->w) / L_MAX(b1->w, b2->w);
return ratio;
}
开发者ID:0359xiaodong,项目名称:tess-two,代码行数:5,代码来源:validator.cpp
示例7: BBoxVDist
l_int32 BBoxVDist(BOX *b1, BOX *b2) {
return L_MAX(b1->y, b2->y) - L_MIN(b1->y + b1->h, b2->y + b2->h);
}
开发者ID:0359xiaodong,项目名称:tess-two,代码行数:3,代码来源:validator.cpp
示例8: pixReadStreamJpeg
//.........这里部分代码省略.........
if (jpeg_read_scanlines(&cinfo, &rowbuffer, (JDIMENSION)1) == 0) {
L_ERROR("read error at scanline %d\n", procName, i);
pixDestroy(&pix);
jpeg_destroy_decompress(&cinfo);
LEPT_FREE(rowbuffer);
return (PIX *)ERROR_PTR("bad data", procName, NULL);
}
/* -- 24 bit color -- */
if ((spp == 3 && cmapflag == 0) || ycck || cmyk) {
ppixel = data + i * wpl;
if (spp == 3) {
for (j = k = 0; j < w; j++) {
SET_DATA_BYTE(ppixel, COLOR_RED, rowbuffer[k++]);
SET_DATA_BYTE(ppixel, COLOR_GREEN, rowbuffer[k++]);
SET_DATA_BYTE(ppixel, COLOR_BLUE, rowbuffer[k++]);
ppixel++;
}
} else {
/* This is a conversion from CMYK -> RGB that ignores
color profiles, and is invoked when the image header
claims to be in CMYK or YCCK colorspace. If in YCCK,
libjpeg may be doing YCCK -> CMYK under the hood.
To understand why the colors need to be inverted on
read-in for the Adobe marker, see the "Special
color spaces" section of "Using the IJG JPEG
Library" by Thomas G. Lane:
http://www.jpegcameras.com/libjpeg/libjpeg-3.html#ss3.1
The non-Adobe conversion is equivalent to:
rval = black - black * cyan / 255
...
The Adobe conversion is equivalent to:
rval = black - black * (255 - cyan) / 255
...
Note that cyan is the complement to red, and we
are subtracting the complement color (weighted
by black) from black. For Adobe conversions,
where they've already inverted the CMY but not
the K, we have to invert again. The results
must be clipped to [0 ... 255]. */
for (j = k = 0; j < w; j++) {
cyan = rowbuffer[k++];
magenta = rowbuffer[k++];
yellow = rowbuffer[k++];
black = rowbuffer[k++];
if (cinfo.saw_Adobe_marker) {
rval = (black * cyan) / 255;
gval = (black * magenta) / 255;
bval = (black * yellow) / 255;
} else {
rval = black * (255 - cyan) / 255;
gval = black * (255 - magenta) / 255;
bval = black * (255 - yellow) / 255;
}
rval = L_MIN(L_MAX(rval, 0), 255);
gval = L_MIN(L_MAX(gval, 0), 255);
bval = L_MIN(L_MAX(bval, 0), 255);
composeRGBPixel(rval, gval, bval, ppixel);
ppixel++;
}
}
} else { /* 8 bpp grayscale or colormapped pix */
line = data + i * wpl;
for (j = 0; j < w; j++)
SET_DATA_BYTE(line, j, rowbuffer[j]);
}
}
nwarn = cinfo.err->num_warnings;
if (pnwarn) *pnwarn = nwarn;
/* If the pixel density is neither 1 nor 2, it may not be defined.
* In that case, don't set the resolution. */
if (cinfo.density_unit == 1) { /* pixels per inch */
pixSetXRes(pix, cinfo.X_density);
pixSetYRes(pix, cinfo.Y_density);
} else if (cinfo.density_unit == 2) { /* pixels per centimeter */
pixSetXRes(pix, (l_int32)((l_float32)cinfo.X_density * 2.54 + 0.5));
pixSetYRes(pix, (l_int32)((l_float32)cinfo.Y_density * 2.54 + 0.5));
}
if (cinfo.output_components != spp)
fprintf(stderr, "output spp = %d, spp = %d\n",
cinfo.output_components, spp);
jpeg_finish_decompress(&cinfo);
jpeg_destroy_decompress(&cinfo);
LEPT_FREE(rowbuffer);
if (nwarn > 0) {
if (hint & L_JPEG_FAIL_ON_BAD_DATA) {
L_ERROR("fail with %d warning(s) of bad data\n", procName, nwarn);
pixDestroy(&pix);
} else {
L_WARNING("%d warning(s) of bad data\n", procName, nwarn);
}
}
return pix;
}
开发者ID:MaTriXy,项目名称:tess-two,代码行数:101,代码来源:jpegio.c
示例9: pixFindLargestRectangle
//.........这里部分代码省略.........
return ERROR_INT("pixs not defined", procName, 1);
pixGetDimensions(pixs, &w, &h, &d);
if (d != 1)
return ERROR_INT("pixs not 1 bpp", procName, 1);
if (polarity != 0 && polarity != 1)
return ERROR_INT("invalid polarity", procName, 1);
/* Initialize lowest "fg" seen so far for each column */
lowestfg = (l_int32 *)CALLOC(w, sizeof(l_int32));
for (i = 0; i < w; i++)
lowestfg[i] = -1;
/* The combination (val ^ polarity) is the color for which we
* are searching for the maximum rectangle. For polarity == 0,
* we search in the bg (white). */
pixw = pixCreate(w, h, 32); /* stores width */
pixh = pixCreate(w, h, 32); /* stores height */
linew = (l_uint32 **)pixGetLinePtrs(pixw, NULL);
lineh = (l_uint32 **)pixGetLinePtrs(pixh, NULL);
datas = pixGetData(pixs);
wpls = pixGetWpl(pixs);
maxarea = xmax = ymax = wmax = hmax = 0;
for (i = 0; i < h; i++) {
lines = datas + i * wpls;
prevfg = -1;
for (j = 0; j < w; j++) {
val = GET_DATA_BIT(lines, j);
if ((val ^ polarity) == 0) { /* bg (0) if polarity == 0, etc. */
if (i == 0 && j == 0) {
wp = hp = 1;
}
else if (i == 0) {
wp = linew[i][j - 1] + 1;
hp = 1;
}
else if (j == 0) {
wp = 1;
hp = lineh[i - 1][j] + 1;
}
else {
/* Expand #1 prev rectangle down */
w1 = linew[i - 1][j];
h1 = lineh[i - 1][j];
horizdist = j - prevfg;
wmin = L_MIN(w1, horizdist); /* width of new rectangle */
area1 = wmin * (h1 + 1);
/* Expand #2 prev rectangle to right */
w2 = linew[i][j - 1];
h2 = lineh[i][j - 1];
vertdist = i - lowestfg[j];
hmin = L_MIN(h2, vertdist); /* height of new rectangle */
area2 = hmin * (w2 + 1);
if (area1 > area2) {
wp = wmin;
hp = h1 + 1;
}
else {
wp = w2 + 1;
hp = hmin;
}
}
}
else { /* fg (1) if polarity == 0; bg (0) if polarity == 1 */
prevfg = j;
lowestfg[j] = i;
wp = hp = 0;
}
linew[i][j] = wp;
lineh[i][j] = hp;
if (wp * hp > maxarea) {
maxarea = wp * hp;
xmax = j;
ymax = i;
wmax = wp;
hmax = hp;
}
}
}
/* Translate from LR corner to Box coords (UL corner, w, h) */
box = boxCreate(xmax - wmax + 1, ymax - hmax + 1, wmax, hmax);
*pbox = box;
if (debugfile) {
PIX *pixdb;
pixdb = pixConvertTo8(pixs, TRUE);
pixRenderHashBoxArb(pixdb, box, 6, 2, L_NEG_SLOPE_LINE, 1, 255, 0, 0);
pixWrite(debugfile, pixdb, IFF_PNG);
pixDestroy(&pixdb);
}
FREE(linew);
FREE(lineh);
FREE(lowestfg);
pixDestroy(&pixw);
pixDestroy(&pixh);
return 0;
}
开发者ID:ansgri,项目名称:rsdt-students,代码行数:101,代码来源:maze.c
示例10: main
int main(int argc,
char **argv)
{
char *filein, *fname, *argp, *argn;
char buffer[512];
l_int32 i, w, h, ignore;
l_float32 scale;
FILE *fp;
PIX *pixs, *pixt;
static char mainName[] = "printimage";
if (argc < 2 || argc > 4)
return ERROR_INT(
" Syntax: printimage filein [-P<printer>] [-#<number>]",
mainName, 1);
/* parse args */
filein = argv[1];
argp = argn = NULL;
if (argc > 2) {
for (i = 2; i < argc; i++) {
if (argv[i][1] == 'P')
argp = argv[i];
else if (argv[i][1] == '#')
argn = argv[i];
}
}
lept_rm(NULL, "print_image.ps");
if ((pixs = pixRead(filein)) == NULL)
return ERROR_INT("pixs not made", mainName, 1);
pixGetDimensions(pixs, &w, &h, NULL);
if (w > h) {
pixt = pixRotate90(pixs, 1);
pixGetDimensions(pixt, &w, &h, NULL);
}
else {
pixt = pixClone(pixs);
}
scale = L_MIN(FILL_FACTOR * 2550 / w, FILL_FACTOR * 3300 / h);
fname = genPathname("/tmp", "print_image.ps");
fp = lept_fopen(fname, "wb+");
pixWriteStreamPS(fp, pixt, NULL, 300, scale);
lept_fclose(fp);
/* print it out */
if (argp && !argn) {
sprintf(buffer, "lpr %s %s &", argp, fname);
ignore = system(buffer);
} else if (!argp && argn) {
sprintf(buffer, "lpr %s %s &", argn, fname);
ignore = system(buffer);
} else if (argp && argn) {
sprintf(buffer, "lpr %s %s %s &", argp, argn, fname);
ignore = system(buffer);
}
lept_free(fname);
pixDestroy(&pixs);
pixDestroy(&pixt);
return 0;
}
开发者ID:0ximDigital,项目名称:appsScanner,代码行数:64,代码来源:printimage.c
示例11: main
int main(int argc,
char **argv)
{
l_int32 i, w, h;
l_float32 factor, scale;
BOX *box;
FILE *fp1;
PIX *pixs, *pixt;
PIXA *pixa;
SARRAY *sa;
L_REGPARAMS *rp;
if (regTestSetup(argc, argv, &rp))
return 1;
factor = 0.95;
/* Uncompressed PS with scaling but centered on the page */
pixs = pixRead("feyn-fract.tif");
pixGetDimensions(pixs, &w, &h, NULL);
scale = L_MIN(factor * 2550 / w, factor * 3300 / h);
fp1 = lept_fopen("/tmp/regout/psio0.ps", "wb+");
pixWriteStreamPS(fp1, pixs, NULL, 300, scale);
lept_fclose(fp1);
regTestCheckFile(rp, "/tmp/regout/psio0.ps"); /* 0 */
pixDestroy(&pixs);
/* Uncompressed PS with scaling, with LL corner at (1500, 1500) mils */
pixs = pixRead("weasel4.11c.png");
pixGetDimensions(pixs, &w, &h, NULL);
scale = L_MIN(factor * 2550 / w, factor * 3300 / h);
box = boxCreate(1500, 1500, (l_int32)(1000 * scale * w / 300),
(l_int32)(1000 * scale * h / 300));
fp1 = lept_fopen("/tmp/regout/psio1.ps", "wb+");
pixWriteStreamPS(fp1, pixs, box, 300, 1.0);
lept_fclose(fp1);
regTestCheckFile(rp, "/tmp/regout/psio1.ps"); /* 1 */
boxDestroy(&box);
pixDestroy(&pixs);
/* DCT compressed PS with LL corner at (300, 1000) pixels */
pixs = pixRead("marge.jpg");
pixt = pixConvertTo32(pixs);
pixWrite("/tmp/regout/psio2.jpg", pixt, IFF_JFIF_JPEG);
convertJpegToPS("/tmp/regout/psio2.jpg", "/tmp/regout/psio3.ps",
"w", 300, 1000, 0, 4.0, 1, 1);
regTestCheckFile(rp, "/tmp/regout/psio2.jpg"); /* 2 */
regTestCheckFile(rp, "/tmp/regout/psio3.ps"); /* 3 */
pixDestroy(&pixt);
pixDestroy(&pixs);
/* For each page, apply tiff g4 image first; then jpeg or png over it */
convertG4ToPS("feyn.tif", "/tmp/regout/psio4.ps", "w",
0, 0, 0, 1.0, 1, 1, 0);
convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps",
"a", 500, 100, 300, 2.0, 1, 0);
convertFlateToPS("weasel4.11c.png", "/tmp/regout/psio4.ps",
"a", 300, 400, 300, 6.0, 1, 0);
convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps",
"a", 100, 800, 300, 1.5, 1, 1);
convertG4ToPS("feyn.tif", "/tmp/regout/psio4.ps",
"a", 0, 0, 0, 1.0, 2, 1, 0);
convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps",
"a", 1000, 700, 300, 2.0, 2, 0);
convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps",
"a", 100, 200, 300, 2.0, 2, 1);
convertG4ToPS("feyn.tif", "/tmp/regout/psio4.ps",
"a", 0, 0, 0, 1.0, 3, 1, 0);
convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps",
"a", 200, 200, 300, 2.0, 3, 0);
convertJpegToPS("marge.jpg", "/tmp/regout/psio4.ps",
"a", 200, 900, 300, 2.0, 3, 1);
regTestCheckFile(rp, "/tmp/regout/psio4.ps"); /* 4 */
/* Now apply jpeg first; then paint through a g4 mask.
* For gv, the first image with a b.b. determines the
* window size for the canvas, so we put down the largest
* image first. If we had rendered a small image first,
* gv and evince will not show the entire page. However, after
* conversion to pdf, everything works fine, regardless of the
* order in which images are placed into the PS. That is
* because the pdf interpreter is robust to bad hints, ignoring
* the page hints and computing the bounding box from the
* set of images rendered on the page.
*
* Concatenate several pages, with colormapped png, color
* jpeg and tiffg4 images (with the g4 image acting as a mask
* that we're painting black through. If the text layer
* is painted first, the following images occlude it; otherwise,
* the images remain in the background of the text. */
pixs = pixRead("wyom.jpg");
pixt = pixScaleToSize(pixs, 2528, 3300);
pixWrite("/tmp/regout/psio5.jpg", pixt, IFF_JFIF_JPEG);
pixDestroy(&pixs);
pixDestroy(&pixt);
convertJpegToPS("/tmp/regout/psio5.jpg", "/tmp/regout/psio5.ps",
"w", 0, 0, 300, 1.0, 1, 0);
convertFlateToPS("weasel8.240c.png", "/tmp/regout/psio5.ps",
//.........这里部分代码省略.........
开发者ID:xmarston,项目名称:BillRecognizer,代码行数:101,代码来源:psio_reg.c
示例12: identifyWatershedBasin
/*!
* identifyWatershedBasin()
*
* Input: wshed
* index (index of basin to be located)
* level (of basin at point at which the two basins met)
* &box (<return> bounding box of basin)
* &pixd (<return> pix of basin, cropped to its bounding box)
* Return: 0 if OK, 1 on error
*
* Notes:
* (1) This is a static function, so we assume pixlab, pixs and pixt
* exist and are the same size.
* (2) It selects all pixels that have the label @index in pixlab
* and that have a value in pixs that is less than @level.
* (3) It is used whenever two seeded basins meet (typically at a saddle),
* or when one seeded basin meets a 'filler'. All identified
* basins are saved as a watershed.
*/
static l_int32
identifyWatershedBasin(L_WSHED *wshed,
l_int32 index,
l_int32 level,
BOX **pbox,
PIX **ppixd) {
l_int32 imin, imax, jmin, jmax, minx, miny, maxx, maxy;
l_int32 bw, bh, i, j, w, h, x, y;
l_int32 *lut;
l_uint32 label, bval, lval;
void **lines8, **linelab32, **linet1;
BOX *box;
PIX *pixs, *pixt, *pixd;
L_QUEUE *lq;
PROCNAME("identifyWatershedBasin");
if (!pbox)
return ERROR_INT("&box not defined", procName, 1);
*pbox = NULL;
if (!ppixd)
return ERROR_INT("&pixd not defined", procName, 1);
*ppixd = NULL;
if (!wshed)
return ERROR_INT("wshed not defined", procName, 1);
/* Make a queue and an auxiliary stack */
lq = lqueueCreate(0);
lq->stack = lstackCreate(0);
pixs = wshed->pixs;
pixt = wshed->pixt;
lines8 = wshed->lines8;
linelab32 = wshed->linelab32;
linet1 = wshed->linet1;
lut = wshed->lut;
pixGetDimensions(pixs, &w, &h, NULL);
/* Prime the queue with the seed pixel for this watershed. */
minx = miny = 1000000;
maxx = maxy = 0;
ptaGetIPt(wshed->ptas, index, &x, &y);
pixSetPixel(pixt, x, y, 1);
pushNewPixel(lq, x, y, &minx, &maxx, &miny, &maxy);
if (wshed->debug) fprintf(stderr, "prime: (x,y) = (%d, %d)\n", x, y);
/* Each pixel in a spreading breadth-first search is inspected.
* It is accepted as part of this watershed, and pushed on
* the search queue, if:
* (1) It has a label value equal to @index
* (2) The pixel value is less than @level, the overflow
* height at which the two basins join.
* (3) It has not yet been seen in this search. */
while (lqueueGetCount(lq) > 0) {
popNewPixel(lq, &x, &y);
imin = L_MAX(0, y - 1);
imax = L_MIN(h - 1, y + 1);
jmin = L_MAX(0, x - 1);
jmax = L_MIN(w - 1, x + 1);
for (i = imin; i <= imax; i++) {
for (j = jmin; j <= jmax; j++) {
if (j == x && i == y) continue; /* parent */
label = GET_DATA_FOUR_BYTES(linelab32[i], j);
if (label == MAX_LABEL_VALUE || lut[label] != index) continue;
bval = GET_DATA_BIT(linet1[i], j);
if (bval == 1) continue; /* already seen */
lval = GET_DATA_BYTE(lines8[i], j);
if (lval >= level) continue; /* too high */
SET_DATA_BIT(linet1[i], j);
pushNewPixel(lq, j, i, &minx, &maxx, &miny, &maxy);
}
}
}
/* Extract the box and pix, and clear pixt */
bw = maxx - minx + 1;
bh = maxy - miny + 1;
box = boxCreate(minx, miny, bw, bh);
pixd = pixClipRectangle(pixt, box, NULL);
pixRasterop(pixt, minx, miny, bw, bh, PIX_SRC ^ PIX_DST, pixd, 0, 0);
*pbox = box;
//.........这里部分代码省略.........
开发者ID:mehulsbhatt,项目名称:MyOCRTEST,代码行数:101,代码来源:watershed.c
示例13: wshedApply
//.........这里部分代码省略.........
nboth = nseeds + nother;
arraysize = 2 * nboth;
wshed->arraysize = arraysize;
nalut = numaMakeSequence(0, 1, arraysize);
lut = numaGetIArray(nalut);
wshed->lut = lut; /* wshed owns this */
links = (NUMA **) CALLOC(arraysize, sizeof(NUMA * ));
wshed->links = links; /* wshed owns this */
nindex = nseeds + nother; /* the next unused index value */
/* ------------------------------------------------------------ *
* Fill the basins, using the priority queue *
* ------------------------------------------------------------ */
pixad = pixaCreate(nseeds);
wshed->pixad = pixad; /* wshed owns this */
nalevels = numaCreate(nseeds);
wshed->nalevels = nalevels; /* wshed owns this */
L_INFO("nseeds = %d, nother = %d\n", procName, nseeds, nother);
while (lheapGetCount(lh) > 0) {
popWSPixel(lh, rstack, &val, &x, &y, &index);
/* fprintf(stderr, "x = %d, y = %d, index = %d\n", x, y, index); */
ulabel = GET_DATA_FOUR_BYTES(linelab32[y], x);
if (ulabel == MAX_LABEL_VALUE)
clabel = ulabel;
else
clabel = lut[ulabel];
cindex = lut[index];
if (clabel == cindex) continue; /* have already seen this one */
if (clabel == MAX_LABEL_VALUE) { /* new one; assign index and try to
* propagate to all neighbors */
SET_DATA_FOUR_BYTES(linelab32[y], x, cindex);
imin = L_MAX(0, y - 1);
imax = L_MIN(h - 1, y + 1);
jmin = L_MAX(0, x - 1);
jmax = L_MIN(w - 1, x + 1);
for (i = imin; i <= imax; i++) {
for (j = jmin; j <= jmax; j++) {
if (i == y && j == x) continue;
uval = GET_DATA_BYTE(lines8[i], j);
pushWSPixel(lh, rstack, (l_int32) uval, j, i, cindex);
}
}
} else { /* pixel is already labeled (differently); must resolve */
/* If both indices are seeds, check if the min height is
* greater than mindepth. If so, we have two new watersheds;
* locate them and assign to both regions a new index
* for further waterfill. If not, absorb the shallower
* watershed into the deeper one and continue filling it. */
pixGetPixel(pixsd, x, y, &uval);
if (clabel < nseeds && cindex < nseeds) {
wshedGetHeight(wshed, val, clabel, &hlabel);
wshedGetHeight(wshed, val, cindex, &hindex);
hmin = L_MIN(hlabel, hindex);
hmax = L_MAX(hlabel, hindex);
if (hmin == hmax) {
hmin = hlabel;
hmax = hindex;
}
if (wshed->debug) {
fprintf(stderr, "clabel,hlabel = %d,%d\n", clabel, hlabel);
fprintf(stderr, "hmin = %d, hmax = %d\n", hmin, hmax);
fprintf(stderr, "cindex,hindex = %d,%d\n", cindex, hindex);
if (hmin < mindepth)
fprintf(stderr, "Too shallow!\n");
开发者ID:mehulsbhatt,项目名称:MyOCRTEST,代码行数:67,代码来源:watershed.c
示例14: pixErodeGray3v
/*!
* pixErodeGray3v()
*
* Input: pixs (8 bpp, not cmapped)
* Return: pixd, or null on error
*
* Notes:
* (1) Special case for vertical 1x3 brick Sel;
* also used as the second step for the 3x3 brick Sel.
* (2) Surprisingly, this is faster than setting up the
* lineptrs array and accessing into it; e.g.,
* val4 = GET_DATA_BYTE(lines8[i + 3], j);
*/
static PIX *
pixErodeGray3v(PIX *pixs)
{
l_uint32 *datas, *datad, *linesi, *linedi;
l_int32 w, h, wpl, i, j;
l_int32 val0, val1, val2, val3, val4, val5, val6, val7, val8, val9, minval;
PIX *pixd;
PROCNAME("pixErodeGray3v");
if (!pixs)
return (PIX *)ERROR_PTR("pixs not defined", procName, NULL);
if (pixGetDepth(pixs) != 8)
return (PIX *)ERROR_PTR("pixs not 8 bpp", procName, NULL);
pixd = pixCreateTemplateNoInit(pixs);
pixGetDimensions(pixs, &w, &h, NULL);
datas = pixGetData(pixs);
datad = pixGetData(pixd);
wpl = pixGetWpl(pixs);
for (j = 0; j < w; j++) {
for (i = 1; i < h - 8; i += 8) {
linesi = datas + i * wpl;
linedi = datad + i * wpl;
val0 = GET_DATA_BYTE(linesi - wpl, j);
val1 = GET_DATA_BYTE(linesi, j);
val2 = GET_DATA_BYTE(linesi + wpl, j);
val3 = GET_DATA_BYTE(linesi + 2 * wpl, j);
val4 = GET_DATA_BYTE(linesi + 3 * wpl, j);
val5 = GET_DATA_BYTE(linesi + 4 * wpl, j);
val6 = GET_DATA_BYTE(linesi + 5 * wpl, j);
val7 = GET_DATA_BYTE(linesi + 6 * wpl, j);
val8 = GET_DATA_BYTE(linesi + 7 * wpl, j);
val9 = GET_DATA_BYTE(linesi + 8 * wpl, j);
minval = L_MIN(val1, val2);
SET_DATA_BYTE(linedi, j, L_MIN(val0, minval));
SET_DATA_BYTE(linedi + wpl, j, L_MIN(minval, val3));
minval = L_MIN(val3, val4);
SET_DATA_BYTE(linedi + 2 * wpl, j, L_MIN(val2, minval));
SET_DATA_BYTE(linedi + 3 * wpl, j, L_MIN(minval, val5));
minval = L_MIN(val5, val6);
SET_DATA_BYTE(linedi + 4 * wpl, j, L_MIN(val4, minval));
SET_DATA_BYTE(linedi + 5 * wpl, j, L_MIN(minval, val7));
minval = L_MIN(val7, val8);
SET_DATA_BYTE(linedi + 6 * wpl, j, L_MIN(val6, minval));
SET_DATA_BYTE(linedi + 7 * wpl, j, L_MIN(minval, val9));
}
}
return pixd;
}
开发者ID:ansgri,项目名称:rsdt-students,代码行数:63,代码来源:graymorph.c
|
请发表评论