Browse Source

New functions for more versatility with gplot.

* Allow various types of input and output with one-line calls
* New gplotMakeOutputPix() is a wrapper for gplotMakeOutput()
  that returns a pix of the plot.
* New simple set of functions that returns the plot, without
  specifying any file names generated by gplot.  Examples are
     gplotSimplePix1(), gplotSimplePix2(), gplotSimplePixN()
* New more general one-liners, that let you specify everything
  except for the labels on individual plots and require the
  same plotstyle for all plots (e.g., GPLOT_LINES).
* The new functions are used in numa1_reg.c
* In gplot.h, rename field plottitle --> plotlabel.
* Also fixed some documentation for color measurement.
pull/468/head
Dan Bloomberg 6 years ago
parent
commit
d9fd6be542
  1. 13
      prog/blend2_reg.c
  2. 117
      prog/numa1_reg.c
  3. 10
      src/allheaders.h
  4. 3
      src/binarize.c
  5. 13
      src/boxfunc5.c
  6. 92
      src/colorcontent.c
  7. 290
      src/gplot.c
  8. 2
      src/gplot.h
  9. 22
      src/jbclass.c
  10. 3
      src/pix4.c

13
prog/blend2_reg.c

@ -33,6 +33,11 @@
#include "allheaders.h"
/* In case libpng is not enabled */
static const char fname_png[64] = "/tmp/lept/regout/blend2.14.png";
static const char fname_bmp[64] = "/tmp/lept/regout/blend2.14.bmp";
int main(int argc,
char **argv)
{
@ -146,8 +151,12 @@ L_REGPARAMS *rp;
regTestWritePixAndCheck(rp, pix4, IFF_JFIF_JPEG); /* 15 */
pixDestroy(&pix4);
/* Read the RGBA image back */
pix4 = pixRead("/tmp/lept/regout/blend2.14.png");
/* Read the RGBA image #14 back */
#if defined(HAVE_LIBPNG)
pix4 = pixRead(fname_png);
#else
pix4 = pixRead(fname_bmp);
#endif
/* Make sure that the alpha channel image hasn't changed */
pix5 = pixGetRGBComponent(pix4, L_ALPHA_CHANNEL);

117
prog/numa1_reg.c

@ -77,11 +77,8 @@ L_REGPARAMS *rp;
nahisto = numaMakeHistogramClipped(na, 6, 2000);
nbins = numaGetCount(nahisto);
nax = numaMakeSequence(0, 1, nbins);
gplot = gplotCreate("/tmp/lept/numa1/histo1", GPLOT_PNG, "example histo 1",
"i", "histo[i]");
gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix1 = gplotGeneralPix2(nax, nahisto, GPLOT_LINES, "/tmp/lept/numa1/histo1",
"example histo 1", "i", "histo[i]");
numaDestroy(&nax);
numaDestroy(&nahisto);
@ -89,11 +86,8 @@ L_REGPARAMS *rp;
nbins = numaGetCount(nahisto);
nax = numaMakeSequence(binstart, binsize, nbins);
fprintf(stderr, " binsize = %d, binstart = %d\n", binsize, binstart);
gplot = gplotCreate("/tmp/lept/numa1/histo2", GPLOT_PNG, "example histo 2",
"i", "histo[i]");
gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix2 = gplotGeneralPix2(nax, nahisto, GPLOT_LINES, "/tmp/lept/numa1/histo2",
"example histo 2", "i", "histo[i]");
numaDestroy(&nax);
numaDestroy(&nahisto);
@ -101,11 +95,8 @@ L_REGPARAMS *rp;
nbins = numaGetCount(nahisto);
nax = numaMakeSequence(0, binsize, nbins);
fprintf(stderr, " binsize = %d, binstart = %d\n", binsize, 0);
gplot = gplotCreate("/tmp/lept/numa1/histo3", GPLOT_PNG, "example histo 3",
"i", "histo[i]");
gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix3 = gplotGeneralPix2(nax, nahisto, GPLOT_LINES, "/tmp/lept/numa1/histo3",
"example histo 3", "i", "histo[i]");
numaDestroy(&nax);
numaDestroy(&nahisto);
@ -115,15 +106,8 @@ L_REGPARAMS *rp;
nax = numaMakeSequence(startval, fbinsize, nbins);
fprintf(stderr, " binsize = %7.4f, binstart = %8.3f\n",
fbinsize, startval);
gplot = gplotCreate("/tmp/lept/numa1/histo4", GPLOT_PNG, "example histo 4",
"i", "histo[i]");
gplotAddPlot(gplot, nax, nahisto, GPLOT_LINES, "sine");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix1 = pixRead("/tmp/lept/numa1/histo1.png");
pix2 = pixRead("/tmp/lept/numa1/histo2.png");
pix3 = pixRead("/tmp/lept/numa1/histo3.png");
pix4 = pixRead("/tmp/lept/numa1/histo4.png");
pix4 = gplotGeneralPix2(nax, nahisto, GPLOT_LINES, "/tmp/lept/numa1/histo4",
"example histo 4", "i", "histo[i]");
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 0 */
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 1 */
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 2 */
@ -174,15 +158,14 @@ L_REGPARAMS *rp;
pixs = pixRead("test8.jpg");
na = pixGetGrayHistogramMasked(pixs, NULL, 0, 0, 1);
nasy = numaGetPartialSums(na);
gplotSimple1(nasy, GPLOT_PNG, "/tmp/lept/numa1/int1", "partial sums");
gplotSimple1(na, GPLOT_PNG, "/tmp/lept/numa1/int2", "simple test");
pix1 = gplotGeneralPix1(nasy, GPLOT_LINES, "/tmp/lept/numa1/int1",
"partial sums", NULL, NULL);
pix2 = gplotGeneralPix1(na, GPLOT_LINES, "/tmp/lept/numa1/int2",
"simple test", NULL, NULL);
numaInterpolateEqxInterval(0.0, 1.0, na, L_LINEAR_INTERP,
0.0, 255.0, 15, &nax, &nay);
gplot = gplotCreate("/tmp/lept/numa1/int3", GPLOT_PNG, "test interpolation",
"pix val", "num pix");
gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "plot 1");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix3 = gplotGeneralPix2(nax, nay, GPLOT_LINES, "/tmp/lept/numa1/int3",
"test interpolation", "pix val", "num pix");
numaDestroy(&na);
numaDestroy(&nasy);
numaDestroy(&nax);
@ -197,11 +180,8 @@ L_REGPARAMS *rp;
nasx = numaMakeSequence(0.0, 1.0, 257);
numaInterpolateArbxInterval(nasx, nasy, L_LINEAR_INTERP,
10.0, 250.0, 23, &nax, &nay);
gplot = gplotCreate("/tmp/lept/numa1/int4", GPLOT_PNG, "arbx interpolation",
"pix val", "cum num pix");
gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "plot 1");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix4 = gplotGeneralPix2(nax, nay, GPLOT_LINES, "/tmp/lept/numa1/int4",
"arbx interpolation", "pix val", "cum num pix");
numaDestroy(&na);
numaDestroy(&nasx);
numaDestroy(&nasy);
@ -223,11 +203,8 @@ L_REGPARAMS *rp;
numaInterpolateArbxVal(nasx, nasy, L_QUADRATIC_INTERP, xval, &yval);
numaAddNumber(nay, yval);
}
gplot = gplotCreate("/tmp/lept/numa1/int5", GPLOT_PNG, "arbx interpolation",
"pix val", "cum num pix");
gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "plot 1");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix5 = gplotGeneralPix2(nax, nay, GPLOT_LINES, "/tmp/lept/numa1/int5",
"arbx interpolation", "pix val", "cum num pix");
numaDestroy(&na);
numaDestroy(&nasx);
numaDestroy(&nasy);
@ -250,25 +227,18 @@ L_REGPARAMS *rp;
gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "quadratic");
numaDestroy(&nax);
numaDestroy(&nay);
gplotMakeOutput(gplot);
pix6 = gplotMakeOutputPix(gplot);
gplotDestroy(&gplot);
gplot = gplotCreate("/tmp/lept/numa1/int7", GPLOT_PNG, "arbx interpolation",
"angle", "score");
numaInterpolateArbxInterval(nasx, nasy, L_LINEAR_INTERP,
-1.2, -0.8, 50, &nax, &nay);
gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "quadratic");
gplotMakeOutput(gplot);
pix7 = gplotMakeOutputPix(gplot);
gplotDestroy(&gplot);
numaFitMax(nay, &yval, nax, &xval);
if (rp->display) fprintf(stderr, "max = %f at loc = %f\n", yval, xval);
pixa = pixaCreate(7);
pix1 = pixRead("/tmp/lept/numa1/int1.png");
pix2 = pixRead("/tmp/lept/numa1/int2.png");
pix3 = pixRead("/tmp/lept/numa1/int3.png");
pix4 = pixRead("/tmp/lept/numa1/int4.png");
pix5 = pixRead("/tmp/lept/numa1/int5.png");
pix6 = pixRead("/tmp/lept/numa1/int6.png");
pix7 = pixRead("/tmp/lept/numa1/int7.png");
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 11 */
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 12 */
regTestWritePixAndCheck(rp, pix3, IFF_PNG); /* 13 */
@ -302,11 +272,8 @@ L_REGPARAMS *rp;
nasy = numaRead("testscore.na");
/* ---------- Plot the derivative ---------- */
numaDifferentiateInterval(nasx, nasy, -2.0, 0.0, 50, &nadx, &nady);
gplot = gplotCreate("/tmp/lept/numa1/diff1", GPLOT_PNG, "derivative",
"angle", "slope");
gplotAddPlot(gplot, nadx, nady, GPLOT_LINES, "derivative");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix1 = gplotGeneralPix2(nadx, nady, GPLOT_LINES, "/tmp/lept/numa1/diff1",
"derivative", "angle", "slope");
/* ---------- Plot the original function ----------- */
/* and the integral of the derivative; the two */
/* should be approximately the same. */
@ -329,11 +296,9 @@ L_REGPARAMS *rp;
numaAddNumber(nay, y0 + yval);
}
gplotAddPlot(gplot, nafx, nay, GPLOT_LINES, "anti-derivative");
gplotMakeOutput(gplot);
pix2 = gplotMakeOutputPix(gplot);
gplotDestroy(&gplot);
pixa = pixaCreate(2);
pix1 = pixRead("/tmp/lept/numa1/diff1.png");
pix2 = pixRead("/tmp/lept/numa1/diff2.png");
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 18 */
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 19 */
pixaAddPix(pixa, pix1, L_INSERT);
@ -359,11 +324,8 @@ L_REGPARAMS *rp;
pixs = pixRead("test8.jpg");
nasy= pixGetGrayHistogramMasked(pixs, NULL, 0, 0, 1);
numaMakeRankFromHistogram(0.0, 1.0, nasy, 350, &nax, &nay);
gplot = gplotCreate("/tmp/lept/numa1/rank1", GPLOT_PNG,
"test rank extractor", "pix val", "rank val");
gplotAddPlot(gplot, nax, nay, GPLOT_LINES, "plot 1");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix1 = gplotGeneralPix2(nax, nay, GPLOT_LINES, "/tmp/lept/numa1/rank1",
"test rank extractor", "pix val", "rank val");
numaDestroy(&nasy);
numaDestroy(&nax);
numaDestroy(&nay);
@ -378,10 +340,9 @@ L_REGPARAMS *rp;
numaHistogramGetValFromRank(na, rank, &val);
numaAddNumber(nap, val);
}
gplotSimple1(nap, GPLOT_PNG, "/tmp/lept/numa1/rank2", "rank value");
pix2 = gplotGeneralPix1(nap, GPLOT_LINES, "/tmp/lept/numa1/rank2",
"rank value", NULL, NULL);
pixa = pixaCreate(2);
pix1 = pixRead("/tmp/lept/numa1/rank1.png");
pix2 = pixRead("/tmp/lept/numa1/rank2.png");
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 20 */
regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 21 */
pixaAddPix(pixa, pix1, L_INSERT);
@ -400,21 +361,21 @@ L_REGPARAMS *rp;
* Numa-morphology *
* -------------------------------------------------------------------*/
na = numaRead("lyra.5.na");
gplotSimple1(na, GPLOT_PNG, "/tmp/lept/numa1/lyra1", "Original");
pix1 = gplotGeneralPix1(na, GPLOT_LINES, "/tmp/lept/numa1/lyra1",
"Original", NULL, NULL);
na1 = numaErode(na, 21);
gplotSimple1(na1, GPLOT_PNG, "/tmp/lept/numa1/lyra2", "Erosion");
pix2 = gplotGeneralPix1(na1, GPLOT_LINES, "/tmp/lept/numa1/lyra2",
"Erosion", NULL, NULL);
na2 = numaDilate(na, 21);
gplotSimple1(na2, GPLOT_PNG, "/tmp/lept/numa1/lyra3", "Dilation");
pix3 = gplotGeneralPix1(na2, GPLOT_LINES, "/tmp/lept/numa1/lyra3",
"Dilation", NULL, NULL);
na3 = numaOpen(na, 21);
gplotSimple1(na3, GPLOT_PNG, "/tmp/lept/numa1/lyra4", "Opening");
pix4 = gplotGeneralPix1(na3, GPLOT_LINES, "/tmp/lept/numa1/lyra4",
"Opening", NULL, NULL);
na4 = numaClose(na, 21);
gplotSimple1(na4, GPLOT_PNG, "/tmp/lept/numa1/lyra5", "Closing");
pix5 = gplotGeneralPix1(na4, GPLOT_LINES, "/tmp/lept/numa1/lyra5",
"Closing", NULL, NULL);
pixa = pixaCreate(2);
pix1 = pixRead("/tmp/lept/numa1/lyra1.png");
pix2 = pixRead("/tmp/lept/numa1/lyra2.png");
pix3 = pixRead("/tmp/lept/numa1/lyra3.png");
pix4 = pixRead("/tmp/lept/numa1/lyra4.png");
pix5 = pixRead("/tmp/lept/numa1/lyra5.png");
pixaAddPix(pixa, pix1, L_INSERT);
pixaAddPix(pixa, pix2, L_INSERT);
pixaAddPix(pixa, pix3, L_INSERT);
@ -453,9 +414,7 @@ L_REGPARAMS *rp;
snprintf(buf1, sizeof(buf1), "/tmp/lept/numa1/histoplot-%d", hw);
snprintf(buf2, sizeof(buf2), "halfwidth = %d, skip = 20, thresh = %d",
hw, thresh);
gplotSimple1(na3, GPLOT_PNG, buf1, buf2);
snprintf(buf1, sizeof(buf1), "/tmp/lept/numa1/histoplot-%d.png", hw);
pix1 = pixRead(buf1);
pix1 = gplotGeneralPix1(na3, GPLOT_LINES, buf1, buf2, NULL, NULL);
if (hw == 4 || hw == 20)
regTestWritePixAndCheck(rp, pix1, IFF_PNG); /* 27, 28 */
pixaAddPix(pixa, pix1, L_INSERT);

10
src/allheaders.h

@ -434,8 +434,8 @@ LEPT_DLL extern l_ok pixGetWordBoxesInTextlines ( PIX *pixs, l_int32 minwidth, l
LEPT_DLL extern l_ok pixFindWordAndCharacterBoxes ( PIX *pixs, BOX *boxs, l_int32 thresh, BOXA **pboxaw, BOXAA **pboxaac, const char *debugdir );
LEPT_DLL extern NUMAA * boxaExtractSortedPattern ( BOXA *boxa, NUMA *na );
LEPT_DLL extern l_ok numaaCompareImagesByBoxes ( NUMAA *naa1, NUMAA *naa2, l_int32 nperline, l_int32 nreq, l_int32 maxshiftx, l_int32 maxshifty, l_int32 delx, l_int32 dely, l_int32 *psame, l_int32 debugflag );
LEPT_DLL extern l_ok pixColorContent ( PIX *pixs, l_int32 rwhite, l_int32 gwhite, l_int32 bwhite, l_int32 mingray, PIX **ppixr, PIX **ppixg, PIX **ppixb );
LEPT_DLL extern PIX * pixColorMagnitude ( PIX *pixs, l_int32 rwhite, l_int32 gwhite, l_int32 bwhite, l_int32 type );
LEPT_DLL extern l_ok pixColorContent ( PIX *pixs, l_int32 rref, l_int32 gref, l_int32 bref, l_int32 mingray, PIX **ppixr, PIX **ppixg, PIX **ppixb );
LEPT_DLL extern PIX * pixColorMagnitude ( PIX *pixs, l_int32 rref, l_int32 gref, l_int32 bref, l_int32 type );
LEPT_DLL extern PIX * pixMaskOverColorPixels ( PIX *pixs, l_int32 threshdiff, l_int32 mindist );
LEPT_DLL extern PIX * pixMaskOverGrayPixels ( PIX *pixs, l_int32 maxlimit, l_int32 satlimit );
LEPT_DLL extern PIX * pixMaskOverColorRange ( PIX *pixs, l_int32 rmin, l_int32 rmax, l_int32 gmin, l_int32 gmax, l_int32 bmin, l_int32 bmax );
@ -936,8 +936,9 @@ LEPT_DLL extern l_ok pixWriteStreamGif ( FILE *fp, PIX *pix );
LEPT_DLL extern l_ok pixWriteMemGif ( l_uint8 **pdata, size_t *psize, PIX *pix );
LEPT_DLL extern GPLOT * gplotCreate ( const char *rootname, l_int32 outformat, const char *title, const char *xlabel, const char *ylabel );
LEPT_DLL extern void gplotDestroy ( GPLOT **pgplot );
LEPT_DLL extern l_ok gplotAddPlot ( GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plottitle );
LEPT_DLL extern l_ok gplotAddPlot ( GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plotlabel );
LEPT_DLL extern l_ok gplotSetScaling ( GPLOT *gplot, l_int32 scaling );
LEPT_DLL extern PIX * gplotMakeOutputPix ( GPLOT *gplot );
LEPT_DLL extern l_ok gplotMakeOutput ( GPLOT *gplot );
LEPT_DLL extern l_ok gplotGenCommandFile ( GPLOT *gplot );
LEPT_DLL extern l_ok gplotGenDataFiles ( GPLOT *gplot );
@ -950,6 +951,9 @@ LEPT_DLL extern PIX * gplotSimplePixN ( NUMAA *naa, const char *title );
LEPT_DLL extern GPLOT * gplotSimpleXY1 ( NUMA *nax, NUMA *nay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title );
LEPT_DLL extern GPLOT * gplotSimpleXY2 ( NUMA *nax, NUMA *nay1, NUMA *nay2, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title );
LEPT_DLL extern GPLOT * gplotSimpleXYN ( NUMA *nax, NUMAA *naay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title );
LEPT_DLL extern PIX * gplotGeneralPix1 ( NUMA *na, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel );
LEPT_DLL extern PIX * gplotGeneralPix2 ( NUMA *na1, NUMA *na2, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel );
LEPT_DLL extern PIX * gplotGeneralPixN ( NUMA *nax, NUMAA *naay, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel );
LEPT_DLL extern GPLOT * gplotRead ( const char *filename );
LEPT_DLL extern l_ok gplotWrite ( const char *filename, GPLOT *gplot );
LEPT_DLL extern PTA * generatePtaLine ( l_int32 x1, l_int32 y1, l_int32 x2, l_int32 y2 );

3
src/binarize.c

@ -964,7 +964,8 @@ PIX *pix1, *pix2, *pix3;
pixDestroy(&pix3);
}
if (debugflag) {
gplot = gplotCreate("/tmp/threshroot", GPLOT_PNG,
lept_mkdir("lept/binarize");
gplot = gplotCreate("/tmp/lept/binarize", GPLOT_PNG,
"number of cc vs. threshold",
"threshold", "number of cc");
gplotAddPlot(gplot, NULL, na4, GPLOT_LINES, "plot 4cc");

13
src/boxfunc5.c

@ -1770,7 +1770,7 @@ NUMA *nal, *nat, *nar, *nab;
* \param[in] plotname [optional], can be NULL
* \param[out] pnaw [optional] na of widths
* \param[out] pnah [optional] na of heights
* \param[out] ppixd [optional] pix of the output plot
* \param[out] ppixd pix of the output plot
* \return 0 if OK, 1 on error
*
* <pre>
@ -1803,18 +1803,18 @@ NUMA *naw, *nah;
if (pnaw) *pnaw = NULL;
if (pnah) *pnah = NULL;
if (ppixd) *ppixd = NULL;
if (!boxa)
return ERROR_INT("boxa not defined", procName, 1);
if ((n = boxaGetCount(boxa)) < 2)
return ERROR_INT("less than 2 boxes", procName, 1);
if (!ppixd)
return ERROR_INT("&pixd not defined", procName, 1);
boxat = boxaFillSequence(boxa, L_USE_ALL_BOXES, 0);
/* Build the numas for the width and height */
naw = numaCreate(n);
nah = numaCreate(n);
for (i = 0; i < n; i++) {
boxaGetBoxGeometry(boxat, i, NULL, NULL, &w, &h);
numaAddNumber(naw, w);
@ -1835,14 +1835,9 @@ NUMA *naw, *nah;
"box index", "box dimension");
gplotAddPlot(gplot, NULL, naw, GPLOT_LINES, "width");
gplotAddPlot(gplot, NULL, nah, GPLOT_LINES, "height");
gplotMakeOutput(gplot);
*ppixd = gplotMakeOutputPix(gplot);
gplotDestroy(&gplot);
if (ppixd) {
stringCat(buf, sizeof(buf), ".png");
*ppixd = pixRead(buf);
}
if (pnaw)
*pnaw = naw;
else

92
src/colorcontent.c

@ -158,7 +158,9 @@
* \brief pixColorContent()
*
* \param[in] pixs 32 bpp rgb or 8 bpp colormapped
* \param[in] rwhite, gwhite, bwhite color value associated with white point
* \param[in] rref, gref, bref reference color values (e.g. median
* or mean, to compare with the pixel
* component values.
* \param[in] mingray min gray value for which color is measured
* \param[out] ppixr [optional] 8 bpp red 'content'
* \param[out] ppixg [optional] 8 bpp green 'content'
@ -172,11 +174,16 @@
* as the difference between the component and the average of
* the other two components. See the discussion at the
* top of this file.
* (2) The three numbers (rwhite, gwhite and bwhite) can be thought
* of as the values in the image corresponding to white.
* They are used to compensate for an unbalanced color white point.
* They must either be all 0 or all non-zero. To turn this
* off, set them all to 0.
* (2) The three numbers (rref, gref and bref) can be thought
* of in two ways:
* (a) as the values in the image corresponding to white,
* to compensate for an unbalanced color white point.
* (b) the median or mean values of the background color of
* a scan.
* The gamma TRC transformation is used to modify all colors so that
* these reference values become white.
* These three numbers must either be all 0 or all non-zero.
* To skip the TRC transform, set them all to 0.
* (3) If the maximum component after white point correction,
* max(r,g,b), is less than mingray, all color components
* for that pixel are set to zero.
@ -188,9 +195,9 @@
*/
l_ok
pixColorContent(PIX *pixs,
l_int32 rwhite,
l_int32 gwhite,
l_int32 bwhite,
l_int32 rref,
l_int32 gref,
l_int32 bref,
l_int32 mingray,
PIX **ppixr,
PIX **ppixg,
@ -219,10 +226,11 @@ PIXCMAP *cmap;
pixGetDimensions(pixs, &w, &h, &d);
if (mingray > 255)
return ERROR_INT("mingray > 255", procName, 1);
if (rwhite < 0 || gwhite < 0 || bwhite < 0)
return ERROR_INT("some white vals are negative", procName, 1);
if ((rwhite || gwhite || bwhite) && (rwhite * gwhite * bwhite == 0))
return ERROR_INT("white vals not all zero or all nonzero", procName, 1);
if (rref < 0 || gref < 0 || bref < 0)
return ERROR_INT("some reference vals are negative", procName, 1);
if ((rref || gref || bref) && (rref * gref * bref == 0))
return ERROR_INT("reference vals not all zero or all nonzero",
procName, 1);
cmap = pixGetColormap(pixs);
if (!cmap && d != 32)
@ -255,12 +263,12 @@ PIXCMAP *cmap;
datac = pixGetData(pixc);
wplc = pixGetWpl(pixc);
if (rwhite) { /* all white pt vals are nonzero */
nar = numaGammaTRC(1.0, 0, rwhite);
if (rref) { /* all reference vals are nonzero */
nar = numaGammaTRC(1.0, 0, rref);
rtab = numaGetIArray(nar);
nag = numaGammaTRC(1.0, 0, gwhite);
nag = numaGammaTRC(1.0, 0, gref);
gtab = numaGetIArray(nag);
nab = numaGammaTRC(1.0, 0, bwhite);
nab = numaGammaTRC(1.0, 0, bref);
btab = numaGetIArray(nab);
}
for (i = 0; i < h; i++) {
@ -274,7 +282,7 @@ PIXCMAP *cmap;
for (j = 0; j < w; j++) {
pixel = linec[j];
extractRGBValues(pixel, &rval, &gval, &bval);
if (rwhite) { /* color correct for white point */
if (rref) { /* color correct for reference values */
rval = rtab[rval];
gval = gtab[gval];
bval = btab[bval];
@ -303,7 +311,7 @@ PIXCMAP *cmap;
}
}
if (rwhite) {
if (rref) {
numaDestroy(&nar);
numaDestroy(&nag);
numaDestroy(&nab);
@ -324,7 +332,9 @@ PIXCMAP *cmap;
* \brief pixColorMagnitude()
*
* \param[in] pixs 32 bpp rgb or 8 bpp colormapped
* \param[in] rwhite, gwhite, bwhite color value associated with white point
* \param[in] rref, gref, bref reference color values (e.g. median
* or mean, to compare with the pixel
* component values.
* \param[in] type chooses the method for calculating the color magnitude:
* L_MAX_DIFF_FROM_AVERAGE_2, L_MAX_MIN_DIFF_FROM_2,
* L_MAX_DIFF
@ -363,18 +373,23 @@ PIXCMAP *cmap;
* (a) L_MAX_DIFF_FROM_AVERAGE_2
* (b) L_MAX_MIN_DIFF_FROM_2
* (c) L_MAX_DIFF
* (4) The three numbers (rwhite, gwhite and bwhite) can be thought
* of as the values in the image corresponding to white.
* They are used to compensate for an unbalanced color white point.
* They must either be all 0 or all non-zero. To turn this
* off, set them all to 0.
* (4) The three numbers (rref, gref and bref) can be thought
* of in two ways:
* (a) as the values in the image corresponding to white,
* to compensate for an unbalanced color white point.
* (b) the median or mean values of the background color of
* a scan.
* The gamma TRC transformation is used to modify all colors so that
* these reference values become white.
* These three numbers must either be all 0 or all non-zero.
* To skip the TRC transform, set them all to 0.
* </pre>
*/
PIX *
pixColorMagnitude(PIX *pixs,
l_int32 rwhite,
l_int32 gwhite,
l_int32 bwhite,
l_int32 rref,
l_int32 gref,
l_int32 bref,
l_int32 type)
{
l_int32 w, h, d, i, j, wplc, wpld;
@ -395,10 +410,11 @@ PIXCMAP *cmap;
if (type != L_MAX_DIFF_FROM_AVERAGE_2 && type != L_MAX_MIN_DIFF_FROM_2 &&
type != L_MAX_DIFF)
return (PIX *)ERROR_PTR("invalid type", procName, NULL);
if (rwhite < 0 || gwhite < 0 || bwhite < 0)
return (PIX *)ERROR_PTR("some white vals are negative", procName, NULL);
if ((rwhite || gwhite || bwhite) && (rwhite * gwhite * bwhite == 0))
return (PIX *)ERROR_PTR("white vals not all zero or all nonzero",
if (rref < 0 || gref < 0 || bref < 0)
return (PIX *)ERROR_PTR("some reference vals are negative",
procName, NULL);
if ((rref || gref || bref) && (rref * gref * bref == 0))
return (PIX *)ERROR_PTR("reference vals not all zero or all nonzero",
procName, NULL);
cmap = pixGetColormap(pixs);
@ -414,12 +430,12 @@ PIXCMAP *cmap;
wpld = pixGetWpl(pixd);
datac = pixGetData(pixc);
wplc = pixGetWpl(pixc);
if (rwhite) { /* all white pt vals are nonzero */
nar = numaGammaTRC(1.0, 0, rwhite);
if (rref) { /* all ref vals are nonzero */
nar = numaGammaTRC(1.0, 0, rref);
rtab = numaGetIArray(nar);
nag = numaGammaTRC(1.0, 0, gwhite);
nag = numaGammaTRC(1.0, 0, gref);
gtab = numaGetIArray(nag);
nab = numaGammaTRC(1.0, 0, bwhite);
nab = numaGammaTRC(1.0, 0, bref);
btab = numaGetIArray(nab);
}
for (i = 0; i < h; i++) {
@ -428,7 +444,7 @@ PIXCMAP *cmap;
for (j = 0; j < w; j++) {
pixel = linec[j];
extractRGBValues(pixel, &rval, &gval, &bval);
if (rwhite) { /* color correct for white point */
if (rref) { /* color correct for reference values */
rval = rtab[rval];
gval = gtab[gval];
bval = btab[bval];
@ -464,7 +480,7 @@ PIXCMAP *cmap;
}
}
if (rwhite) {
if (rref) {
numaDestroy(&nar);
numaDestroy(&nag);
numaDestroy(&nab);

290
src/gplot.c

@ -33,11 +33,12 @@
* void gplotDestroy()
* l_int32 gplotAddPlot()
* l_int32 gplotSetScaling()
* PIX *gplotMakeOutputPix()
* l_int32 gplotMakeOutput()
* l_int32 gplotGenCommandFile()
* l_int32 gplotGenDataFiles()
*
* Quick and dirty plots
* Quick, one-line plots
* l_int32 gplotSimple1()
* l_int32 gplotSimple2()
* l_int32 gplotSimpleN()
@ -47,6 +48,9 @@
* GPLOT *gplotSimpleXY1()
* GPLOT *gplotSimpleXY2()
* GPLOT *gplotSimpleXYN()
* PIX *gplotGeneralPix1()
* PIX *gplotGeneralPix2()
* PIX *gplotGeneralPixN()
*
* Serialize for I/O
* GPLOT *gplotRead()
@ -56,18 +60,18 @@
* Utility for programmatic plotting using gnuplot 4.6 or later
* Enabled:
* ~ output to png (color), ps and eps (mono), latex (mono)
* ~ optional title for graph
* ~ optional title for plot
* ~ optional x and y axis labels
* ~ multiple plots on one frame
* ~ optional title for each plot on the frame
* ~ optional label for each plot on the frame
* ~ optional log scaling on either or both axes
* ~ choice of 5 plot styles for each plot
* ~ choice of 5 plot styles for each array of input data
* ~ choice of 2 plot modes, either using one input array
* (Y vs index) or two input arrays (Y vs X). This
* choice is made implicitly depending on the number of
* input arrays.
* (Y vs index) or two input arrays (Y vs X). For functions
* that take two arrays, the first mode (Y vs index) is
* employed if the first array is NULL.
*
* Usage:
* General usage:
* gplotCreate() initializes for plotting
* gplotAddPlot() for each plot on the frame
* gplotMakeOutput() to generate all output files and run gnuplot
@ -82,6 +86,42 @@
* gplotMakeOutput(gplot);
* gplotDestroy(&gplot);
*
* Example usage of one-line plot generators:
*
* -- Simple plots --
* Specify the root of output files, the output format,
* and the title (optional), but not the x and y coordinate labels
* or the plot labels. The plotstyle defaults to GPLOT_LINES.
* gplotSimple2(na1, na2, GPLOT_PNG, "/tmp/lept/histo/gray",
* "gray histogram");
* Multiple plots can be generated using gplotSimpleN().
*
* -- Simple plots with more options --
* Specify the root of output files, the plotstyle, the output format,
* and optionally the title, but not the x and y coordinate labels
* or the plot labels.
* gplotSimpleXY1(na1, na2, GPLOT_LINES, GPLOT_PNG,
* "/tmp/lept/histo/gray", "gray histogram");
* Multiple plots can be generated using gplotSimpleXYN().
*
* -- Simple plots returning a pix --
* Specify only the title (optional). The plotstyle defaults
* GPLOT_LINES and the output format is GPLOT_PNG..
* You can't specify the x and y coordinate lables or the plot label.
* The rootname of the generated files is determined internally.
* Pix *pix = gplotSimplePix2(na1, na2, "gray histogram");
* Multiple plots can be generated using gplotSimplePixN().
*
* -- General plots returning a pix --
* Specify the root of the output files, the plotstyle, and optionally
* the title and axis labels. This does not allow the individual
* plots to have plot labels, or to use different plotstyles
* for each plot.
* Pix *pix = gplotGeneralPix2(na1, na2, "/tmp/lept/histo/gray",
* GPLOT_LINES, "gray histogram",
* "pix value", "num pixels");
* Multiple plots can be generated using gplotGeneralPixN().
*
* Note for output to GPLOT_LATEX:
* This creates latex output of the plot, named <rootname>.tex.
* It needs to be placed in a latex file <latexname>.tex
@ -178,7 +218,7 @@ GPLOT *gplot;
gplot->cmddata = sarrayCreate(0);
gplot->datanames = sarrayCreate(0);
gplot->plotdata = sarrayCreate(0);
gplot->plottitles = sarrayCreate(0);
gplot->plotlabels = sarrayCreate(0);
gplot->plotstyles = numaCreate(0);
/* Save title, labels, rootname, outformat, cmdname, outname */
@ -231,7 +271,7 @@ GPLOT *gplot;
sarrayDestroy(&gplot->cmddata);
sarrayDestroy(&gplot->datanames);
sarrayDestroy(&gplot->plotdata);
sarrayDestroy(&gplot->plottitles);
sarrayDestroy(&gplot->plotlabels);
numaDestroy(&gplot->plotstyles);
LEPT_FREE(gplot->outname);
if (gplot->title)
@ -256,7 +296,7 @@ GPLOT *gplot;
* \param[in] nay numa; required for both Y_VS_I and Y_VS_X
* \param[in] plotstyle GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES,
* GPLOT_LINESPOINTS, GPLOT_DOTS
* \param[in] plottitle [optional] title for individual plot
* \param[in] plotlabel [optional] label for individual plot
* \return 0 if OK, 1 on error
*
* <pre>
@ -273,7 +313,7 @@ GPLOT *gplot;
* values are startx = 0.0, delx = 1.0.
* (3) If %nax is defined, it must be the same size as %nay, and
* must have at least one number.
* (4) The 'plottitle' string can have spaces, double
* (4) The 'plotlabel' string can have spaces, double
* quotes and backquotes, but not single quotes.
* </pre>
*/
@ -282,7 +322,7 @@ gplotAddPlot(GPLOT *gplot,
NUMA *nax,
NUMA *nay,
l_int32 plotstyle,
const char *plottitle)
const char *plotlabel)
{
char buf[Bufsize];
char emptystring[] = "";
@ -309,14 +349,14 @@ SARRAY *sa;
plotstyle = GPLOT_POINTS;
}
/* Save plotstyle and plottitle */
/* Save plotstyle and plotlabel */
numaGetParameters(nay, &startx, &delx);
numaAddNumber(gplot->plotstyles, plotstyle);
if (plottitle) {
title = stringNew(plottitle);
sarrayAddString(gplot->plottitles, title, L_INSERT);
if (plotlabel) {
title = stringNew(plotlabel);
sarrayAddString(gplot->plotlabels, title, L_INSERT);
} else {
sarrayAddString(gplot->plottitles, emptystring, L_COPY);
sarrayAddString(gplot->plotlabels, emptystring, L_COPY);
}
/* Generate and save data filename */
@ -375,6 +415,35 @@ gplotSetScaling(GPLOT *gplot,
}
/*!
* \brief gplotMakeOutputPix()
*
* \param[in] gplot
* \return 0 if OK; 1 on error
*
* <pre>
* Notes:
* (1) This wraps gplotMakeOutput(), and returns a pix.
* See gplotMakeOutput() for details.
* (2) The gplot output format must be an image (png or pnm).
* </pre>
*/
PIX *
gplotMakeOutputPix(GPLOT *gplot)
{
PROCNAME("gplotMakeOutputPix");
if (!gplot)
return (PIX *)ERROR_PTR("gplot not defined", procName, NULL);
if (gplot->outformat != GPLOT_PNG && gplot->outformat != GPLOT_PNM)
return (PIX *)ERROR_PTR("output format not an image", procName, NULL);
if (gplotMakeOutput(gplot))
return (PIX *)ERROR_PTR("plot output not made", procName, NULL);
return pixRead(gplot->outname);
}
/*!
* \brief gplotMakeOutput()
*
@ -386,8 +455,9 @@ gplotSetScaling(GPLOT *gplot,
* (1) This uses gplot and the new arrays to add a plot
* to the output, by writing a new data file and appending
* the appropriate plot commands to the command file.
* (2) This is the only function in this file that requires the
* gnuplot executable, to actually generate the plot.
* (2) Along with gplotMakeOutputPix(), these are the only functions
* in this file that requires the gnuplot executable to
* actually generate the plot.
* (3) The command file name for unix is canonical (i.e., directory /tmp)
* but the temp filename paths in the command file must be correct.
* (4) The gnuplot program for windows is wgnuplot.exe.
@ -440,7 +510,7 @@ l_ok
gplotGenCommandFile(GPLOT *gplot)
{
char buf[Bufsize];
char *cmdstr, *plottitle, *dataname;
char *cmdstr, *plotlabel, *dataname;
l_int32 i, plotstyle, nplots;
FILE *fp;
@ -498,22 +568,22 @@ FILE *fp;
nplots = sarrayGetCount(gplot->datanames);
for (i = 0; i < nplots; i++) {
plottitle = sarrayGetString(gplot->plottitles, i, L_NOCOPY);
plotlabel = sarrayGetString(gplot->plotlabels, i, L_NOCOPY);
dataname = sarrayGetString(gplot->datanames, i, L_NOCOPY);
numaGetIValue(gplot->plotstyles, i, &plotstyle);
if (nplots == 1) {
snprintf(buf, Bufsize, "plot '%s' title '%s' %s",
dataname, plottitle, gplotstylenames[plotstyle]);
dataname, plotlabel, gplotstylenames[plotstyle]);
} else {
if (i == 0)
snprintf(buf, Bufsize, "plot '%s' title '%s' %s, \\",
dataname, plottitle, gplotstylenames[plotstyle]);
dataname, plotlabel, gplotstylenames[plotstyle]);
else if (i < nplots - 1)
snprintf(buf, Bufsize, " '%s' title '%s' %s, \\",
dataname, plottitle, gplotstylenames[plotstyle]);
dataname, plotlabel, gplotstylenames[plotstyle]);
else
snprintf(buf, Bufsize, " '%s' title '%s' %s",
dataname, plottitle, gplotstylenames[plotstyle]);
dataname, plotlabel, gplotstylenames[plotstyle]);
}
sarrayAddString(gplot->cmddata, buf, L_COPY);
}
@ -571,7 +641,7 @@ FILE *fp;
/*-----------------------------------------------------------------*
* Quick and Dirty Plots *
* Quick one-line plots *
*-----------------------------------------------------------------*/
/*!
* \brief gplotSimple1()
@ -997,6 +1067,166 @@ NUMA *nay;
}
/*!
* \brief gplotGeneralPix1()
*
* \param[in] na data array
* \param[in] plotstyle GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES,
* GPLOT_LINESPOINTS, GPLOT_DOTS
* \param[in] rootname root for all output files
* \param[in] title [optional] overall title
* \param[in] xlabel [optional] x axis label
* \param[in] ylabel [optional] y axis label
* \return pix of plot, or NULL on error
*
* <pre>
* Notes:
* (1) The 'title', 'xlabel' and 'ylabel' strings can have spaces,
* double quotes and backquotes, but not single quotes.
* </pre>
*/
PIX *
gplotGeneralPix1(NUMA *na,
l_int32 plotstyle,
const char *rootname,
const char *title,
const char *xlabel,
const char *ylabel)
{
GPLOT *gplot;
PIX *pix;
PROCNAME("gplotGeneralPix1");
if (!na)
return (PIX *)ERROR_PTR("na not defined", procName, NULL);
if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
return (PIX *)ERROR_PTR("invalid plotstyle", procName, NULL);
if (!rootname)
return (PIX *)ERROR_PTR("rootname not defined", procName, NULL);
gplot = gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
if (!gplot)
return (PIX *)ERROR_PTR("gplot not made", procName, NULL);
gplotAddPlot(gplot, NULL, na, plotstyle, NULL);
pix = gplotMakeOutputPix(gplot);
gplotDestroy(&gplot);
return pix;
}
/*!
* \brief gplotGeneralPix2()
*
* \param[in] na1 x-axis data array
* \param[in] na2 y-axis data array
* \param[in] plotstyle GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES,
* GPLOT_LINESPOINTS, GPLOT_DOTS
* \param[in] rootname root for all output files
* \param[in] title [optional] overall title
* \param[in] xlabel [optional] x axis label
* \param[in] ylabel [optional] y axis label
* \return pix of plot, or NULL on error
*
* <pre>
* Notes:
* (1) The 'title', 'xlabel' and 'ylabel' strings can have spaces,
* double quotes and backquotes, but not single quotes.
* </pre>
*/
PIX *
gplotGeneralPix2(NUMA *na1,
NUMA *na2,
l_int32 plotstyle,
const char *rootname,
const char *title,
const char *xlabel,
const char *ylabel)
{
GPLOT *gplot;
PIX *pix;
PROCNAME("gplotGeneralPix2");
if (!na1)
return (PIX *)ERROR_PTR("na1 not defined", procName, NULL);
if (!na2)
return (PIX *)ERROR_PTR("na2 not defined", procName, NULL);
if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
return (PIX *)ERROR_PTR("invalid plotstyle", procName, NULL);
if (!rootname)
return (PIX *)ERROR_PTR("rootname not defined", procName, NULL);
gplot = gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
if (!gplot)
return (PIX *)ERROR_PTR("gplot not made", procName, NULL);
gplotAddPlot(gplot, na1, na2, plotstyle, NULL);
pix = gplotMakeOutputPix(gplot);
gplotDestroy(&gplot);
return pix;
}
/*!
* \brief gplotGeneralPixN()
*
* \param[in] nax x-axis data array
* \param[in] naay array of y-axis data arrays
* \param[in] plotstyle GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES,
* GPLOT_LINESPOINTS, GPLOT_DOTS
* \param[in] rootname root for all output files
* \param[in] title [optional] overall title
* \param[in] xlabel [optional] x axis label
* \param[in] ylabel [optional] y axis label
* \return pix of plot, or NULL on error
*
* <pre>
* Notes:
* (1) The 'title', 'xlabel' and 'ylabel' strings can have spaces,
* double quotes and backquotes, but not single quotes.
* </pre>
*/
PIX *
gplotGeneralPixN(NUMA *nax,
NUMAA *naay,
l_int32 plotstyle,
const char *rootname,
const char *title,
const char *xlabel,
const char *ylabel)
{
l_int32 i, n;
GPLOT *gplot;
NUMA *nay;
PIX *pix;
PROCNAME("gplotGeneralPixN");
if (!nax)
return (PIX *)ERROR_PTR("nax not defined", procName, NULL);
if (!naay)
return (PIX *)ERROR_PTR("naay not defined", procName, NULL);
if ((n = numaaGetCount(naay)) == 0)
return (PIX *)ERROR_PTR("no numa in array", procName, NULL);
if (plotstyle < 0 || plotstyle >= NUM_GPLOT_STYLES)
return (PIX *)ERROR_PTR("invalid plotstyle", procName, NULL);
if (!rootname)
return (PIX *)ERROR_PTR("rootname not defined", procName, NULL);
gplot = gplotCreate(rootname, GPLOT_PNG, title, xlabel, ylabel);
if (!gplot)
return (PIX *)ERROR_PTR("gplot not made", procName, NULL);
for (i = 0; i < n; i++) {
nay = numaaGetNuma(naay, i, L_CLONE);
gplotAddPlot(gplot, nax, nay, plotstyle, NULL);
numaDestroy(&nay);
}
pix = gplotMakeOutputPix(gplot);
gplotDestroy(&gplot);
return pix;
}
/*-----------------------------------------------------------------*
* Serialize for I/O *
*-----------------------------------------------------------------*/
@ -1058,7 +1288,7 @@ GPLOT *gplot;
sarrayDestroy(&gplot->cmddata);
sarrayDestroy(&gplot->datanames);
sarrayDestroy(&gplot->plotdata);
sarrayDestroy(&gplot->plottitles);
sarrayDestroy(&gplot->plotlabels);
numaDestroy(&gplot->plotstyles);
ignore = fscanf(fp, "Commandfile name: %511s\n", buf); /* Bufsize - 1 */
@ -1070,7 +1300,7 @@ GPLOT *gplot;
ignore = fscanf(fp, "\nPlot data:");
gplot->plotdata = sarrayReadStream(fp);
ignore = fscanf(fp, "\nPlot titles:");
gplot->plottitles = sarrayReadStream(fp);
gplot->plotlabels = sarrayReadStream(fp);
ignore = fscanf(fp, "\nPlot styles:");
gplot->plotstyles = numaReadStream(fp);
@ -1122,7 +1352,7 @@ FILE *fp;
fprintf(fp, "\nPlot data:");
sarrayWriteStream(fp, gplot->plotdata);
fprintf(fp, "\nPlot titles:");
sarrayWriteStream(fp, gplot->plottitles);
sarrayWriteStream(fp, gplot->plotlabels);
fprintf(fp, "\nPlot styles:");
numaWriteStream(fp, gplot->plotstyles);

2
src/gplot.h

@ -80,7 +80,7 @@ struct GPlot
struct Sarray *cmddata; /*!< command file contents */
struct Sarray *datanames; /*!< data file names */
struct Sarray *plotdata; /*!< plot data (1 string/file) */
struct Sarray *plottitles; /*!< title for each individual plot */
struct Sarray *plotlabels; /*!< label for each individual plot */
struct Numa *plotstyles; /*!< plot style for individual plots */
l_int32 nplots; /*!< current number of plots */
char *outname; /*!< output file name */

22
src/jbclass.c

@ -1535,23 +1535,17 @@ PIX *pix1, *pix2;
PIX *pix3, *pix4;
L_INFO("Best dilation: %d\n", procName, L_MAX(3, ibest + 1));
naseq = numaMakeSequence(1, 1, numaGetCount(nacc));
gplot = gplotCreate("/tmp/lept/jb/numcc", GPLOT_PNG,
"Number of cc vs. horizontal dilation",
"Sel horiz", "Number of cc");
gplotAddPlot(gplot, naseq, nacc, GPLOT_LINES, "");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix3 = pixRead("/tmp/lept/jb/numcc.png");
pix3 = gplotGeneralPix2(naseq, nacc, GPLOT_LINES,
"/tmp/lept/jb/numcc",
"Number of cc vs. horizontal dilation",
"Sel horiz", "Number of cc");
pixaAddPix(pixadb, pix3, L_INSERT);
numaDestroy(&naseq);
naseq = numaMakeSequence(1, 1, numaGetCount(nadiff));
gplot = gplotCreate("/tmp/lept/jb/diffcc", GPLOT_PNG,
"Diff count of cc vs. horizontal dilation",
"Sel horiz", "Diff in cc");
gplotAddPlot(gplot, naseq, nadiff, GPLOT_LINES, "");
gplotMakeOutput(gplot);
gplotDestroy(&gplot);
pix3 = pixRead("/tmp/lept/jb/diffcc.png");
pix3 = gplotGeneralPix2(naseq, nadiff, GPLOT_LINES,
"/tmp/lept/jb/diffcc",
"Diff count of cc vs. horizontal dilation",
"Sel horiz", "Diff in cc");
pixaAddPix(pixadb, pix3, L_INSERT);
numaDestroy(&naseq);
pix3 = pixCloseBrick(NULL, pixs, ibest + 1, 1);

3
src/pix4.c

@ -3446,11 +3446,10 @@ PIX *pixg;
numaReplaceNumber(nay, 1, (l_int32)(0.5 * maxnum));
snprintf(buf, sizeof(buf), "score fract = %3.1f", scorefract);
gplotAddPlot(gplot, nax, nay, GPLOT_LINES, buf);
gplotMakeOutput(gplot);
*ppixdb = gplotMakeOutputPix(gplot);
gplotDestroy(&gplot);
numaDestroy(&nax);
numaDestroy(&nay);
*ppixdb = pixRead("/tmp/lept/redout/histplot.png");
}
pixDestroy(&pixg);

Loading…
Cancel
Save