![]() |
Leptonica
1.82.0
Image processing and image analysis suite
|
#include <string.h>
#include "allheaders.h"
Go to the source code of this file.
Macros | |
#define | Bufsize 512 /* hardcoded below in fscanf */ |
Functions | |
GPLOT * | gplotCreate (const char *rootname, l_int32 outformat, const char *title, const char *xlabel, const char *ylabel) |
void | gplotDestroy (GPLOT **pgplot) |
l_ok | gplotAddPlot (GPLOT *gplot, NUMA *nax, NUMA *nay, l_int32 plotstyle, const char *plotlabel) |
l_ok | gplotSetScaling (GPLOT *gplot, l_int32 scaling) |
PIX * | gplotMakeOutputPix (GPLOT *gplot) |
l_ok | gplotMakeOutput (GPLOT *gplot) |
l_ok | gplotGenCommandFile (GPLOT *gplot) |
l_ok | gplotGenDataFiles (GPLOT *gplot) |
l_ok | gplotSimple1 (NUMA *na, l_int32 outformat, const char *outroot, const char *title) |
l_ok | gplotSimple2 (NUMA *na1, NUMA *na2, l_int32 outformat, const char *outroot, const char *title) |
l_ok | gplotSimpleN (NUMAA *naa, l_int32 outformat, const char *outroot, const char *title) |
PIX * | gplotSimplePix1 (NUMA *na, const char *title) |
PIX * | gplotSimplePix2 (NUMA *na1, NUMA *na2, const char *title) |
PIX * | gplotSimplePixN (NUMAA *naa, const char *title) |
GPLOT * | gplotSimpleXY1 (NUMA *nax, NUMA *nay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title) |
GPLOT * | gplotSimpleXY2 (NUMA *nax, NUMA *nay1, NUMA *nay2, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title) |
GPLOT * | gplotSimpleXYN (NUMA *nax, NUMAA *naay, l_int32 plotstyle, l_int32 outformat, const char *outroot, const char *title) |
PIX * | gplotGeneralPix1 (NUMA *na, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel) |
PIX * | gplotGeneralPix2 (NUMA *na1, NUMA *na2, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel) |
PIX * | gplotGeneralPixN (NUMA *nax, NUMAA *naay, l_int32 plotstyle, const char *rootname, const char *title, const char *xlabel, const char *ylabel) |
GPLOT * | gplotRead (const char *filename) |
l_ok | gplotWrite (const char *filename, GPLOT *gplot) |
Variables | |
const char * | gplotstylenames [] |
const char * | gplotfileoutputs [] |
Basic plotting functions GPLOT *gplotCreate() void gplotDestroy() l_int32 gplotAddPlot() l_int32 gplotSetScaling() PIX *gplotMakeOutputPix() l_int32 gplotMakeOutput() l_int32 gplotGenCommandFile() l_int32 gplotGenDataFiles() Quick, one-line plots l_int32 gplotSimple1() l_int32 gplotSimple2() l_int32 gplotSimpleN() PIX *gplotSimplePix1() PIX *gplotSimplePix2() PIX *gplotSimplePixN() GPLOT *gplotSimpleXY1() GPLOT *gplotSimpleXY2() GPLOT *gplotSimpleXYN() PIX *gplotGeneralPix1() PIX *gplotGeneralPix2() PIX *gplotGeneralPixN() Serialize for I/O GPLOT *gplotRead() l_int32 gplotWrite() Utility for programmatic plotting using gnuplot 4.6 or later Enabled: ~ output to png (color), ps and eps (mono), latex (mono) ~ optional title for plot ~ optional x and y axis labels ~ multiple plots on one frame ~ optional label for each plot on the frame ~ optional log scaling on either or both axes ~ 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). For functions that take two arrays, the first mode (Y vs index) is employed if the first array is NULL. General usage: gplotCreate() initializes for plotting gplotAddPlot() for each plot on the frame gplotMakeOutput() to generate all output files and run gnuplot gplotDestroy() to clean up Example of use: gplot = gplotCreate("tempskew", GPLOT_PNG, "Skew score vs angle", "angle (deg)", "score"); gplotAddPlot(gplot, natheta, nascore1, GPLOT_LINES, "plot 1"); gplotAddPlot(gplot, natheta, nascore2, GPLOT_POINTS, "plot 2"); gplotSetScaling(gplot, GPLOT_LOG_SCALE_Y); 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 labels 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 that precedes the plot output with, at a minimum: \documentclass{article} \begin{document} and ends with \end{document} You can then generate a dvi file <latexname>.dvi using latex <latexname>.tex and a PostScript file <psname>.ps from that using dvips -o <psname>.ps <latexname>.dvi N.B. To generate plots, it is necessary to have gnuplot installed on your Unix system, or wgnuplot on Windows.
Definition in file gplot.c.
l_ok gplotAddPlot | ( | GPLOT * | gplot, |
NUMA * | nax, | ||
NUMA * | nay, | ||
l_int32 | plotstyle, | ||
const char * | plotlabel | ||
) |
[in] | gplot | |
[in] | nax | [optional] numa: set to null for Y_VS_I; required for Y_VS_X |
[in] | nay | numa; required for both Y_VS_I and Y_VS_X |
[in] | plotstyle | GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES, GPLOT_LINESPOINTS, GPLOT_DOTS |
[in] | plotlabel | [optional] label for individual plot |
Notes: (1) There are 2 options for (x,y) values: o To plot an array vs a linear function of the index, set nax = NULL. o To plot one array vs another, use both nax and nay. (2) If nax is NULL, the x value corresponding to the i-th value of nay is found from the startx and delx fields in nay: x = startx + i * delx These are set with numaSetParameters(). Their default 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 'plotlabel' string can have spaces, double quotes and backquotes, but not single quotes.
GPLOT* gplotCreate | ( | const char * | rootname, |
l_int32 | outformat, | ||
const char * | title, | ||
const char * | xlabel, | ||
const char * | ylabel | ||
) |
[in] | rootname | root for all output files |
[in] | outformat | GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX, GPLOT_PNM |
[in] | title | [optional] overall title |
[in] | xlabel | [optional] x axis label |
[in] | ylabel | [optional] y axis label |
Notes: (1) This initializes the plot. (2) The 'title', 'xlabel' and 'ylabel' strings can have spaces, double quotes and backquotes, but not single quotes.
Definition at line 187 of file gplot.c.
Referenced by boxaPlotSides(), boxaPlotSizes(), numaQuantizeCrossingsByWidth(), and pixSplitDistributionFgBg().
void gplotDestroy | ( | GPLOT ** | pgplot | ) |
[in,out] | pgplot | will be set to null before returning |
Definition at line 255 of file gplot.c.
References GPlot::cmddata, GPlot::cmdname, GPlot::datanames, numaDestroy(), GPlot::outname, GPlot::plotdata, GPlot::plotlabels, GPlot::plotstyles, GPlot::rootname, sarrayDestroy(), GPlot::title, GPlot::xlabel, and GPlot::ylabel.
l_ok gplotGenCommandFile | ( | GPLOT * | gplot | ) |
[in] | gplot |
l_ok gplotGenDataFiles | ( | GPLOT * | gplot | ) |
[in] | gplot |
Notes: (1) The pathnames in the gplot command file are actual pathnames, which can be in temp directories. Consequently, they must not be rewritten by calling fopenWriteStream(), and we use fopen().
Definition at line 617 of file gplot.c.
References GPlot::datanames, L_NOCOPY, GPlot::plotdata, sarrayGetCount(), and sarrayGetString().
PIX* gplotGeneralPix1 | ( | NUMA * | na, |
l_int32 | plotstyle, | ||
const char * | rootname, | ||
const char * | title, | ||
const char * | xlabel, | ||
const char * | ylabel | ||
) |
[in] | na | data array |
[in] | plotstyle | GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES, GPLOT_LINESPOINTS, GPLOT_DOTS |
[in] | rootname | root for all output files |
[in] | title | [optional] overall title |
[in] | xlabel | [optional] x axis label |
[in] | ylabel | [optional] y axis label |
Notes: (1) The 'title', 'xlabel' and 'ylabel' strings can have spaces, double quotes and backquotes, but not single quotes.
PIX* gplotGeneralPix2 | ( | NUMA * | na1, |
NUMA * | na2, | ||
l_int32 | plotstyle, | ||
const char * | rootname, | ||
const char * | title, | ||
const char * | xlabel, | ||
const char * | ylabel | ||
) |
[in] | na1 | x-axis data array |
[in] | na2 | y-axis data array |
[in] | plotstyle | GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES, GPLOT_LINESPOINTS, GPLOT_DOTS |
[in] | rootname | root for all output files |
[in] | title | [optional] overall title |
[in] | xlabel | [optional] x axis label |
[in] | ylabel | [optional] y axis label |
Notes: (1) The 'title', 'xlabel' and 'ylabel' strings can have spaces, double quotes and backquotes, but not single quotes.
PIX* gplotGeneralPixN | ( | NUMA * | nax, |
NUMAA * | naay, | ||
l_int32 | plotstyle, | ||
const char * | rootname, | ||
const char * | title, | ||
const char * | xlabel, | ||
const char * | ylabel | ||
) |
[in] | nax | x-axis data array |
[in] | naay | array of y-axis data arrays |
[in] | plotstyle | GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES, GPLOT_LINESPOINTS, GPLOT_DOTS |
[in] | rootname | root for all output files |
[in] | title | [optional] overall title |
[in] | xlabel | [optional] x axis label |
[in] | ylabel | [optional] y axis label |
Notes: (1) The 'title', 'xlabel' and 'ylabel' strings can have spaces, double quotes and backquotes, but not single quotes.
Definition at line 1189 of file gplot.c.
References numaaGetCount().
l_ok gplotMakeOutput | ( | GPLOT * | gplot | ) |
[in] | gplot |
Notes: (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) 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.
[in] | gplot |
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).
Definition at line 431 of file gplot.c.
References GPlot::outformat.
GPLOT* gplotRead | ( | const char * | filename | ) |
[in] | filename |
l_ok gplotSetScaling | ( | GPLOT * | gplot, |
l_int32 | scaling | ||
) |
[in] | gplot | |
[in] | scaling | GPLOT_LINEAR_SCALE, GPLOT_LOG_SCALE_X, GPLOT_LOG_SCALE_Y, GPLOT_LOG_SCALE_X_Y |
Notes: (1) By default, the x and y axis scaling is linear. (2) Call this function to set semi-log or log-log scaling.
Definition at line 400 of file gplot.c.
References GPLOT_LINEAR_SCALE.
l_ok gplotSimple1 | ( | NUMA * | na, |
l_int32 | outformat, | ||
const char * | outroot, | ||
const char * | title | ||
) |
[in] | na | numa; plot Y_VS_I |
[in] | outformat | GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX, GPLOT_PNM |
[in] | outroot | root of output files |
[in] | title | [optional], can be NULL |
Notes: (1) This generates a line plot of a numa, where the array value is plotted vs the array index. The plot is generated in the specified output format; the title is optional. (2) When calling these simple plot functions more than once, use different outroot to avoid overwriting the output files.
Definition at line 665 of file gplot.c.
References gplotSimpleXY1().
Referenced by numaSplitDistribution(), and pixGetDifferenceStats().
l_ok gplotSimple2 | ( | NUMA * | na1, |
NUMA * | na2, | ||
l_int32 | outformat, | ||
const char * | outroot, | ||
const char * | title | ||
) |
[in] | na1 | numa; plot with Y_VS_I |
[in] | na2 | ditto |
[in] | outformat | GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX, GPLOT_PNM |
[in] | outroot | root of output files |
[in] | title | [optional] |
Notes: (1) This generates a line plot of two numa, where the array values are each plotted vs the array index. The plot is generated in the specified output format; the title is optional. (2) When calling these simple plot functions more than once, use different outroot to avoid overwriting the output files.
Definition at line 703 of file gplot.c.
References gplotSimpleXY2().
Referenced by compareTilesByHisto(), and pixCompareTilesByHisto().
l_ok gplotSimpleN | ( | NUMAA * | naa, |
l_int32 | outformat, | ||
const char * | outroot, | ||
const char * | title | ||
) |
[in] | naa | numaa; plot Y_VS_I for each numa |
[in] | outformat | GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX, GPLOT_PNM |
[in] | outroot | root of output files |
[in] | title | [optional] |
Notes: (1) This generates a line plot of all numas in a numaa (array of numa), where the array values are each plotted vs the array index. The plot is generated in the specified output format; the title is optional. (2) When calling these simple plot functions more than once, use different outroot to avoid overwriting the output files.
Definition at line 743 of file gplot.c.
References gplotSimpleXYN().
[in] | na | numa; plot Y_VS_I |
[in] | title | [optional], can be NULL |
Notes: (1) This generates a line plot of a numa as a pix, where the array value is plotted vs the array index. The title is optional. (2) The temporary plot file is a png; its name is generated internally and stored in gplot.
Definition at line 776 of file gplot.c.
References gplotSimpleXY1(), and lept_mkdir().
[in] | na1 | numa; plot with Y_VS_I |
[in] | na2 | ditto |
[in] | title | [optional], can be NULL |
Notes: (1) This generates a pix with line plots of two numa, where each of two arrays is plotted vs the array index. the title is optional. (2) The temporary plot file is a png; its name is generated internally and stored in gplot.
Definition at line 819 of file gplot.c.
References gplotSimpleXY2(), and lept_mkdir().
[in] | naa | numaa; plot Y_VS_I for each numa |
[in] | title | [optional], can be NULL |
Notes: (1) This generates a pix with an arbitrary number of line plots, each coming from a numa in naa. Each array value is plotted vs the array index. The title is optional. (2) The temporary plot file is a png; its name is generated internally and stored in gplot.
Definition at line 863 of file gplot.c.
References gplotSimpleXYN(), and lept_mkdir().
GPLOT* gplotSimpleXY1 | ( | NUMA * | nax, |
NUMA * | nay, | ||
l_int32 | plotstyle, | ||
l_int32 | outformat, | ||
const char * | outroot, | ||
const char * | title | ||
) |
[in] | nax | [optional] |
[in] | nay | [required] |
[in] | plotstyle | GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES, GPLOT_LINESPOINTS, GPLOT_DOTS |
[in] | outformat | GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX, GPLOT_PNM |
[in] | outroot | root of output files |
[in] | title | [optional], can be NULL |
Notes: (1) This generates a plot of a nay vs nax, generated in the specified output format. The title is optional. (2) Use 0 for default plotstyle (lines). (3) nax is optional. If NULL, nay is plotted against the array index. (4) When calling these simple plot functions more than once, use different outroot to avoid overwriting the output files. (5) The returned gplot must be destroyed by the caller.
Definition at line 915 of file gplot.c.
Referenced by gplotSimple1(), and gplotSimplePix1().
GPLOT* gplotSimpleXY2 | ( | NUMA * | nax, |
NUMA * | nay1, | ||
NUMA * | nay2, | ||
l_int32 | plotstyle, | ||
l_int32 | outformat, | ||
const char * | outroot, | ||
const char * | title | ||
) |
[in] | nax | [optional], can be NULL |
[in] | nay1 | |
[in] | nay2 | |
[in] | plotstyle | GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES, GPLOT_LINESPOINTS, GPLOT_DOTS |
[in] | outformat | GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX, GPLOT_PNM |
[in] | outroot | root of output files |
[in] | title | [optional] |
Notes: (1) This generates plots of nay1 and nay2 against nax, generated in the specified output format. The title is optional. (2) Use 0 for default plotstyle (lines). (3) nax is optional. If NULL, nay1 and nay2 are plotted against the array index. (4) When calling these simple plot functions more than once, use different outroot to avoid overwriting the output files. (5) The returned gplot must be destroyed by the caller.
Definition at line 972 of file gplot.c.
Referenced by gplotSimple2(), and gplotSimplePix2().
GPLOT* gplotSimpleXYN | ( | NUMA * | nax, |
NUMAA * | naay, | ||
l_int32 | plotstyle, | ||
l_int32 | outformat, | ||
const char * | outroot, | ||
const char * | title | ||
) |
[in] | nax | [optional]; can be NULL |
[in] | naay | numaa of arrays to plot against nax |
[in] | plotstyle | GPLOT_LINES, GPLOT_POINTS, GPLOT_IMPULSES, GPLOT_LINESPOINTS, GPLOT_DOTS |
[in] | outformat | GPLOT_PNG, GPLOT_PS, GPLOT_EPS, GPLOT_LATEX, GPLOT_PNM |
[in] | outroot | root of output files |
[in] | title | [optional] |
Notes: (1) This generates plots of each Numa in naa against nax, generated in the specified output format. The title is optional. (2) Use 0 for default plotstyle (lines). (3) nax is optional. If NULL, each Numa array is plotted against the array index. (4) When calling these simple plot functions more than once, use different outroot to avoid overwriting the output files. (5) The returned gplot must be destroyed by the caller.
Definition at line 1031 of file gplot.c.
References numaaGetCount().
Referenced by gplotSimpleN(), and gplotSimplePixN().
l_ok gplotWrite | ( | const char * | filename, |
GPLOT * | gplot | ||
) |
[in] | filename | |
[in] | gplot |
Definition at line 1324 of file gplot.c.
References fopenWriteStream().
const char* gplotfileoutputs[] |