本文整理汇总了C++中pixThresholdToBinary函数的典型用法代码示例。如果您正苦于以下问题:C++ pixThresholdToBinary函数的具体用法?C++ pixThresholdToBinary怎么用?C++ pixThresholdToBinary使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了pixThresholdToBinary函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddTestSet
void
AddTestSet(PIXA *pixa,
PIX *pixs,
l_int32 filtertype,
l_int32 edgethresh,
l_int32 smoothx,
l_int32 smoothy,
l_float32 gamma,
l_int32 minval,
l_int32 maxval,
l_int32 targetthresh)
{
PIX *pixb, *pixd, *pixth;
pixThresholdSpreadNorm(pixs, filtertype, edgethresh,
smoothx, smoothy, gamma, minval,
maxval, targetthresh, &pixth, NULL, &pixd);
pixSaveTiled(pixth, pixa, 1.0, 1, 20, 0);
pixSaveTiled(pixd, pixa, 1.0, 0, 20, 0);
pixb = pixThresholdToBinary(pixd, targetthresh - 20);
pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0);
pixDestroy(&pixb);
pixb = pixThresholdToBinary(pixd, targetthresh);
pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0);
pixDestroy(&pixb);
pixb = pixThresholdToBinary(pixd, targetthresh + 20);
pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0);
pixDestroy(&pixb);
pixb = pixThresholdToBinary(pixd, targetthresh + 40);
pixSaveTiled(pixb, pixa, 1.0, 0, 20, 0);
pixDestroy(&pixb);
pixDestroy(&pixth);
pixDestroy(&pixd);
return;
}
示例2: main
main(int argc,
char **argv)
{
l_int32 i, w, h, d;
l_float32 time;
PIX *pixs, *pixf, *pixd;
PIXA *pixa;
char *filein, *fileout;
static char mainName[] = "edgetest";
if (argc != 3)
exit(ERROR_INT(" Syntax: edgetest filein fileout", mainName, 1));
filein = argv[1];
fileout = argv[2];
if ((pixs = pixRead(filein)) == NULL)
exit(ERROR_INT("pix not made", mainName, 1));
pixGetDimensions(pixs, &w, &h, &d);
if (d != 8)
exit(ERROR_INT("pix not 8 bpp", mainName, 1));
/* Speed: about 12 Mpix/GHz/sec */
startTimer();
pixf = pixSobelEdgeFilter(pixs, L_HORIZONTAL_EDGES);
pixd = pixThresholdToBinary(pixf, 60);
pixInvert(pixd, pixd);
time = stopTimer();
fprintf(stderr, "Time = %7.3f sec\n", time);
fprintf(stderr, "MPix/sec: %7.3f\n", 0.000001 * w * h / time);
pixDisplay(pixs, 0, 0);
pixInvert(pixf, pixf);
pixDisplay(pixf, 480, 0);
pixDisplay(pixd, 960, 0);
pixWrite(fileout, pixf, IFF_PNG);
pixDestroy(&pixd);
/* Threshold at different values */
pixInvert(pixf, pixf);
for (i = 10; i <= 120; i += 10) {
pixd = pixThresholdToBinary(pixf, i);
pixInvert(pixd, pixd);
pixDisplayWrite(pixd, 1);
pixDestroy(&pixd);
}
pixDestroy(&pixf);
/* Display tiled */
pixa = pixaReadFiles("/tmp", "junk_write_display");
pixd = pixaDisplayTiledAndScaled(pixa, 8, 400, 3, 0, 25, 2);
pixWrite("/tmp/junktiles.jpg", pixd, IFF_JFIF_JPEG);
pixDestroy(&pixd);
pixaDestroy(&pixa);
pixDestroy(&pixs);
exit(0);
}
示例3: main
l_int32 main(int argc,
char **argv)
{
l_int32 pageno;
L_DEWARP *dew1;
L_DEWARPA *dewa;
PIX *pixs, *pixn, *pixg, *pixb;
static char mainName[] = "dewarptest2";
if (argc != 1 && argc != 3)
return ERROR_INT("Syntax: dewarptest2 [image pageno]", mainName, 1);
if (argc == 1) {
pixs = pixRead("cat-35.jpg");
pageno = 35;
}
else {
pixs = pixRead(argv[1]);
pageno = atoi(argv[2]);
}
if (!pixs)
return ERROR_INT("image not read", mainName, 1);
dewa = dewarpaCreate(40, 30, 1, 6, 50);
#if NORMALIZE
/* Normalize for varying background and binarize */
pixn = pixBackgroundNormSimple(pixs, NULL, NULL);
pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2);
pixb = pixThresholdToBinary(pixg, 130);
pixDestroy(&pixn);
#else
/* Don't normalize; just threshold and clean edges */
pixg = pixConvertTo8(pixs, 0);
pixb = pixThresholdToBinary(pixg, 100);
pixSetOrClearBorder(pixb, 30, 30, 40, 40, PIX_CLR);
#endif
/* Run the basic functions */
dew1 = dewarpCreate(pixb, pageno);
dewarpaInsertDewarp(dewa, dew1);
dewarpBuildModel(dew1, "/tmp/dewarp_model1.pdf");
dewarpaApplyDisparity(dewa, pageno, pixg, "/tmp/dewarp_apply1.pdf");
dewarpaDestroy(&dewa);
pixDestroy(&pixs);
pixDestroy(&pixg);
pixDestroy(&pixb);
return 0;
}
示例4: Java_com_googlecode_leptonica_android_GrayQuant_nativePixThresholdToBinary
jlong Java_com_googlecode_leptonica_android_GrayQuant_nativePixThresholdToBinary(JNIEnv *env, jclass clazz,
jlong nativePix, jint thresh) {
PIX *pixs = (PIX *) nativePix;
PIX *pixd = pixThresholdToBinary(pixs, (l_int32) thresh);
return (jlong) pixd;
}
示例5: dfprintf
/* load PNG, TIFF, JPG, GIF or BMP to PIX datastructure. The actual supported
* formats depends on how the leptonica was compiled */
PIX *loadimage(char *filename){
PIX *pix, *pixt;
int format, bpp;
format=fileformat(filename);
// In later versions of leptonica you will have to do this
// pixReadHeader(filename, format,NULL,NULL,NULL,bpp,NULL);
if(format!=IFF_PNG && format!=IFF_JFIF_JPEG && format!=IFF_TIFF && format!=
IFF_GIF && format!=7 && format!=8){
dfprintf(stderr,"Not recognised file format %i", format);
return NULL;
}
if ((pix = pixRead(filename)) == NULL) return NULL;
/* TODO: convert image to 1-bpp 300dpi regardless of scan */
bpp=pixGetDepth(pix);
if(bpp>1){
/*
printf("Bits per pixel=%i",bpp);
exit(1); */
//pixThresholdForFgBg(pix,5,100,NULL,NULL);
//pixContrastTRC(pix, pix, 1000);
pixt = pixContrastNorm(NULL, pix, 10, 10, 40, 2, 2);
pixDestroy(&pix);
pix = pixGammaTRC(NULL, pixt, 1.5, 50, 235);
pixt=pixThresholdToBinary(pix, 200);
//pixt=pixThreshold8(pix,1,1,0);
pixDestroy(&pix);
pix=pixt;
}
return pix;
}
示例6: pixRotateBinaryNice
/*!
* pixRotateBinaryNice()
*
* Input: pixs (1 bpp)
* angle (radians; clockwise is positive; about the center)
* incolor (L_BRING_IN_WHITE, L_BRING_IN_BLACK)
* Return: pixd, or null on error
*
* Notes:
* (1) For very small rotations, just return a clone.
* (2) This does a computationally expensive rotation of 1 bpp images.
* The fastest rotators (using shears or subsampling) leave
* visible horizontal and vertical shear lines across which
* the image shear changes by one pixel. To ameliorate the
* visual effect one can introduce random dithering. One
* way to do this in a not-too-random fashion is given here.
* We convert to 8 bpp, do a very small blur, rotate using
* linear interpolation (same as area mapping), do a
* small amount of sharpening to compensate for the initial
* blur, and threshold back to binary. The shear lines
* are magically removed.
* (3) This operation is about 5x slower than rotation by sampling.
*/
PIX *
pixRotateBinaryNice(PIX *pixs,
l_float32 angle,
l_int32 incolor)
{
PIX *pixt1, *pixt2, *pixt3, *pixt4, *pixd;
PROCNAME("pixRotateBinaryNice");
if (!pixs || pixGetDepth(pixs) != 1)
return (PIX *)ERROR_PTR("pixs undefined or not 1 bpp", procName, NULL);
if (incolor != L_BRING_IN_WHITE && incolor != L_BRING_IN_BLACK)
return (PIX *)ERROR_PTR("invalid incolor", procName, NULL);
pixt1 = pixConvertTo8(pixs, 0);
pixt2 = pixBlockconv(pixt1, 1, 1); /* smallest blur allowed */
pixt3 = pixRotateAM(pixt2, angle, incolor);
pixt4 = pixUnsharpMasking(pixt3, 1, 1.0); /* sharpen a bit */
pixd = pixThresholdToBinary(pixt4, 128);
pixDestroy(&pixt1);
pixDestroy(&pixt2);
pixDestroy(&pixt3);
pixDestroy(&pixt4);
return pixd;
}
示例7: main
main(int argc,
char **argv)
{
char *infile, *outfile;
l_int32 d;
PIX *pixs, *pixgr, *pixb;
static char mainName[] = "showedges";
if (argc != 3)
exit(ERROR_INT(" Syntax: showedges infile outfile", mainName, 1));
infile = argv[1];
outfile = argv[2];
pixs = pixRead(infile);
d = pixGetDepth(pixs);
if (d != 8 && d != 32)
exit(ERROR_INT("d not 8 or 32 bpp", mainName, 1));
pixgr = pixHalfEdgeByBandpass(pixs, SMOOTH_WIDTH_1, SMOOTH_WIDTH_1,
SMOOTH_WIDTH_2, SMOOTH_WIDTH_2);
pixb = pixThresholdToBinary(pixgr, THRESHOLD);
pixInvert(pixb, pixb);
/* pixWrite("junkpixgr", pixgr, IFF_JFIF_JPEG); */
pixWrite(outfile, pixb, IFF_PNG);
return 0;
}
示例8: dewarpSinglePageInit
/*!
* dewarpSinglePageInit()
*
* Input: pixs (with text, any depth)
* thresh (for global thresholding to 1 bpp; ignored otherwise)
* adaptive (1 for adaptive thresholding; 0 for global threshold)
* use_both (1 for horizontal and vertical; 0 for vertical only)
* &pixb (<return> 1 bpp image)
* &dewa (<return> initialized dewa)
* Return: 0 if OK, 1 on error (list of page numbers), or null on error
*
* Notes:
* (1) This binarizes the input pixs if necessary, returning the
* binarized image. It also initializes the dewa to default values
* for the model parameters.
* (2) If pixs is 1 bpp, the parameters @adaptive and @thresh are ignored.
* (3) To change the model parameters, call dewarpaSetCurvatures()
* before running dewarpSinglePageRun(). For DC:
* dewarpSinglePageInit(pixs, 0, 1, 1, &pixb, &dewa);
* dewarpaSetCurvatures(dewa, 250, -1, -1, 80, 70, 150);
* dewarpSinglePageRun(pixs, pixb, dewa, &pixd, 0);
* dewarpaDestroy(&dewa);
* pixDestroy(&pixb);
*/
l_int32
dewarpSinglePageInit(PIX *pixs,
l_int32 thresh,
l_int32 adaptive,
l_int32 use_both,
PIX **ppixb,
L_DEWARPA **pdewa)
{
PIX *pix1;
PROCNAME("dewarpSinglePageInit");
if (ppixb) *ppixb = NULL;
if (pdewa) *pdewa = NULL;
if (!ppixb || !pdewa)
return ERROR_INT("&pixb and &dewa not both defined", procName, 1);
if (!pixs)
return ERROR_INT("pixs not defined", procName, 1);
*pdewa = dewarpaCreate(1, 0, 1, 0, -1);
dewarpaUseBothArrays(*pdewa, use_both);
/* Generate a binary image, if necessary */
if (pixGetDepth(pixs) > 1) {
pix1 = pixConvertTo8(pixs, 0);
if (adaptive)
*ppixb = pixAdaptThresholdToBinary(pix1, NULL, 1.0);
else
*ppixb = pixThresholdToBinary(pix1, thresh);
pixDestroy(&pix1);
} else {
*ppixb = pixClone(pixs);
}
return 0;
}
示例9: Pix
// threshold the image -- warning, operates ONLY on grayscale pixmaps
// original image is unchanged - a new modified image at raster's end
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Pix Pix::ThresholdToBinary(int threshold)
{
if(IsEmpty())
return Pix();
PIX *dPix = pixThresholdToBinary(pix, threshold);
if(!dPix)
return Pix();
return Pix(&dPix);
} // END Pix::ThresholdToBinary()
示例10: Java_com_googlecode_leptonica_android_Dewarp_nativeDewarp
jint Java_com_googlecode_leptonica_android_Dewarp_nativeDewarp(JNIEnv *env, jclass clazz, jint nativePix) {
LOGV("%s",__FUNCTION__);
PIX* pixd=NULL;
PIX *pixs = (PIX *) nativePix;
PIX* pixb = pixThresholdToBinary(pixs, 130);
// Basic functioning:
L_Dewarp *dew = dewarpCreate(pixb,0,60,5,1);
int buildresult=dewarpBuildModel(dew, 0);
if(buildresult==0){
int applyresult=dewarpApplyDisparity(dew, pixs, 0);
if(applyresult==0){
pixd = pixClone(dew->pixd);
}
}
pixDestroy(&pixb);
dewarpDestroy(&dew);
if(pixd!=NULL){
return (jint) pixd;
} else {
return (jint) 0;
}
}
示例11: _process_frame_tickertext
char* _process_frame_tickertext(struct lib_hardsubx_ctx *ctx, AVFrame *frame, int width, int height, int index)
{
PIX *im;
PIX *edge_im;
PIX *lum_im;
PIX *feat_im;
char *subtitle_text=NULL;
im = pixCreate(width,height,32);
lum_im = pixCreate(width,height,32);
feat_im = pixCreate(width,height,32);
int i,j;
for(i=(92*height)/100;i<height;i++)
{
for(j=0;j<width;j++)
{
int p=j*3+i*frame->linesize[0];
int r=frame->data[0][p];
int g=frame->data[0][p+1];
int b=frame->data[0][p+2];
pixSetRGBPixel(im,j,i,r,g,b);
float L,A,B;
rgb_to_lab((float)r,(float)g,(float)b,&L,&A,&B);
if(L > ctx->lum_thresh)
pixSetRGBPixel(lum_im,j,i,255,255,255);
else
pixSetRGBPixel(lum_im,j,i,0,0,0);
}
}
//Handle the edge image
edge_im = pixCreate(width,height,8);
edge_im = pixConvertRGBToGray(im,0.0,0.0,0.0);
edge_im = pixSobelEdgeFilter(edge_im, L_VERTICAL_EDGES);
edge_im = pixDilateGray(edge_im, 21, 11);
edge_im = pixThresholdToBinary(edge_im,50);
for(i=92*(height/100);i<height;i++)
{
for(j=0;j<width;j++)
{
unsigned int p1,p2,p3;
pixGetPixel(edge_im,j,i,&p1);
// pixGetPixel(pixd,j,i,&p2);
pixGetPixel(lum_im,j,i,&p3);
if(p1==0&&p3>0)
pixSetRGBPixel(feat_im,j,i,255,255,255);
else
pixSetRGBPixel(feat_im,j,i,0,0,0);
}
}
// Tesseract OCR for the ticker text here
subtitle_text = get_ocr_text_simple(ctx, lum_im);
char write_path[100];
sprintf(write_path,"./lum_im%04d.jpg",index);
pixWrite(write_path,lum_im,IFF_JFIF_JPEG);
sprintf(write_path,"./im%04d.jpg",index);
pixWrite(write_path,im,IFF_JFIF_JPEG);
pixDestroy(&lum_im);
pixDestroy(&im);
pixDestroy(&edge_im);
pixDestroy(&feat_im);
return subtitle_text;
}
示例12: _display_frame
void _display_frame(struct lib_hardsubx_ctx *ctx, AVFrame *frame, int width, int height, int timestamp)
{
// Debug: Display the frame after processing
PIX *im;
im = pixCreate(width,height,32);
PIX *hue_im = pixCreate(width,height,32);
int i,j;
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
int p=j*3+i*frame->linesize[0];
int r=frame->data[0][p];
int g=frame->data[0][p+1];
int b=frame->data[0][p+2];
pixSetRGBPixel(im,j,i,r,g,b);
float H,S,V;
rgb_to_hsv((float)r,(float)g,(float)b,&H,&S,&V);
if(abs(H-ctx->hue)<20)
{
pixSetRGBPixel(hue_im,j,i,r,g,b);
}
}
}
PIX *edge_im = pixCreate(width,height,8),*edge_im_2 = pixCreate(width,height,8);
edge_im = pixConvertRGBToGray(im,0.0,0.0,0.0);
edge_im = pixSobelEdgeFilter(edge_im, L_VERTICAL_EDGES);
edge_im = pixDilateGray(edge_im, 21, 1);
edge_im = pixThresholdToBinary(edge_im,50);
PIX *pixd = pixCreate(width,height,1);
pixSauvolaBinarize(pixConvertRGBToGray(hue_im,0.0,0.0,0.0), 15, 0.3, 1, NULL, NULL, NULL, &pixd);
edge_im_2 = pixConvertRGBToGray(hue_im,0.0,0.0,0.0);
edge_im_2 = pixDilateGray(edge_im_2, 5, 5);
PIX *feat_im = pixCreate(width,height,32);
for(i=3*(height/4);i<height;i++)
{
for(j=0;j<width;j++)
{
unsigned int p1,p2,p3,p4;
pixGetPixel(edge_im,j,i,&p1);
pixGetPixel(pixd,j,i,&p2);
// pixGetPixel(hue_im,j,i,&p3);
pixGetPixel(edge_im_2,j,i,&p4);
if(p1==0&&p2==0&&p4>0)//if(p4>0&&p1==0)//if(p2==0&&p1==0&&p3>0)
{
pixSetRGBPixel(feat_im,j,i,255,255,255);
}
}
}
char *txt=NULL;
// txt = get_ocr_text_simple(ctx, feat_im);
// txt=get_ocr_text_wordwise_threshold(ctx, feat_im, ctx->conf_thresh);
// if(txt != NULL)printf("%s\n", txt);
pixDestroy(&im);
pixDestroy(&edge_im);
pixDestroy(&feat_im);
pixDestroy(&edge_im_2);
pixDestroy(&pixd);
}
示例13: _process_frame_white_basic
char* _process_frame_white_basic(struct lib_hardsubx_ctx *ctx, AVFrame *frame, int width, int height, int index)
{
//printf("frame : %04d\n", index);
PIX *im;
PIX *edge_im;
PIX *lum_im;
PIX *feat_im;
char *subtitle_text=NULL;
im = pixCreate(width,height,32);
lum_im = pixCreate(width,height,32);
feat_im = pixCreate(width,height,32);
int i,j;
for(i=(3*height)/4;i<height;i++)
{
for(j=0;j<width;j++)
{
int p=j*3+i*frame->linesize[0];
int r=frame->data[0][p];
int g=frame->data[0][p+1];
int b=frame->data[0][p+2];
pixSetRGBPixel(im,j,i,r,g,b);
float L,A,B;
rgb_to_lab((float)r,(float)g,(float)b,&L,&A,&B);
if(L > ctx->lum_thresh)
pixSetRGBPixel(lum_im,j,i,255,255,255);
else
pixSetRGBPixel(lum_im,j,i,0,0,0);
}
}
//Handle the edge image
edge_im = pixCreate(width,height,8);
edge_im = pixConvertRGBToGray(im,0.0,0.0,0.0);
edge_im = pixSobelEdgeFilter(edge_im, L_VERTICAL_EDGES);
edge_im = pixDilateGray(edge_im, 21, 11);
edge_im = pixThresholdToBinary(edge_im,50);
for(i=3*(height/4);i<height;i++)
{
for(j=0;j<width;j++)
{
unsigned int p1,p2,p3;
pixGetPixel(edge_im,j,i,&p1);
// pixGetPixel(pixd,j,i,&p2);
pixGetPixel(lum_im,j,i,&p3);
if(p1==0&&p3>0)
pixSetRGBPixel(feat_im,j,i,255,255,255);
else
pixSetRGBPixel(feat_im,j,i,0,0,0);
}
}
if(ctx->detect_italics)
{
ctx->ocr_mode = HARDSUBX_OCRMODE_WORD;
}
// TESSERACT OCR FOR THE FRAME HERE
switch(ctx->ocr_mode)
{
case HARDSUBX_OCRMODE_WORD:
if(ctx->conf_thresh > 0)
subtitle_text = get_ocr_text_wordwise_threshold(ctx, lum_im, ctx->conf_thresh);
else
subtitle_text = get_ocr_text_wordwise(ctx, lum_im);
break;
case HARDSUBX_OCRMODE_LETTER:
if(ctx->conf_thresh > 0)
subtitle_text = get_ocr_text_letterwise_threshold(ctx, lum_im, ctx->conf_thresh);
else
subtitle_text = get_ocr_text_letterwise(ctx, lum_im);
break;
case HARDSUBX_OCRMODE_FRAME:
if(ctx->conf_thresh > 0)
subtitle_text = get_ocr_text_simple_threshold(ctx, lum_im, ctx->conf_thresh);
else
subtitle_text = get_ocr_text_simple(ctx, lum_im);
break;
default:
fatal(EXIT_MALFORMED_PARAMETER,"Invalid OCR Mode");
}
pixDestroy(&lum_im);
pixDestroy(&im);
pixDestroy(&edge_im);
pixDestroy(&feat_im);
return subtitle_text;
}
示例14: main
l_int32 main(int argc,
char **argv) {
l_int32 i, n;
l_float32 a, b, c, d, e;
NUMA *nax, *nafit;
PIX *pixs, *pixn, *pixg, *pixb, *pixt1, *pixt2;
PIXA *pixa;
PTA *pta, *ptad;
PTAA *ptaa1, *ptaa2;
pixs = pixRead("cat-35.jpg");
/* pixs = pixRead("zanotti-78.jpg"); */
/* Normalize for varying background and binarize */
pixn = pixBackgroundNormSimple(pixs, NULL, NULL);
pixg = pixConvertRGBToGray(pixn, 0.5, 0.3, 0.2);
pixb = pixThresholdToBinary(pixg, 130);
pixDestroy(&pixn);
pixDestroy(&pixg);
/* Get the textline centers */
pixa = pixaCreate(6);
ptaa1 = dewarpGetTextlineCenters(pixb, 0);
pixt1 = pixCreateTemplate(pixs);
pixSetAll(pixt1);
pixt2 = pixDisplayPtaa(pixt1, ptaa1);
pixWrite("/tmp/textline1.png", pixt2, IFF_PNG);
pixDisplayWithTitle(pixt2, 0, 100, "textline centers 1", 1);
pixaAddPix(pixa, pixt2, L_INSERT);
pixDestroy(&pixt1);
/* Remove short lines */
fprintf(stderr, "Num all lines = %d\n", ptaaGetCount(ptaa1));
ptaa2 = dewarpRemoveShortLines(pixb, ptaa1, 0.8, 0);
pixt1 = pixCreateTemplate(pixs);
pixSetAll(pixt1);
pixt2 = pixDisplayPtaa(pixt1, ptaa2);
pixWrite("/tmp/textline2.png", pixt2, IFF_PNG);
pixDisplayWithTitle(pixt2, 300, 100, "textline centers 2", 1);
pixaAddPix(pixa, pixt2, L_INSERT);
pixDestroy(&pixt1);
n = ptaaGetCount(ptaa2);
fprintf(stderr, "Num long lines = %d\n", n);
ptaaDestroy(&ptaa1);
pixDestroy(&pixb);
/* Long lines over input image */
pixt1 = pixCopy(NULL, pixs);
pixt2 = pixDisplayPtaa(pixt1, ptaa2);
pixWrite("/tmp/textline3.png", pixt2, IFF_PNG);
pixDisplayWithTitle(pixt2, 600, 100, "textline centers 3", 1);
pixaAddPix(pixa, pixt2, L_INSERT);
pixDestroy(&pixt1);
/* Quadratic fit to curve */
pixt1 = pixCopy(NULL, pixs);
for (i = 0; i < n; i++) {
pta = ptaaGetPta(ptaa2, i, L_CLONE);
ptaGetArrays(pta, &nax, NULL);
ptaGetQuadraticLSF(pta, &a, &b, &c, &nafit);
fprintf(stderr, "Quadratic: a = %10.6f, b = %7.3f, c = %7.3f\n",
a, b, c);
ptad = ptaCreateFromNuma(nax, nafit);
pixDisplayPta(pixt1, pixt1, ptad);
ptaDestroy(&pta);
ptaDestroy(&ptad);
numaDestroy(&nax);
numaDestroy(&nafit);
}
pixWrite("/tmp/textline4.png", pixt1, IFF_PNG);
pixDisplayWithTitle(pixt1, 900, 100, "textline centers 4", 1);
pixaAddPix(pixa, pixt1, L_INSERT);
/* Cubic fit to curve */
pixt1 = pixCopy(NULL, pixs);
for (i = 0; i < n; i++) {
pta = ptaaGetPta(ptaa2, i, L_CLONE);
ptaGetArrays(pta, &nax, NULL);
ptaGetCubicLSF(pta, &a, &b, &c, &d, &nafit);
fprintf(stderr, "Cubic: a = %10.6f, b = %10.6f, c = %7.3f, d = %7.3f\n",
a, b, c, d);
ptad = ptaCreateFromNuma(nax, nafit);
pixDisplayPta(pixt1, pixt1, ptad);
ptaDestroy(&pta);
ptaDestroy(&ptad);
numaDestroy(&nax);
numaDestroy(&nafit);
}
pixWrite("/tmp/textline5.png", pixt1, IFF_PNG);
pixDisplayWithTitle(pixt1, 1200, 100, "textline centers 5", 1);
pixaAddPix(pixa, pixt1, L_INSERT);
/* Quartic fit to curve */
pixt1 = pixCopy(NULL, pixs);
for (i = 0; i < n; i++) {
pta = ptaaGetPta(ptaa2, i, L_CLONE);
ptaGetArrays(pta, &nax, NULL);
ptaGetQuarticLSF(pta, &a, &b, &c, &d, &e, &nafit);
fprintf(stderr,
"Quartic: a = %7.3f, b = %7.3f, c = %9.5f, d = %7.3f, e = %7.3f\n",
//.........这里部分代码省略.........
示例15: main
int main(int argc,
char **argv) {
char *infile;
l_int32 w, d, threshval, ival, newval;
l_uint32 val;
PIX *pixs, *pixg, *pixg2;
PIX *pix1, *pix2;
PIXA *pixa;
static char mainName[] = "binarize_set";
if (argc != 2)
return ERROR_INT(" Syntax: binarize_set infile", mainName, 1);
infile = argv[1];
pixa = pixaCreate(5);
pixs = pixRead(infile);
pixGetDimensions(pixs, &w, NULL, &d);
pixSaveTiled(pixs, pixa, 1.0, 1, 50, 32);
pixDisplay(pixs, 100, 0);
#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);
//.........这里部分代码省略.........