diff options
Diffstat (limited to 'analyzer')
-rw-r--r-- | analyzer/pamfind.c | 93 | ||||
-rw-r--r-- | analyzer/pamgetcolor.c | 6 | ||||
-rw-r--r-- | analyzer/pamsumm.c | 4 | ||||
-rw-r--r-- | analyzer/pamtable.c | 85 | ||||
-rw-r--r-- | analyzer/pamtilt.c | 13 | ||||
-rw-r--r-- | analyzer/pgmtexture.c | 101 | ||||
-rw-r--r-- | analyzer/pnmpsnr.c | 2 | ||||
-rw-r--r-- | analyzer/ppmhist.c | 44 |
8 files changed, 233 insertions, 115 deletions
diff --git a/analyzer/pamfind.c b/analyzer/pamfind.c index 860c01ff..15ca9e85 100644 --- a/analyzer/pamfind.c +++ b/analyzer/pamfind.c @@ -1,4 +1,6 @@ +#include <assert.h> #include <nstring.h> + #include <pam.h> #include "pm_c_util.h" @@ -9,11 +11,13 @@ typedef struct { unsigned int * target; unsigned int targetDepth; + unsigned int machine; const char * color; /* NULL means not specified */ const char * inputFileName; } CmdLineInfo; + static CmdLineInfo parsedCommandLine(int argc, const char ** const argv) { @@ -33,9 +37,10 @@ parsedCommandLine(int argc, MALLOCARRAY_NOFAIL(option_def, 100); option_def_index = 0; /* incremented by OPTENT3 */ - OPTENT3(0, "target", OPT_STRINGLIST, &target, &targetSpec, 0); - OPTENT3(0, "color", OPT_STRING, &cmdLine.color, &colorSpec, 0); - OPTENT3(0, 0, OPT_END, NULL, NULL, 0); + OPTENT3(0, "target", OPT_STRINGLIST, &target, &targetSpec, 0); + OPTENT3(0, "color", OPT_STRING, &cmdLine.color, &colorSpec, 0); + OPTENT3(0, "machine", OPT_FLAG, NULL, &cmdLine.machine, 0); + OPTENT3(0, 0, OPT_END, NULL, NULL, 0); opt.opt_table = option_def; opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ @@ -43,35 +48,37 @@ parsedCommandLine(int argc, pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); - if (targetSpec) { - if (colorSpec) - pm_error("You cannot specify both -target and -color"); - else { - unsigned int i; + if (targetSpec + colorSpec > 1) + pm_error("You cannot specify both -target and -color"); - cmdLine.color = NULL; + else if (targetSpec + colorSpec == 0) + pm_error("You must specify either -target or -color"); - cmdLine.target = NULL; /* initial value */ + else if (targetSpec) { + unsigned int i; - for (i = 0, cmdLine.targetDepth = 0; target[i]; ++i) { - unsigned int sampleVal; - const char * error; + cmdLine.color = NULL; - pm_string_to_uint(target[i], &sampleVal, &error); - if (error) { - pm_error("Invalid sample value in -target option: '%s'. " - "%s", target[i], error); - } + cmdLine.target = NULL; /* initial value */ - REALLOCARRAY(cmdLine.target, i+1); + for (i = 0, cmdLine.targetDepth = 0; target[i]; ++i) { + unsigned int sampleVal; + const char * error; - cmdLine.target[cmdLine.targetDepth++] = sampleVal; + pm_string_to_uint(target[i], &sampleVal, &error); + if (error) { + pm_error("Invalid sample value in -target option: '%s'. " + "%s", target[i], error); } - free(target); + REALLOCARRAY(cmdLine.target, i+1); + + cmdLine.target[cmdLine.targetDepth++] = sampleVal; } - } else if (!colorSpec) - pm_error("You must specify either -target or -color"); + + free(target); + } else + assert (colorSpec == 1); if (argc-1 < 1) cmdLine.inputFileName = "-"; @@ -118,7 +125,7 @@ targetValue(CmdLineInfo const cmdLine, } else { if (cmdLine.targetDepth != inpamP->depth) pm_error("You specified a %u-tuple for -target, " - "but the input image of of depth %u", + "but the input image is of depth %u", cmdLine.targetDepth, inpamP->depth); else { unsigned int i; @@ -161,6 +168,29 @@ printHeader(FILE * const ofP, +static unsigned int +decimalDigitCt(unsigned int const n) { +/*---------------------------------------------------------------------------- + Minimum number of digits needed to display 'n' in decimal. +-----------------------------------------------------------------------------*/ + unsigned int digitCt; + + if (n == 0) + digitCt = 1; + else { + unsigned int x; + + for (digitCt = 0, x = n; x > 0;) { + ++digitCt; + x /= 10; + } + assert(digitCt > 0); + } + return digitCt; +} + + + static void pamfind(FILE * const ifP, struct pam * const inpamP, @@ -174,8 +204,16 @@ pamfind(FILE * const ifP, tuple const target = targetValue(cmdLine, inpamP); unsigned int row; - - printHeader(ofP, inpamP, target); + const char * fmt; + + if (cmdLine.machine) { + pm_asprintf(&fmt, "%%0%uu %%0%uu\n", + decimalDigitCt(inpamP->height-1), + decimalDigitCt(inpamP->width-1)); + } else { + printHeader(ofP, inpamP, target); + fmt = pm_strdup("(%u, %u)\n"); + } for (row = 0; row < inpamP->height; ++row) { unsigned int col; @@ -185,10 +223,11 @@ pamfind(FILE * const ifP, for (col = 0; col < inpamP->width; ++col) { if (pnm_tupleequal(inpamP, target, inputRow[col])) { - fprintf(ofP, "(%u, %u)\n", row, col); + fprintf(ofP, fmt, row, col); } } } + pm_strfree(fmt); pnm_freepamtuple(target); pnm_freepamrow(inputRow); } diff --git a/analyzer/pamgetcolor.c b/analyzer/pamgetcolor.c index 430f3b07..d1ea3799 100644 --- a/analyzer/pamgetcolor.c +++ b/analyzer/pamgetcolor.c @@ -37,7 +37,7 @@ typedef struct { uint regN; /* number of regions */ uint maxLbLen; /* maximum label length */ RegSpec * regSpecs; - /* list of points to sample, dymamically allocated*/ + /* list of points to sample, dynamically allocated*/ const char * formatStr; /* output color format as string */ uint formatId; /* the Id of the selected color format */ uint formatArg; /* the argument to the color formatting function */ @@ -45,9 +45,9 @@ typedef struct { } CmdLineInfo; /* Generic pointer to a color-formatting function. Returns the textual - representation of the color <tuple> in terms of the image pointed-to + representation of the color <tuple> in terms of the image pointed to by <pamP>. <param> is a generic integer parameter that depends on the - specific funcion and may denote precison or maxval. + specific function and may denote precision or maxval. */ typedef const char * (*FormatColor)(struct pam * const pamP, diff --git a/analyzer/pamsumm.c b/analyzer/pamsumm.c index 9b74e789..03ff6749 100644 --- a/analyzer/pamsumm.c +++ b/analyzer/pamsumm.c @@ -58,8 +58,8 @@ parseCommandLine(int argc, const char ** const argv, pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ - if (sumSpec + minSpec + maxSpec > 1) - pm_error("You may specify at most one of -sum, -min, and -max"); + if (sumSpec + minSpec + maxSpec + meanSpec > 1) + pm_error("You may specify at most one of -sum, -min, -max, and -mean"); if (sumSpec) { cmdlineP->function = FN_ADD; diff --git a/analyzer/pamtable.c b/analyzer/pamtable.c index 2835469a..acd027a6 100644 --- a/analyzer/pamtable.c +++ b/analyzer/pamtable.c @@ -15,12 +15,16 @@ #include "mallocvar.h" #include "nstring.h" +enum Style {STYLE_BASIC, STYLE_TUPLE}; + struct CmdlineInfo { /* All the information the user supplied in the command line, in a form easy for the program to use. */ const char * inputFileName; /* Name of input file */ - unsigned int verbose; + enum Style outputStyle; + unsigned int hex; + unsigned int verbose; }; @@ -34,11 +38,14 @@ parseCommandLine(int argc, const char ** const argv, optStruct3 opt; unsigned int option_def_index; + unsigned int tuple; MALLOCARRAY(option_def, 100); option_def_index = 0; /* incremented by OPTENT3 */ + OPTENT3(0, "tuple", OPT_FLAG, NULL, &tuple, 0); + OPTENT3(0, "hex", OPT_FLAG, NULL, &cmdlineP->hex, 0); OPTENT3(0, "verbose", OPT_FLAG, NULL, &cmdlineP->verbose, 0); /* For future expansion */ @@ -49,6 +56,14 @@ parseCommandLine(int argc, const char ** const argv, pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); /* Uses and sets argc, argv, and some of *cmdlineP and others. */ + if (tuple && cmdlineP->hex) + pm_error("-hex is invalid with -tuple"); + + if (tuple) + cmdlineP->outputStyle = STYLE_TUPLE; + else + cmdlineP->outputStyle = STYLE_BASIC; + if (argc-1 > 1) pm_error("Too many arguments (%d). File name is the only argument.", argc-1); @@ -74,12 +89,27 @@ typedef struct { const char * interTupleGutter; /* What we print between tuples within a row */ + const char * rowStartString; + /* What we print at the beginning of each row */ + + const char * rowEndString; + /* What we print at the end of each row */ + } Format; +static double const +log16(double const arg) { + + return log(arg)/log(16); +} + + + static const char * -sampleFormat(const struct pam * const pamP) { +basicSampleFormat(const struct pam * const pamP, + bool const wantHex) { /*---------------------------------------------------------------------------- The printf format string for a single sample in the output table. @@ -87,11 +117,21 @@ sampleFormat(const struct pam * const pamP) { This format does not include any spacing between samples. -----------------------------------------------------------------------------*/ - unsigned int const decimalWidth = ROUNDU(ceil(log10(pamP->maxval + 1))); - + unsigned int cipherWidth; + char formatSpecifier; + const char * flag; const char * retval; - pm_asprintf(&retval, "%%%uu", decimalWidth); + if (wantHex) { + formatSpecifier = 'x'; + cipherWidth = ROUNDU(ceil(log16(pamP->maxval + 1))); + flag = "0"; + } else { + formatSpecifier = 'u'; + cipherWidth = ROUNDU(ceil(log10(pamP->maxval + 1))); + flag = ""; + } + pm_asprintf(&retval, "%%%s%u%c", flag, cipherWidth, formatSpecifier); return retval; } @@ -100,13 +140,26 @@ sampleFormat(const struct pam * const pamP) { static void makeFormat(const struct pam * const pamP, + enum Style const outputStyle, + bool const wantHex, Format * const formatP) { - formatP->sampleFmt = sampleFormat(pamP); - - formatP->interSampleGutter = " "; - - formatP->interTupleGutter = pamP->depth > 1 ? "|" : " "; + switch (outputStyle) { + case STYLE_BASIC: + formatP->sampleFmt = basicSampleFormat(pamP, wantHex); + formatP->interSampleGutter = " "; + formatP->interTupleGutter = pamP->depth > 1 ? "|" : " "; + formatP->rowStartString = ""; + formatP->rowEndString = "\n"; + break; + case STYLE_TUPLE: + formatP->sampleFmt = pm_strdup("%u"); + formatP->interSampleGutter = ","; + formatP->interTupleGutter = ") ("; + formatP->rowStartString = "("; + formatP->rowEndString = ")\n"; + break; + } } @@ -127,6 +180,8 @@ printRow(const struct pam * const pamP, unsigned int col; + fputs (format.rowStartString, ofP); + for (col = 0; col < pamP->width; ++col) { unsigned int plane; @@ -142,7 +197,7 @@ printRow(const struct pam * const pamP, } } - fputs("\n", ofP); + fputs (format.rowEndString, ofP); } @@ -150,14 +205,16 @@ printRow(const struct pam * const pamP, static void printRaster(FILE * const ifP, const struct pam * const pamP, - FILE * const ofP) { + FILE * const ofP, + enum Style const outputStyle, + bool const wantHex) { Format format; tuple * inputRow; /* Row from input image */ unsigned int row; - makeFormat(pamP, &format); + makeFormat(pamP, outputStyle, wantHex, &format); inputRow = pnm_allocpamrow(pamP); @@ -189,7 +246,7 @@ main(int argc, const char *argv[]) { pnm_readpaminit(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); - printRaster(ifP, &inpam, stdout); + printRaster(ifP, &inpam, stdout, cmdline.outputStyle, cmdline.hex); pm_close(inpam.file); diff --git a/analyzer/pamtilt.c b/analyzer/pamtilt.c index 70338545..2898d30f 100644 --- a/analyzer/pamtilt.c +++ b/analyzer/pamtilt.c @@ -143,7 +143,7 @@ load(const struct pam * const pamP, sample ** pixels; tuplerow = pnm_allocpamrow(pamP); - + MALLOCARRAY(pixels, pamP->height); if (pixels == NULL) @@ -221,7 +221,7 @@ totalBrightness(sample ** const pixels, /*---------------------------------------------------------------------------- Total brightness of samples in the line that goes from the left edge of Row 'startRow' of 'pixels' down to the right at 'dy' rows per column. - + Note that 'dy' can be negative. Assume that whatever 'dy' is, the sloping line thus described remains @@ -319,7 +319,7 @@ scoreAngle(const struct pam * const pamP, If 'angle' is so great that not a single line goes all the way across the page without running off the top or bottom, we call the score -1. In every other case, it is nonnegative. - + 'pixels' is NOT all the pixels in the image; it is just a sampling. In each row, it contains only 'hsampleCt' pixels, sampled from the image at intervals of 'hstep' pixels. E.g if the image is 1000 @@ -468,7 +468,7 @@ readSampledPixels(const char * const inputFilename, *hstepP = hstep; *vstepP = vstep; - + pm_close(ifP); } @@ -490,7 +490,7 @@ getAngle(const struct pam * const pamP, float a; float da; float lastq; /* quality (s/n ratio) of last measurement */ - + getBestAngleLocal(pamP, pixels, hstep, vstep, hsampleCt, -maxangle, maxangle, astep, verbose, &a, &lastq); @@ -551,3 +551,6 @@ main(int argc, const char ** argv) { return 0; } + + + diff --git a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c index 4e0dd4d5..5af51bf5 100644 --- a/analyzer/pgmtexture.c +++ b/analyzer/pgmtexture.c @@ -1,49 +1,5 @@ /* pgmtexture.c - calculate textural features of a PGM image ** -** Author: James Darrell McCauley -** Texas Agricultural Experiment Station -** Department of Agricultural Engineering -** Texas A&M University -** College Station, Texas 77843-2117 USA -** -** Code written partially taken from pgmtofs.c in the PBMPLUS package -** by Jef Poskanzer. -** -** Algorithms for calculating features (and some explanatory comments) are -** taken from: -** -** Haralick, R.M., K. Shanmugam, and I. Dinstein. 1973. Textural features -** for image classification. IEEE Transactions on Systems, Man, and -** Cybertinetics, SMC-3(6):610-621. -** -** Copyright (C) 1991 Texas Agricultural Experiment Station, employer for -** hire of James Darrell McCauley -** -** Permission to use, copy, modify, and distribute this software and its -** documentation for any purpose and without fee is hereby granted, provided -** that the above copyright notice appear in all copies and that both that -** copyright notice and this permission notice appear in supporting -** documentation. This software is provided "as is" without express or -** implied warranty. -** -** THE TEXAS AGRICULTURAL EXPERIMENT STATION (TAES) AND THE TEXAS A&M -** UNIVERSITY SYSTEM (TAMUS) MAKE NO EXPRESS OR IMPLIED WARRANTIES -** (INCLUDING BY WAY OF EXAMPLE, MERCHANTABILITY) WITH RESPECT TO ANY -** ITEM, AND SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL -** OR CONSEQUENTAL DAMAGES ARISING OUT OF THE POSESSION OR USE OF -** ANY SUCH ITEM. LICENSEE AND/OR USER AGREES TO INDEMNIFY AND HOLD -** TAES AND TAMUS HARMLESS FROM ANY CLAIMS ARISING OUT OF THE USE OR -** POSSESSION OF SUCH ITEMS. -** -** Modification History: -** 24 Jun 91 - J. Michael Carstensen <jmc@imsor.dth.dk> supplied fix for -** correlation function. -** -** 05 Oct 05 - Marc Breithecker <Marc.Breithecker@informatik.uni-erlangen.de> -** Fix calculation or normalizing constants for d > 1. -** 9 Jul 11 - Francois P. S. Luus <fpsluus@gmail.com> supplied fix for sum -** variance calculation (use F6:savg instead of F8:sentropy in -** F7:svar equation). */ @@ -93,7 +49,16 @@ static bool const sortit = FALSE; static float * vector(unsigned int const nl, unsigned int const nh) { +/*---------------------------------------------------------------------------- + Allocate a float vector with range [nl..nh] + + We do some seedy C here, subtracting an arbitrary integer from a pointer and + calling the result a pointer. It normally works because the only way we'll + use that pointer is by adding that same integer or something greater to it. + The point of this is not to allocate memory for vector elements that will + never be referenced (component < nl). +-----------------------------------------------------------------------------*/ float * v; unsigned int i; @@ -1175,3 +1140,51 @@ main (int argc, const char ** argv) { return 0; } + + +/* +** Author: James Darrell McCauley +** Texas Agricultural Experiment Station +** Department of Agricultural Engineering +** Texas A&M University +** College Station, Texas 77843-2117 USA +** +** Code written partially taken from pgmtofs.c in the PBMPLUS package +** by Jef Poskanzer. +** +** Algorithms for calculating features (and some explanatory comments) are +** taken from: +** +** Haralick, R.M., K. Shanmugam, and I. Dinstein. 1973. Textural features +** for image classification. IEEE Transactions on Systems, Man, and +** Cybertinetics, SMC-3(6):610-621. +** +** Copyright (C) 1991 Texas Agricultural Experiment Station, employer for +** hire of James Darrell McCauley +** +** Permission to use, copy, modify, and distribute this software and its +** documentation for any purpose and without fee is hereby granted, provided +** that the above copyright notice appear in all copies and that both that +** copyright notice and this permission notice appear in supporting +** documentation. This software is provided "as is" without express or +** implied warranty. +** +** THE TEXAS AGRICULTURAL EXPERIMENT STATION (TAES) AND THE TEXAS A&M +** UNIVERSITY SYSTEM (TAMUS) MAKE NO EXPRESS OR IMPLIED WARRANTIES +** (INCLUDING BY WAY OF EXAMPLE, MERCHANTABILITY) WITH RESPECT TO ANY +** ITEM, AND SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL +** OR CONSEQUENTAL DAMAGES ARISING OUT OF THE POSSESSION OR USE OF +** ANY SUCH ITEM. LICENSEE AND/OR USER AGREES TO INDEMNIFY AND HOLD +** TAES AND TAMUS HARMLESS FROM ANY CLAIMS ARISING OUT OF THE USE OR +** POSSESSION OF SUCH ITEMS. +** +** Modification History: +** 24 Jun 91 - J. Michael Carstensen <jmc@imsor.dth.dk> supplied fix for +** correlation function. +** +** 05 Oct 05 - Marc Breithecker <Marc.Breithecker@informatik.uni-erlangen.de> +** Fix calculation or normalizing constants for d > 1. +** 9 Jul 11 - Francois P. S. Luus <fpsluus@gmail.com> supplied fix for sum +** variance calculation (use F6:savg instead of F8:sentropy in +** F7:svar equation). +*/ diff --git a/analyzer/pnmpsnr.c b/analyzer/pnmpsnr.c index 2363e8c3..6543c542 100644 --- a/analyzer/pnmpsnr.c +++ b/analyzer/pnmpsnr.c @@ -179,7 +179,7 @@ validateInput(struct pam const pam1, pam1.height, pam2.height); if (pam1.maxval != pam2.maxval) - pm_error("images do not have the same maxval. This programs works " + pm_error("images do not have the same maxval. This program works " "only on like maxvals. " "The first image has maxval %u, " "while the second has %u. Use Pamdepth to change the " diff --git a/analyzer/ppmhist.c b/analyzer/ppmhist.c index c4ab3581..62345fa1 100644 --- a/analyzer/ppmhist.c +++ b/analyzer/ppmhist.c @@ -120,25 +120,6 @@ cmpUint(unsigned int const a, #ifndef LITERAL_FN_DEF_MATCH -static qsort_comparison_fn countcompare; -#endif - - -static int -countcompare(const void * const a, - const void * const b) { -/*---------------------------------------------------------------------------- - This is a 'qsort' collation function. ------------------------------------------------------------------------------*/ - const struct colorhist_item * const histItem1P = a; - const struct colorhist_item * const histItem2P = b; - - return cmpUint(histItem2P->value, histItem1P->value); -} - - - -#ifndef LITERAL_FN_DEF_MATCH static qsort_comparison_fn rgbcompare; #endif @@ -167,6 +148,31 @@ rgbcompare(const void * const a, +#ifndef LITERAL_FN_DEF_MATCH +static qsort_comparison_fn countcompare; +#endif + + +static int +countcompare(const void * const a, + const void * const b) { +/*---------------------------------------------------------------------------- + This is a 'qsort' collation function. +-----------------------------------------------------------------------------*/ + const struct colorhist_item * const histItem1P = a; + const struct colorhist_item * const histItem2P = b; + + int const countComparison = cmpUint(histItem2P->value, histItem1P->value); + + if (countComparison == 0) { + /* Counts are the same; use RGB secondary sort */ + return rgbcompare(a, b); + } else + return countComparison; +} + + + static pixval universalMaxval(pixval const maxval, int const format) { |