diff options
Diffstat (limited to 'analyzer')
-rw-r--r-- | analyzer/pamfile.c | 28 | ||||
-rw-r--r-- | analyzer/pamgetcolor.c | 6 | ||||
-rw-r--r-- | analyzer/pamsharpmap.c | 26 | ||||
-rw-r--r-- | analyzer/pamsharpness.c | 26 | ||||
-rw-r--r-- | analyzer/pamslice.c | 22 | ||||
-rw-r--r-- | analyzer/pbmminkowski.c | 62 | ||||
-rw-r--r-- | analyzer/pgmhist.c | 6 | ||||
-rw-r--r-- | analyzer/pgmminkowski.c | 100 | ||||
-rw-r--r-- | analyzer/pgmtexture.c | 840 | ||||
-rw-r--r-- | analyzer/pnmhistmap.c | 28 |
10 files changed, 715 insertions, 429 deletions
diff --git a/analyzer/pamfile.c b/analyzer/pamfile.c index 7b61f6fd..6e12375f 100644 --- a/analyzer/pamfile.c +++ b/analyzer/pamfile.c @@ -92,30 +92,30 @@ dumpHeaderHuman(struct pam const pam) { printf(" Tuple type: %s\n", pam.tuple_type); break; - case PBM_FORMAT: + case PBM_FORMAT: printf("PBM plain, %d by %d\n", pam.width, pam.height ); break; - case RPBM_FORMAT: + case RPBM_FORMAT: printf("PBM raw, %d by %d\n", pam.width, pam.height); break; - case PGM_FORMAT: + case PGM_FORMAT: printf("PGM plain, %d by %d maxval %ld\n", pam.width, pam.height, pam.maxval); break; - case RPGM_FORMAT: + case RPGM_FORMAT: printf("PGM raw, %d by %d maxval %ld\n", pam.width, pam.height, pam.maxval); break; - case PPM_FORMAT: + case PPM_FORMAT: printf("PPM plain, %d by %d maxval %ld\n", pam.width, pam.height, pam.maxval); break; - case RPPM_FORMAT: + case RPPM_FORMAT: printf("PPM raw, %d by %d maxval %ld\n", pam.width, pam.height, pam.maxval); break; @@ -136,32 +136,32 @@ dumpHeaderMachine(struct pam const pam) { plain = false; break; - case PBM_FORMAT: + case PBM_FORMAT: formatString = "PBM"; plain = TRUE; break; - case RPBM_FORMAT: + case RPBM_FORMAT: formatString = "PBM"; plain = false; break; - case PGM_FORMAT: + case PGM_FORMAT: formatString = "PGM"; plain = TRUE; break; - case RPGM_FORMAT: + case RPGM_FORMAT: formatString = "PGM"; plain = false; break; - case PPM_FORMAT: + case PPM_FORMAT: formatString = "PPM"; plain = TRUE; break; - case RPPM_FORMAT: + case RPPM_FORMAT: formatString = "PPM"; plain = false; break; } @@ -340,8 +340,8 @@ main(int argc, const char *argv[]) { cmdline.comments); pm_close(ifP); - } - } + } + } return 0; } diff --git a/analyzer/pamgetcolor.c b/analyzer/pamgetcolor.c index d1ea3799..2bd3050c 100644 --- a/analyzer/pamgetcolor.c +++ b/analyzer/pamgetcolor.c @@ -1,4 +1,8 @@ +#define _C99_SOURCE /* Make sure snprintf() is in stdio.h */ + #include <string.h> +#include <stdio.h> + #include <nstring.h> #include <pm_gamma.h> #include <pam.h> @@ -526,7 +530,7 @@ printColors(struct pam * const pamP, tup = pnm_allocpamtuple(pamP); - pm_snprintf(fmt, sizeof(fmt), "%%%is: %%s\n", cmdLine.maxLbLen); + snprintf(fmt, sizeof(fmt), "%%%is: %%s\n", cmdLine.maxLbLen); for (r = 0; r < cmdLine.regN; ++r) { RegSpec spec; diff --git a/analyzer/pamsharpmap.c b/analyzer/pamsharpmap.c index 2f31835b..f63760fe 100644 --- a/analyzer/pamsharpmap.c +++ b/analyzer/pamsharpmap.c @@ -14,7 +14,7 @@ No warranty. See file 'artistic.license' for more details. boris@13thmonkey.org - www.13thmonkey.org/~boris/photopnmtools/ + www.13thmonkey.org/~boris/photopnmtools/ -----------------------------------------------------------------------------*/ #include <stdio.h> @@ -40,7 +40,7 @@ parseCommandLine ( int argc, char ** argv, struct cmdlineInfo *cmdlineP ) { /*---------------------------------------------------------------------------- parse program command line described in Unix standard form by argc - and argv. Return the information in the options as *cmdlineP. + and argv. Return the information in the options as *cmdlineP. If command line is internally inconsistent (invalid options, etc.), issue error message to stderr and abort program. @@ -58,7 +58,7 @@ parseCommandLine ( int argc, char ** argv, unsigned int contextSpec; option_def_index = 0; /* incremented by OPTENT3 */ - OPTENT3(0, "context", OPT_UINT, &cmdlineP->context, + OPTENT3(0, "context", OPT_UINT, &cmdlineP->context, &contextSpec, 0 ); opt.opt_table = option_def; @@ -92,7 +92,7 @@ makeSharpnessPixel(struct pam * const pamP, unsigned int plane; for (plane = 0; plane < pamP->depth; ++plane) - sharpnessTuple[plane] = + sharpnessTuple[plane] = (sample)(sharpness[plane] * pamP->maxval + 0.5); } @@ -132,20 +132,20 @@ main(int argc, char **argv) { int row; float * sharpness; - pnm_init(&argc, argv); + pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); - tuplenarray = pnm_readpamn(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); + tuplenarray = pnm_readpamn(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); mappam = inpam; mappam.file = stdout; mappam.maxval = 255; MALLOCARRAY_NOFAIL(sharpness, inpam.depth); - + map = pnm_allocpamarray(&mappam); makeBlackRown(&inpam, tuplenarray[0]); for (row = 1; row < inpam.height-1; ++row) { @@ -154,7 +154,7 @@ main(int argc, char **argv) { for (col = 1; col < inpam.width-1; ++col) { int dy; unsigned int plane; - + for (plane = 0; plane < inpam.depth; ++plane) sharpness[plane] = 0.0; @@ -164,9 +164,9 @@ main(int argc, char **argv) { if (dx != 0 || dy != 0) { unsigned int plane; for (plane = 0; plane < inpam.depth; ++plane) { - samplen const sampleval = + samplen const sampleval = tuplenarray[row][col][plane]; - samplen const sampleval2 = + samplen const sampleval2 = tuplenarray[row+dy][col+dx][plane]; sharpness[plane] += fabs(sampleval - sampleval2); } @@ -179,11 +179,11 @@ main(int argc, char **argv) { } makeBlackRown(&inpam, tuplenarray[inpam.height-1]); free(sharpness); - + pnm_writepam(&mappam, map); pnm_freepamarray(map, &mappam); - pnm_freepamarrayn(tuplenarray, &inpam); + pnm_freepamarrayn(tuplenarray, &inpam); - return 0; + return 0; } diff --git a/analyzer/pamsharpness.c b/analyzer/pamsharpness.c index 5943416f..f9140bcf 100644 --- a/analyzer/pamsharpness.c +++ b/analyzer/pamsharpness.c @@ -14,7 +14,7 @@ No warranty. See file 'artistic.license' for more details. boris@13thmonkey.org - www.13thmonkey.org/~boris/photopnmtools/ + www.13thmonkey.org/~boris/photopnmtools/ -----------------------------------------------------------------------------*/ #include <stdio.h> @@ -40,7 +40,7 @@ parseCommandLine(int argc, char ** argv, struct cmdlineInfo *cmdlineP) { /*---------------------------------------------------------------------------- parse program command line described in Unix standard form by argc - and argv. Return the information in the options as *cmdlineP. + and argv. Return the information in the options as *cmdlineP. If command line is internally inconsistent (invalid options, etc.), issue error message to stderr and abort program. @@ -60,7 +60,7 @@ parseCommandLine(int argc, char ** argv, MALLOCARRAY_NOFAIL(option_def, 100); option_def_index = 0; /* incremented by OPTENT3 */ - OPTENT3(0, "context", OPT_UINT, &cmdlineP->context, + OPTENT3(0, "context", OPT_UINT, &cmdlineP->context, &contextSpec, 0 ); opt.opt_table = option_def; @@ -96,7 +96,7 @@ computeSharpness(struct pam * const inpamP, unsigned int row; double totsharp; - + totsharp = 0.0; for (row = 1; row < inpamP->height-1; ++row) { @@ -109,18 +109,18 @@ computeSharpness(struct pam * const inpamP, if (dx != 0 || dy != 0) { unsigned int plane; for (plane = 0; plane < inpamP->depth; ++plane) { - samplen const sampleval = + samplen const sampleval = tuplenarray[row][col][plane]; - samplen const sampleval2 = + samplen const sampleval2 = tuplenarray[row+dy][col+dx][plane]; totsharp += fabs(sampleval - sampleval2); } } } } - } - } - *sharpnessP = + } + } + *sharpnessP = totsharp / (inpamP->width * inpamP->height * inpamP->depth * 8); /* The 8 above is for the 8 neighbors to which we compare each pixel */ } @@ -136,13 +136,13 @@ main(int argc, char **argv) { struct pam inpam; double sharpness; - pnm_init(&argc, argv); + pnm_init(&argc, argv); parseCommandLine(argc, argv, &cmdline); ifP = pm_openr(cmdline.inputFilespec); - tuplenarray = pnm_readpamn(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); + tuplenarray = pnm_readpamn(ifP, &inpam, PAM_STRUCT_SIZE(tuple_type)); if (inpam.height < 3 || inpam.width < 3) pm_error("sharpness is undefined for an image less than 3 pixels " @@ -153,8 +153,8 @@ main(int argc, char **argv) { printf("Sharpness = %f\n", sharpness); - pnm_freepamarrayn(tuplenarray, &inpam); + pnm_freepamarrayn(tuplenarray, &inpam); pm_close(ifP); - return 0; + return 0; } diff --git a/analyzer/pamslice.c b/analyzer/pamslice.c index db0ab9c0..5bdbea10 100644 --- a/analyzer/pamslice.c +++ b/analyzer/pamslice.c @@ -1,4 +1,4 @@ -/* +/* * * This program (Pamslice) was derived by Bryan Henderson in July 2002 * from Pgmslice by Jos Dingjan. Pgmslice did the same thing, but @@ -10,10 +10,10 @@ * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License @@ -77,12 +77,12 @@ parseCommandLine(int argc, char ** const argv, if (argc-1 > 1) pm_error("Too many arguments (%d). Only argument is filename.", argc-1); - else if (argc-1 == 1) + else if (argc-1 == 1) cmdlineP->inputFilespec = argv[1]; else cmdlineP->inputFilespec = "-"; - if (rowSpec) + if (rowSpec) cmdlineP->orientation = ROW; else if (colSpec) cmdlineP->orientation = COLUMN; @@ -121,7 +121,7 @@ printSlice(FILE * const outfile, else fprintf(stdout,"@ type nxy\n"); } - + count = 0; for (row = rowstart; row < rowend; ++row) { unsigned int col; @@ -137,7 +137,7 @@ printSlice(FILE * const outfile, -int +int main(int argc, char *argv[]) { struct cmdlineInfo cmdline; @@ -177,7 +177,7 @@ main(int argc, char *argv[]) { break; } - + if (cmdline.onePlane) { if (cmdline.plane >= inpam.depth) pm_error("You specified plane %u, but there are only %u planes " @@ -189,12 +189,12 @@ main(int argc, char *argv[]) { planeend = inpam.depth; } - printSlice(stdout, tuples, + printSlice(stdout, tuples, rowstart, rowend, colstart, colend, planestart, planeend, cmdline.xmgr); pm_close(ifP); pm_close(stdout); - + exit(0); } diff --git a/analyzer/pbmminkowski.c b/analyzer/pbmminkowski.c index 0f7b47a9..368ff34e 100644 --- a/analyzer/pbmminkowski.c +++ b/analyzer/pbmminkowski.c @@ -25,15 +25,15 @@ int main(int argc, const char ** argv) { bit * prevrow; bit * thisrow; bit * tmprow; - + int row; - int col; + int col; int countTile; int countEdgeX; int countEdgeY; int countVertex; - + int rows; int cols; int format; @@ -42,15 +42,15 @@ int main(int argc, const char ** argv) { pm_proginit(&argc, argv); - + if (argc > 2) pm_usage("[pbmfile]"); - + if (argc == 2) ifP = pm_openr(argv[1]); else ifP = stdin; - + pbm_readpbminit(ifP, &cols, &rows, &format); prevrow = pbm_allocrow(cols); @@ -68,10 +68,10 @@ int main(int argc, const char ** argv) { /* tiles */ - for (col = 0; col < cols; ++col) + for (col = 0; col < cols; ++col) if (ISWHITE(thisrow[col])) ++countTile; - + /* shortcut: for the first row, edgeY == countTile */ countEdgeY = countTile; @@ -80,7 +80,7 @@ int main(int argc, const char ** argv) { if (ISWHITE(thisrow[0])) ++countEdgeX; - for (col = 0; col < cols-1; ++col) + for (col = 0; col < cols-1; ++col) if (ISWHITE(thisrow[col]) || ISWHITE(thisrow[col+1])) ++countEdgeX; @@ -88,56 +88,56 @@ int main(int argc, const char ** argv) { ++countEdgeX; /* shortcut: for the first row, countVertex == countEdgeX */ - + countVertex = countEdgeX; - - for (row = 1; row < rows; ++row) { - - tmprow = prevrow; + + for (row = 1; row < rows; ++row) { + + tmprow = prevrow; prevrow = thisrow; thisrow = tmprow; - + pbm_readpbmrow(ifP, thisrow, cols, format); - + /* tiles */ - for (col = 0; col < cols; ++col) + for (col = 0; col < cols; ++col) if (ISWHITE(thisrow[col])) ++countTile; - + /* y-edges */ - for (col = 0; col < cols; ++col) + for (col = 0; col < cols; ++col) if (ISWHITE(thisrow[col]) || ISWHITE(prevrow[col])) ++countEdgeY; - + /* x-edges */ if (ISWHITE(thisrow[0])) ++countEdgeX; - for (col = 0; col < cols-1; ++col) + for (col = 0; col < cols-1; ++col) if (ISWHITE(thisrow[col]) || ISWHITE(thisrow[col+1])) ++countEdgeX; - + if (ISWHITE(thisrow[cols-1])) ++countEdgeX; - + /* vertices */ if (ISWHITE(thisrow[0]) || ISWHITE(prevrow[0])) ++countVertex; - for (col = 0; col < cols-1; ++col) - if (ISWHITE(thisrow[col]) || ISWHITE(thisrow[col+1]) + for (col = 0; col < cols-1; ++col) + if (ISWHITE(thisrow[col]) || ISWHITE(thisrow[col+1]) || ISWHITE(prevrow[col]) || ISWHITE(prevrow[col+1])) ++countVertex; if (ISWHITE(thisrow[cols-1]) || ISWHITE(prevrow[cols-1])) ++countVertex; - + } /* for row */ /* now thisrow contains the top row*/ @@ -145,19 +145,19 @@ int main(int argc, const char ** argv) { vertices remain */ - + /* y-edges */ - for (col = 0; col < cols; ++col) + for (col = 0; col < cols; ++col) if (ISWHITE(thisrow[col])) ++countEdgeY; /* vertices */ - + if (ISWHITE(thisrow[0])) ++countVertex; - for (col = 0; col < cols-1; ++col) + for (col = 0; col < cols-1; ++col) if (ISWHITE(thisrow[col]) || ISWHITE(thisrow[col+1])) ++countVertex; @@ -179,7 +179,7 @@ int main(int argc, const char ** argv) { printf(" area:\t%d\nperimeter:\t%d\n eulerchi:\t%d\n", area, perimeter, eulerchi ); - + return 0; } diff --git a/analyzer/pgmhist.c b/analyzer/pgmhist.c index 1e779655..a85f0649 100644 --- a/analyzer/pgmhist.c +++ b/analyzer/pgmhist.c @@ -211,8 +211,8 @@ findQuantiles(unsigned int const n, cumCt = hist[0]; /* initial value */ for (quantSeq = 1; quantSeq <= n; ++quantSeq) { - unsigned long int const q = totalCt / n; - unsigned long int const r = totalCt % n; + unsigned long int const q = totalCt / n; + unsigned long int const r = totalCt % n; unsigned long int const quantCt = q*quantSeq + (r*quantSeq + n - 1)/n; /* This is how many pixels are (ignoring quantization) in the quantile. E.g. for the 3rd quartile, it is 3/4 of the pixels @@ -419,7 +419,7 @@ summarizeInvalidPixels(unsigned long int const hist[], Print total count of valid and invalid pixels, if there are any invalid ones. -----------------------------------------------------------------------------*/ - unsigned long int const invalidPixelCt = + unsigned long int const invalidPixelCt = mmaxval > maxval ? rcount[maxval+1] : 0; if (invalidPixelCt > 0) { diff --git a/analyzer/pgmminkowski.c b/analyzer/pgmminkowski.c index dfb08429..676dd567 100644 --- a/analyzer/pgmminkowski.c +++ b/analyzer/pgmminkowski.c @@ -1,9 +1,9 @@ -/* pgmminkowsky.c - read a portable graymap and calculate the Minkowski +/* pgmminkowsky.c - read a portable graymap and calculate the Minkowski ** Integrals as a function of the threshold. ** ** Copyright (C) 2000 by Luuk van Dijk/Mind over Matter ** -** Based on pgmhist.c, +** Based on pgmhist.c, ** Copyright (C) 1989 by Jef Poskanzer. ** ** Permission to use, copy, modify, and distribute this software and its @@ -22,7 +22,7 @@ #define MAX4(a,b,c,d) MAX2( MAX2((a),(b)), MAX2((c),(d)) ) int main( int argc, char** argv ){ - + FILE *ifp; gray maxval; @@ -31,11 +31,11 @@ int main( int argc, char** argv ){ gray* prevrow; gray* thisrow; gray* tmprow; - - int* countTile; - int* countEdgeX; - int* countEdgeY; - int* countVertex; + + int* countTile; + int* countEdgeX; + int* countEdgeY; + int* countVertex; int i, col, row; @@ -46,12 +46,12 @@ int main( int argc, char** argv ){ /* * parse arg and initialize - */ + */ pgm_init( &argc, argv ); if ( argc > 2 ) pm_usage( "[pgmfile]" ); - + if ( argc == 2 ) ifp = pm_openr( argv[1] ); else @@ -62,19 +62,19 @@ int main( int argc, char** argv ){ */ pgm_readpgminit( ifp, &cols, &rows, &maxval, &format ); - + prevrow = pgm_allocrow( cols ); thisrow = pgm_allocrow( cols ); - + MALLOCARRAY(countTile , maxval + 1 ); MALLOCARRAY(countEdgeX , maxval + 1 ); MALLOCARRAY(countEdgeY , maxval + 1 ); MALLOCARRAY(countVertex , maxval + 1 ); - + if (countTile == NULL || countEdgeX == NULL || countEdgeY == NULL || countVertex == NULL) pm_error( "out of memory" ); - + for ( i = 0; i <= maxval; i++ ) countTile[i] = 0; for ( i = 0; i <= maxval; i++ ) countEdgeX[i] = 0; for ( i = 0; i <= maxval; i++ ) countEdgeY[i] = 0; @@ -89,84 +89,84 @@ int main( int argc, char** argv ){ /* tiles */ - for ( col = 0; col < cols; ++col ) ++countTile[thisrow[col]]; - + for ( col = 0; col < cols; ++col ) ++countTile[thisrow[col]]; + /* y-edges */ - for ( col = 0; col < cols; ++col ) ++countEdgeY[thisrow[col]]; + for ( col = 0; col < cols; ++col ) ++countEdgeY[thisrow[col]]; /* x-edges */ ++countEdgeX[thisrow[0]]; - for ( col = 0; col < cols-1; ++col ) + for ( col = 0; col < cols-1; ++col ) ++countEdgeX[ MAX2(thisrow[col], thisrow[col+1]) ]; - + ++countEdgeX[thisrow[cols-1]]; - + /* shortcut: for the first row, countVertex == countEdgeX */ - + ++countVertex[thisrow[0]]; - for ( col = 0; col < cols-1; ++col ) + for ( col = 0; col < cols-1; ++col ) ++countVertex[ MAX2(thisrow[col], thisrow[col+1]) ]; ++countVertex[thisrow[cols-1]]; - - for ( row = 1; row < rows; ++row ){ - - tmprow = prevrow; + + for ( row = 1; row < rows; ++row ){ + + tmprow = prevrow; prevrow = thisrow; thisrow = tmprow; - + pgm_readpgmrow( ifp, thisrow, cols, maxval, format ); - + /* tiles */ - for ( col = 0; col < cols; ++col ) ++countTile[thisrow[col]]; - + for ( col = 0; col < cols; ++col ) ++countTile[thisrow[col]]; + /* y-edges */ - - for ( col = 0; col < cols; ++col ) + + for ( col = 0; col < cols; ++col ) ++countEdgeY[ MAX2(thisrow[col], prevrow[col]) ]; /* x-edges */ - + ++countEdgeX[thisrow[0]]; - - for ( col = 0; col < cols-1; ++col ) + + for ( col = 0; col < cols-1; ++col ) ++countEdgeX[ MAX2(thisrow[col], thisrow[col+1]) ]; - + ++countEdgeX[thisrow[cols-1]]; - + /* vertices */ ++countVertex[ MAX2(thisrow[0],prevrow[0]) ]; - for ( col = 0; col < cols-1; ++col ) + for ( col = 0; col < cols-1; ++col ) ++countVertex[ MAX4(thisrow[col], thisrow[col+1], prevrow[col], prevrow[col+1]) ]; - + ++countVertex[ MAX2(thisrow[cols-1],prevrow[cols-1]) ]; - + } /* for row */ - + /* now thisrow contains the top row*/ /* tiles and x-edges have been counted, now upper y-edges and top vertices remain */ - + /* y-edges */ for ( col = 0; col < cols; ++col ) ++countEdgeY[ thisrow[col] ]; /* vertices */ - + ++countVertex[thisrow[0]]; - for ( col = 0; col < cols-1; ++col ) + for ( col = 0; col < cols-1; ++col ) ++countVertex[ MAX2(thisrow[col],thisrow[col+1]) ]; ++countVertex[ thisrow[cols-1] ]; @@ -178,7 +178,7 @@ int main( int argc, char** argv ){ maxedgex = rows * (cols+1); maxedgey = (rows+1) * cols; maxvertex= (rows+1) * (cols+1); - + l2inv = 1.0/maxtiles; linv = 0.5/(rows+cols); @@ -187,14 +187,14 @@ int main( int argc, char** argv ){ printf( "#---------\t -----\t-------\t-------\t--------\n" ); for ( i = 0; i <= maxval; i++ ){ - if( !(countTile[i] || countEdgeX[i] || countEdgeY[i] || countVertex[i] ) ) + if( !(countTile[i] || countEdgeX[i] || countEdgeY[i] || countVertex[i] ) ) continue; /* skip empty slots */ area = maxtiles; perimeter = 2*maxedgex + 2*maxedgey - 4*maxtiles; eulerchi = maxtiles - maxedgex - maxedgey + maxvertex; - printf( "%f\t%6d\t%7d\t%7d\t%8d\t%g\t%g\t%6d\n", (float) i/(1.0*maxval), + printf( "%f\t%6d\t%7d\t%7d\t%8d\t%g\t%g\t%6d\n", (float) i/(1.0*maxval), maxtiles, maxedgex, maxedgey, maxvertex, area*l2inv, perimeter*linv, eulerchi ); @@ -210,13 +210,13 @@ int main( int argc, char** argv ){ } /* these should be zero: */ - printf( "# check:\t%6d\t%7d\t%7d\t%8d\n", + printf( "# check:\t%6d\t%7d\t%7d\t%8d\n", maxtiles, maxedgex, maxedgey, maxvertex ); pm_close( ifp ); - + exit( 0 ); - + } /*main*/ diff --git a/analyzer/pgmtexture.c b/analyzer/pgmtexture.c index 06db12f2..8a1678e2 100644 --- a/analyzer/pgmtexture.c +++ b/analyzer/pgmtexture.c @@ -9,25 +9,64 @@ #include "pm_c_util.h" #include "mallocvar.h" +#include "shhopt.h" #include "pgm.h" + +struct CmdlineInfo { + /* All the information the user supplied in the command line, + * in a form easy for the program to use. + */ + const char * inputFileName; /* Filespec of input file */ + unsigned int d; +}; + + + +static void +parseCommandLine(int argc, const char ** const argv, + struct CmdlineInfo * const cmdlineP) { +/*---------------------------------------------------------------------------- + Note that the file spec array we return is stored in the storage that + was passed to us as the argv array. +-----------------------------------------------------------------------------*/ + optEntry * option_def; + /* Instructions to OptParseOptions3 on how to parse our options. + */ + optStruct3 opt; + unsigned int option_def_index; + + unsigned int dSpec; + + MALLOCARRAY_NOFAIL(option_def, 100); + + option_def_index = 0; /* incremented by OPTENT3 */ + OPTENT3(0, "d", OPT_UINT, &cmdlineP->d, &dSpec, 0); + + opt.opt_table = option_def; + opt.short_allowed = FALSE; /* We have no short (old-fashioned) options */ + opt.allowNegNum = TRUE; /* We may have parms that are negative numbers */ + + pm_optParseOptions3(&argc, (char **)argv, opt, sizeof(opt), 0); + /* Uses and sets argc, argv, and some of *cmdlineP and others. */ + + if (!dSpec) + cmdlineP->d = 1; + + if (argc-1 < 1) + cmdlineP->inputFileName = "-"; + else if (argc-1 == 1) + cmdlineP->inputFileName = argv[1]; + else + pm_error("Program takes at most 1 parameter: the file name. " + "You specified %u", argc-1); +} + + + #define RADIX 2.0 #define EPSILON 0.000000001 #define BL "Angle " -#define F1 "Angular Second Moment " -#define F2 "Contrast " -#define F3 "Correlation " -#define F4 "Variance " -#define F5 "Inverse Diff Moment " -#define F6 "Sum Average " -#define F7 "Sum Variance " -#define F8 "Sum Entropy " -#define F9 "Entropy " -#define F10 "Difference Variance " -#define F11 "Difference Entropy " -#define F12 "Meas of Correlation-1 " -#define F13 "Meas of Correlation-2 " -#define F14 "Max Correlation Coeff " #define SWAP(a,b) do {float const y=(a);(a)=(b);(b)=y;} while (0) @@ -42,10 +81,6 @@ sign(float const x, -static bool const sortit = FALSE; - - - static float * vector(unsigned int const nl, unsigned int const nh) { @@ -62,14 +97,14 @@ vector(unsigned int const nl, float * v; unsigned int i; - assert(nh >= nl); + assert(nh >= nl); assert(nh <= UINT_MAX-1); MALLOCARRAY(v, (unsigned) (nh - nl + 1)); if (v == NULL) pm_error("Unable to allocate memory for a vector."); - for(i = 0; i < nh - nl +1; ++i) + for (i = 0; i < nh - nl +1; ++i) v[i] = 0; return v - nl; } @@ -84,48 +119,61 @@ matrix (unsigned int const nrl, /*---------------------------------------------------------------------------- Allocate a float matrix with range [nrl..nrh][ncl..nch] - 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 matrix elements that will - never be referenced (row < nrl or column < ncl). + Return value is a pointer to array of pointers to rows -----------------------------------------------------------------------------*/ + /* 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 matrix elements that + will never be referenced (row < nrl or column < ncl). + */ + unsigned int i; - float ** m; + float ** matrix; /* What we are creating */ - assert(nrh >= nrl); + assert(nrh >= nrl); assert(nrh <= UINT_MAX-1); /* allocate pointers to rows */ - MALLOCARRAY(m, (unsigned) (nrh - nrl + 1)); - if (m == NULL) + MALLOCARRAY(matrix, (unsigned) (nrh - nrl + 1)); + if (matrix == NULL) pm_error("Unable to allocate memory for a matrix."); - m -= ncl; + matrix -= ncl; - assert (nch >= ncl); + assert (nch >= ncl); assert(nch <= UINT_MAX-1); /* allocate rows and set pointers to them */ for (i = nrl; i <= nrh; ++i) { - MALLOCARRAY(m[i], (unsigned) (nch - ncl + 1)); - if (m[i] == NULL) + MALLOCARRAY(matrix[i], (unsigned) (nch - ncl + 1)); + if (!matrix[i]) pm_error("Unable to allocate memory for a matrix row."); - m[i] -= ncl; + matrix[i] -= ncl; } - /* return pointer to array of pointers to rows */ - return m; + return matrix; } static void -results (const char * const name, - const float * const a) { +printHeader() { + + fprintf(stdout, + "%-22.22s %10.10s %10.10s %10.10s %10.10s %10.10s\n", + "Angle", "0", "45", "90", "135", "Avg"); +} + + + +static void +printResults(const char * const name, + const float * const a) { unsigned int i; - fprintf(stdout, "%s", name); + fprintf(stdout, "%-22.22s ", name); for (i = 0; i < 4; ++i) fprintf(stdout, "% 1.3e ", a[i]); @@ -136,24 +184,105 @@ results (const char * const name, static void -simplesrt (unsigned int const n, - float * const arr) { +makeGrayToneSpatialDependenceMatrix(gray ** const grays, + unsigned int const rows, + unsigned int const cols, + unsigned int const d, + unsigned int * const tone, + unsigned int const toneCt, + float *** const pmatrix0P, + float *** const pmatrix45P, + float *** const pmatrix90P, + float *** const pmatrix135P) { + + float ** pmatrix0, ** pmatrix45, ** pmatrix90, ** pmatrix135; + unsigned int row; - unsigned int j; - float a; + pm_message("Computing spatial dependence matrix..."); - for (j = 2; j <= n; ++j) { - unsigned int i; + /* Allocate memory */ + pmatrix0 = matrix(0, toneCt, 0, toneCt); + pmatrix45 = matrix(0, toneCt, 0, toneCt); + pmatrix90 = matrix(0, toneCt, 0, toneCt); + pmatrix135 = matrix(0, toneCt, 0, toneCt); - a = arr[j]; - i = j; + for (row = 0; row < toneCt; ++row) { + unsigned int col; + for (col = 0; col < toneCt; ++col) { + pmatrix0 [row][col] = pmatrix45 [row][col] = 0; + pmatrix90[row][col] = pmatrix135[row][col] = 0; + } + } + for (row = 0; row < rows; ++row) { + unsigned int col; + for (col = 0; col < cols; ++col) { + unsigned int angle; + unsigned int x; + for (angle = 0, x = 0; angle <= 135; angle += 45) { + while (tone[x] != grays[row][col]) + ++x; + if (angle == 0 && col + d < cols) { + unsigned int y; + y = 0; + while (tone[y] != grays[row][col + d]) + ++y; + ++pmatrix0[x][y]; + ++pmatrix0[y][x]; + } + if (angle == 90 && row + d < rows) { + unsigned int y; + y = 0; + while (tone[y] != grays[row + d][col]) + ++y; + ++pmatrix90[x][y]; + ++pmatrix90[y][x]; + } + if (angle == 45 && row + d < rows && col >= d) { + unsigned int y; + y = 0; + while (tone[y] != grays[row + d][col - d]) + ++y; + ++pmatrix45[x][y]; + ++pmatrix45[y][x]; + } + if (angle == 135 && row + d < rows && col + d < cols) { + unsigned int y; + y = 0; + while (tone[y] != grays[row + d][col + d]) + ++y; + ++pmatrix135[x][y]; + ++pmatrix135[y][x]; + } + } + } + } + /* Gray-tone spatial dependence matrices are complete */ - while (i > 1 && arr[i-1] > a) { - arr[i] = arr[i-1]; - --i; + { + /* Find normalizing constants */ + unsigned int const r0 = 2 * rows * (cols - d); + unsigned int const r45 = 2 * (rows - d) * (cols - d); + unsigned int const r90 = 2 * (rows - d) * cols; + + unsigned int i; + + /* Normalize gray-tone spatial dependence matrix */ + for (i = 0; i < toneCt; ++i) { + unsigned int j; + for (j = 0; j < toneCt; ++j) { + pmatrix0 [i][j] /= r0; + pmatrix45 [i][j] /= r45; + pmatrix90 [i][j] /= r90; + pmatrix135[i][j] /= r45; } - arr[i] = a; } + } + pm_message(" ...done."); + + *pmatrix0P = pmatrix0; + *pmatrix45P = pmatrix45; + *pmatrix90P = pmatrix90; + *pmatrix135P = pmatrix135; } @@ -209,8 +338,8 @@ mkbalanced (float ** const a, static void -reduction (float ** const a, - unsigned int const n) { +reduction(float ** const a, + unsigned int const n) { unsigned int m; @@ -327,7 +456,7 @@ hessenberg(float ** const a, float p, q, r; if (its == 30) pm_error("Too many iterations to required " - "to find %s. Giving up", F14); + "to find max correlation coefficient"); if (its == 10 || its == 20) { int i; float s; @@ -570,6 +699,43 @@ f5_idm (float ** const p, } +static double * +newPxpy2(unsigned int const ng) { + + double * pxpy; + + if (ng > UINT_MAX-1) + pm_error("Too many gray levels (%u) to do computations", ng); + + MALLOCARRAY(pxpy, ng+1); + + if (!pxpy) + pm_error("Unable to allocate %u entries for the pxpy table", + ng+1); + + return pxpy; +} + + + +static float * +newPxpy(unsigned int const ng) { + + float * pxpy; + + if (ng > (UINT_MAX-1)/2 -1) + pm_error("Too many gray levels (%u) to do computations", ng); + + MALLOCARRAY(pxpy, 2 * (ng+1) + 1); + + if (!pxpy) + pm_error("Unable to allocate %u entries for the pxpy table", + 2* (ng+1) + 1); + + return pxpy; +} + + static float f6_savg (float ** const p, @@ -577,12 +743,11 @@ f6_savg (float ** const p, /*---------------------------------------------------------------------------- Sum Average -----------------------------------------------------------------------------*/ - float pxpy[2 * (PGM_MAXMAXVAL+1) + 1]; + float * const pxpy = newPxpy(ng); + unsigned int i; float savg; - assert(2*ng < ARRAY_SIZE(pxpy)); - for (i = 0; i <= 2 * ng; ++i) pxpy[i] = 0.0; @@ -594,6 +759,8 @@ f6_savg (float ** const p, for (i = 2, savg = 0.0; i <= 2 * ng; ++i) savg += i * pxpy[i]; + free(pxpy); + return savg; } @@ -606,12 +773,11 @@ f7_svar (float ** const p, /*---------------------------------------------------------------------------- Sum Variance -----------------------------------------------------------------------------*/ - float pxpy[2 * (PGM_MAXMAXVAL+1) + 1]; + float * const pxpy = newPxpy(ng); + unsigned int i; float var; - assert(2*ng < ARRAY_SIZE(pxpy)); - for (i = 0; i <= 2 * ng; ++i) pxpy[i] = 0; @@ -623,6 +789,8 @@ f7_svar (float ** const p, for (i = 2, var = 0.0; i <= 2 * ng; ++i) var += (i - s) * (i - s) * pxpy[i]; + free(pxpy); + return var; } @@ -634,12 +802,11 @@ f8_sentropy (float ** const p, /*---------------------------------------------------------------------------- Sum Entropy -----------------------------------------------------------------------------*/ - float pxpy[2 * (PGM_MAXMAXVAL+1) + 1]; + float * const pxpy = newPxpy(ng); + unsigned int i; float sentropy; - assert(2*ng < ARRAY_SIZE(pxpy)); - for (i = 0; i <= 2 * ng; ++i) pxpy[i] = 0; @@ -651,6 +818,8 @@ f8_sentropy (float ** const p, for (i = 2, sentropy = 0.0; i <= 2 * ng; ++i) sentropy -= pxpy[i] * log10(pxpy[i] + EPSILON); + free(pxpy); + return sentropy; } @@ -681,15 +850,14 @@ f10_dvar(float ** const p, /*---------------------------------------------------------------------------- Difference Variance -----------------------------------------------------------------------------*/ - double pxpy[PGM_MAXMAXVAL + 1]; + double * const pxpy = newPxpy2(ng); + unsigned int i; double sqrNg; /* Square of 'ng' */ double sum; double sumSqr; double var; - assert(ng <= ARRAY_SIZE(pxpy)); - for (i = 0; i < ng; ++i) pxpy[i] = 0; @@ -706,6 +874,8 @@ f10_dvar(float ** const p, sqrNg = SQR(ng); var = (sqrNg * sumSqr - SQR(sum)) / SQR(sqrNg); + free(pxpy); + return var; } @@ -717,12 +887,11 @@ f11_dentropy (float ** const p, /*---------------------------------------------------------------------------- Difference Entropy -----------------------------------------------------------------------------*/ - float pxpy[2 * (PGM_MAXMAXVAL+1) + 1]; + float * const pxpy = newPxpy(ng); + unsigned int i; float sum; - assert(2*ng < ARRAY_SIZE(pxpy)); - for (i = 0; i <= 2 * ng; ++i) pxpy[i] = 0; @@ -734,6 +903,8 @@ f11_dentropy (float ** const p, for (i = 0, sum = 0.0; i < ng; ++i) sum += pxpy[i] * log10(pxpy[i] + EPSILON); + free(pxpy); + return -sum; } @@ -879,8 +1050,6 @@ f14_maxcorr (float ** const p, reduction(q, ng); /* Finding eigenvalue for nonsymetric matrix using QR algorithm */ hessenberg(q, ng, x, iy); - if (sortit) - simplesrt(ng, x); /* Return the sqrt of the second largest eigenvalue of q */ for (i = 2, tmp = x[1]; i <= ng; ++i) @@ -891,257 +1060,370 @@ f14_maxcorr (float ** const p, +static void +printAngularSecondMom(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f1_a2m(pmatrix0, toneCt); + res[1] = f1_a2m(pmatrix45, toneCt); + res[2] = f1_a2m(pmatrix90, toneCt); + res[3] = f1_a2m(pmatrix135, toneCt); + + printResults("Angular Second Moment", res); +} + + + +static void +printContrast(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f2_contrast(pmatrix0, toneCt); + res[1] = f2_contrast(pmatrix45, toneCt); + res[2] = f2_contrast(pmatrix90, toneCt); + res[3] = f2_contrast(pmatrix135, toneCt); + + printResults("Contrast", res); +} + + + +static void +printCorrelation(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f3_corr(pmatrix0, toneCt); + res[1] = f3_corr(pmatrix45, toneCt); + res[2] = f3_corr(pmatrix90, toneCt); + res[3] = f3_corr(pmatrix135, toneCt); + + printResults("Correlation", res); +} + + + +static void +printVariance(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f4_var(pmatrix0, toneCt); + res[1] = f4_var(pmatrix45, toneCt); + res[2] = f4_var(pmatrix90, toneCt); + res[3] = f4_var(pmatrix135, toneCt); + + printResults("Variance", res); +} + + + +static void +printInverseDiffMoment(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f5_idm(pmatrix0, toneCt); + res[1] = f5_idm(pmatrix45, toneCt); + res[2] = f5_idm(pmatrix90, toneCt); + res[3] = f5_idm(pmatrix135, toneCt); + + printResults("Inverse Diff Moment", res); +} + + + +static void +printSumAverage(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f6_savg(pmatrix0, toneCt); + res[1] = f6_savg(pmatrix45, toneCt); + res[2] = f6_savg(pmatrix90, toneCt); + res[3] = f6_savg(pmatrix135, toneCt); + + printResults("Sum Average", res); +} + + + +static void +printSumVariance(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + float savg[4]; + + savg[0] = f6_savg(pmatrix0, toneCt); + savg[1] = f6_savg(pmatrix45, toneCt); + savg[2] = f6_savg(pmatrix90, toneCt); + savg[3] = f6_savg(pmatrix135, toneCt); + + res[0] = f7_svar(pmatrix0, toneCt, savg[0]); + res[1] = f7_svar(pmatrix45, toneCt, savg[1]); + res[2] = f7_svar(pmatrix90, toneCt, savg[2]); + res[3] = f7_svar(pmatrix135, toneCt, savg[3]); + + printResults("Sum Variance", res); +} + + + +static void +printSumVarianceEnt(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f8_sentropy(pmatrix0, toneCt); + res[1] = f8_sentropy(pmatrix45, toneCt); + res[2] = f8_sentropy(pmatrix90, toneCt); + res[3] = f8_sentropy(pmatrix135, toneCt); + + printResults("Sum Entropy", res); +} + + + +static void +printEntropy(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + + res[0] = f9_entropy(pmatrix0, toneCt); + res[1] = f9_entropy(pmatrix45, toneCt); + res[2] = f9_entropy(pmatrix90, toneCt); + res[3] = f9_entropy(pmatrix135, toneCt); + + printResults("Entropy", res); +} + + + +static void +printDiffVariance(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f10_dvar(pmatrix0, toneCt); + res[1] = f10_dvar(pmatrix45, toneCt); + res[2] = f10_dvar(pmatrix90, toneCt); + res[3] = f10_dvar(pmatrix135, toneCt); + + printResults("Difference Variance", res); +} + + + +static void +printDiffEntropy(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f11_dentropy(pmatrix0, toneCt); + res[1] = f11_dentropy(pmatrix45, toneCt); + res[2] = f11_dentropy(pmatrix90, toneCt); + res[3] = f11_dentropy(pmatrix135, toneCt); + + printResults ("Difference Entropy", res); +} + + + +static void +printCorrelation1(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f12_icorr(pmatrix0, toneCt); + res[1] = f12_icorr(pmatrix45, toneCt); + res[2] = f12_icorr(pmatrix90, toneCt); + res[3] = f12_icorr(pmatrix135, toneCt); + + printResults("Meas of Correlation-1", res); +} + + + +static void +printCorrelation2(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f13_icorr(pmatrix0, toneCt); + res[1] = f13_icorr(pmatrix45, toneCt); + res[2] = f13_icorr(pmatrix90, toneCt); + res[3] = f13_icorr(pmatrix135, toneCt); + + printResults("Meas of Correlation2", res); +} + + + +static void +printCorrelationMax(float ** const pmatrix0, + float ** const pmatrix45, + float ** const pmatrix90, + float ** const pmatrix135, + unsigned int const toneCt) { + + float res[4]; + + res[0] = f14_maxcorr(pmatrix0, toneCt); + res[1] = f14_maxcorr(pmatrix45, toneCt); + res[2] = f14_maxcorr(pmatrix90, toneCt); + res[3] = f14_maxcorr(pmatrix135, toneCt); + + printResults("Max Correlation Coeff", res); +} + + + int main (int argc, const char ** argv) { + struct CmdlineInfo cmdline; FILE * ifP; gray ** grays; - unsigned int tone[PGM_MAXMAXVAL+1]; - unsigned int r0, r45, r90; - unsigned int d; - unsigned int x, y; + unsigned int * tone; /* malloced array */ + unsigned int toneCt; unsigned int row; int rows, cols; - int argn; unsigned int itone; - unsigned int toneCt; - float ** p_matrix0, ** p_matrix45, ** p_matrix90, ** p_matrix135; - float a2m[4], contrast[4], corr[4], var[4], idm[4], savg[4]; - float sentropy[4], svar[4], entropy[4], dvar[4], dentropy[4]; - float icorr[4], maxcorr[4]; + float ** pmatrix0, ** pmatrix45, ** pmatrix90, ** pmatrix135; gray maxval; unsigned int i; - const char * const usage = "[-d <d>] [pgmfile]"; pm_proginit(&argc, argv); - d = 1; + parseCommandLine(argc, argv, &cmdline); - argn = 1; - - /* Check for flags. */ - if ( argn < argc && argv[argn][0] == '-' ) - { - if ( argv[argn][1] == 'd' ) - { - ++argn; - if ( argn == argc || sscanf( argv[argn], "%u", &d ) != 1 ) - pm_usage( usage ); - } - else - pm_usage( usage ); - ++argn; - } - - if ( argn < argc ) - { - ifP = pm_openr( argv[argn] ); - ++argn; - } - else - ifP = stdin; - - if ( argn != argc ) - pm_usage( usage ); + ifP = pm_openr(cmdline.inputFileName); grays = pgm_readpgm(ifP, &cols, &rows, &maxval); - pm_close (ifP); - if (maxval > PGM_MAXMAXVAL) - pm_error("Maxval %u is too high. We can handle only up to %u", - maxval, PGM_MAXMAXVAL); + MALLOCARRAY(tone, maxval+1); /* Determine the number of different gray scales (not maxval) */ - for (i = 0; i <= PGM_MAXMAXVAL; ++i) + for (i = 0; i <= maxval; ++i) tone[i] = -1; for (row = 0; row < rows; ++row) { unsigned int col; for (col = 0; col < cols; ++col) tone[grays[row][col]] = grays[row][col]; } - for (i = 0, toneCt = 0; i <= PGM_MAXMAXVAL; ++i) { + for (i = 0, toneCt = 0; i <= maxval; ++i) { if (tone[i] != -1) ++toneCt; } pm_message("(Image has %u gray levels.)", toneCt); /* Collapse array, taking out all zero values */ - for (row = 0, itone = 0; row <= PGM_MAXMAXVAL; ++row) + for (row = 0, itone = 0; row <= maxval; ++row) if (tone[row] != -1) tone[itone++] = tone[row]; /* Now array contains only the gray levels present (in ascending order) */ - /* Allocate memory for gray-tone spatial dependence matrix */ - p_matrix0 = matrix (0, toneCt, 0, toneCt); - p_matrix45 = matrix (0, toneCt, 0, toneCt); - p_matrix90 = matrix (0, toneCt, 0, toneCt); - p_matrix135 = matrix (0, toneCt, 0, toneCt); - - for (row = 0; row < toneCt; ++row) { - unsigned int col; - for (col = 0; col < toneCt; ++col) { - p_matrix0 [row][col] = p_matrix45 [row][col] = 0; - p_matrix90[row][col] = p_matrix135[row][col] = 0; - } - } - if (d > cols) + if (cmdline.d > cols) pm_error("Image is narrower (%u columns) " - "than specified distance (%u)", cols, d); - - /* Find gray-tone spatial dependence matrix */ - pm_message("Computing spatial dependence matrix..."); - for (row = 0; row < rows; ++row) { - unsigned int col; - for (col = 0; col < cols; ++col) { - unsigned int angle; - for (angle = 0, x = 0; angle <= 135; angle += 45) { - while (tone[x] != grays[row][col]) - ++x; - if (angle == 0 && col + d < cols) { - y = 0; - while (tone[y] != grays[row][col + d]) - ++y; - ++p_matrix0[x][y]; - ++p_matrix0[y][x]; - } - if (angle == 90 && row + d < rows) { - y = 0; - while (tone[y] != grays[row + d][col]) - ++y; - ++p_matrix90[x][y]; - ++p_matrix90[y][x]; - } - if (angle == 45 && row + d < rows && col >= d) { - y = 0; - while (tone[y] != grays[row + d][col - d]) - ++y; - ++p_matrix45[x][y]; - ++p_matrix45[y][x]; - } - if (angle == 135 && row + d < rows && col + d < cols) { - y = 0; - while (tone[y] != grays[row + d][col + d]) - ++y; - ++p_matrix135[x][y]; - ++p_matrix135[y][x]; - } - } - } - } - /* Gray-tone spatial dependence matrices are complete */ + "than specified distance (%u)", cols, cmdline.d); - /* Find normalizing constants */ - r0 = 2 * rows * (cols - d); - r45 = 2 * (rows - d) * (cols - d); - r90 = 2 * (rows - d) * cols; - - /* Normalize gray-tone spatial dependence matrix */ - for (itone = 0; itone < toneCt; ++itone) { - unsigned int jtone; - for (jtone = 0; jtone < toneCt; ++jtone) { - p_matrix0[itone][jtone] /= r0; - p_matrix45[itone][jtone] /= r45; - p_matrix90[itone][jtone] /= r90; - p_matrix135[itone][jtone] /= r45; - } - } - pm_message(" ...done."); + makeGrayToneSpatialDependenceMatrix( + grays, rows, cols, cmdline.d, tone, toneCt, + &pmatrix0, &pmatrix45, &pmatrix90, &pmatrix135); pm_message("Computing textural features ..."); fprintf(stdout, "\n"); - fprintf(stdout, - "%s 0 45 90 135 Avg\n", - BL); - - a2m[0] = f1_a2m(p_matrix0, toneCt); - a2m[1] = f1_a2m(p_matrix45, toneCt); - a2m[2] = f1_a2m(p_matrix90, toneCt); - a2m[3] = f1_a2m(p_matrix135, toneCt); - results(F1, a2m); - - contrast[0] = f2_contrast(p_matrix0, toneCt); - contrast[1] = f2_contrast(p_matrix45, toneCt); - contrast[2] = f2_contrast(p_matrix90, toneCt); - contrast[3] = f2_contrast(p_matrix135, toneCt); - results(F2, contrast); - - - corr[0] = f3_corr(p_matrix0, toneCt); - corr[1] = f3_corr(p_matrix45, toneCt); - corr[2] = f3_corr(p_matrix90, toneCt); - corr[3] = f3_corr(p_matrix135, toneCt); - results(F3, corr); - - var[0] = f4_var(p_matrix0, toneCt); - var[1] = f4_var(p_matrix45, toneCt); - var[2] = f4_var(p_matrix90, toneCt); - var[3] = f4_var(p_matrix135, toneCt); - results(F4, var); - - - idm[0] = f5_idm(p_matrix0, toneCt); - idm[1] = f5_idm(p_matrix45, toneCt); - idm[2] = f5_idm(p_matrix90, toneCt); - idm[3] = f5_idm(p_matrix135, toneCt); - results(F5, idm); - - savg[0] = f6_savg(p_matrix0, toneCt); - savg[1] = f6_savg(p_matrix45, toneCt); - savg[2] = f6_savg(p_matrix90, toneCt); - savg[3] = f6_savg(p_matrix135, toneCt); - results(F6, savg); - - svar[0] = f7_svar(p_matrix0, toneCt, savg[0]); - svar[1] = f7_svar(p_matrix45, toneCt, savg[1]); - svar[2] = f7_svar(p_matrix90, toneCt, savg[2]); - svar[3] = f7_svar(p_matrix135, toneCt, savg[3]); - results(F7, svar); - - sentropy[0] = f8_sentropy(p_matrix0, toneCt); - sentropy[1] = f8_sentropy(p_matrix45, toneCt); - sentropy[2] = f8_sentropy(p_matrix90, toneCt); - sentropy[3] = f8_sentropy(p_matrix135, toneCt); - results(F8, sentropy); - - entropy[0] = f9_entropy(p_matrix0, toneCt); - entropy[1] = f9_entropy(p_matrix45, toneCt); - entropy[2] = f9_entropy(p_matrix90, toneCt); - entropy[3] = f9_entropy(p_matrix135, toneCt); - results(F9, entropy); - - dvar[0] = f10_dvar(p_matrix0, toneCt); - dvar[1] = f10_dvar(p_matrix45, toneCt); - dvar[2] = f10_dvar(p_matrix90, toneCt); - dvar[3] = f10_dvar(p_matrix135, toneCt); - results(F10, dvar); - - dentropy[0] = f11_dentropy(p_matrix0, toneCt); - dentropy[1] = f11_dentropy(p_matrix45, toneCt); - dentropy[2] = f11_dentropy(p_matrix90, toneCt); - dentropy[3] = f11_dentropy(p_matrix135, toneCt); - results (F11, dentropy); - - icorr[0] = f12_icorr(p_matrix0, toneCt); - icorr[1] = f12_icorr(p_matrix45, toneCt); - icorr[2] = f12_icorr(p_matrix90, toneCt); - icorr[3] = f12_icorr(p_matrix135, toneCt); - results(F12, icorr); - - icorr[0] = f13_icorr(p_matrix0, toneCt); - icorr[1] = f13_icorr(p_matrix45, toneCt); - icorr[2] = f13_icorr(p_matrix90, toneCt); - icorr[3] = f13_icorr(p_matrix135, toneCt); - results(F13, icorr); - - maxcorr[0] = f14_maxcorr(p_matrix0, toneCt); - maxcorr[1] = f14_maxcorr(p_matrix45, toneCt); - maxcorr[2] = f14_maxcorr(p_matrix90, toneCt); - maxcorr[3] = f14_maxcorr(p_matrix135, toneCt); - results(F14, maxcorr); + + printHeader(); + + printAngularSecondMom (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printContrast (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printCorrelation (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printVariance (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printInverseDiffMoment(pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printSumAverage (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printSumVariance (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printSumVarianceEnt (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printEntropy (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printDiffVariance (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printDiffEntropy (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printCorrelation1 (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printCorrelation2 (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); + + printCorrelationMax (pmatrix0, pmatrix45, pmatrix90, pmatrix135, toneCt); pm_message(" ...done."); + pm_close (ifP); + return 0; } diff --git a/analyzer/pnmhistmap.c b/analyzer/pnmhistmap.c index fc1bbbde..e51bbb24 100644 --- a/analyzer/pnmhistmap.c +++ b/analyzer/pnmhistmap.c @@ -113,7 +113,7 @@ parseCommandLine(int argc, const char ** argv, if (!heightSpec) cmdlineP->height = 200; - if (argc-1 == 0) + if (argc-1 == 0) cmdlineP->inputFilespec = "-"; else if (argc-1 != 1) pm_error("Program takes zero or one argument (filename). You " @@ -202,7 +202,7 @@ pgmHist(FILE * const ifP, unsigned int * ghist; double vscale; unsigned int hmax; - + MALLOCARRAY(ghist, histWidth); if (ghist == NULL) pm_error("Not enough memory for histogram array (%u bytes)", @@ -231,7 +231,7 @@ pgmHist(FILE * const ifP, pm_message("finding max. slot height..."); if (clipSpec) hmax = clipCount; - else + else hmax = maxSlotCount(ghist, histWidth, no_white, no_black); assert(hmax > 0); @@ -275,10 +275,10 @@ maxSlotCountAll(unsigned int * const hist[3], for (color = 0; color < 3; ++color) if (hist[color]) - hmax = MAX(hmax, - maxSlotCount(hist[color], + hmax = MAX(hmax, + maxSlotCount(hist[color], histWidth, no_white, no_black)); - + return hmax; } @@ -418,7 +418,7 @@ ppmHist(FILE * const ifP, pm_message("finding max. slot height..."); if (clipSpec) hmax = clipCount; - else + else hmax = maxSlotCountAll(hist, histWidth, no_white, no_black); assert(hmax > 0); @@ -427,7 +427,7 @@ ppmHist(FILE * const ifP, vscale = (double) histHeight / hmax; if (verbose && pm_have_float_format()) - pm_message("Done: height = %u, vertical scale factor = %g", + pm_message("Done: height = %u, vertical scale factor = %g", hmax, vscale); for (i = 0; i < histWidth; ++i) { @@ -435,8 +435,8 @@ ppmHist(FILE * const ifP, unsigned int j; bool plotted; plotted = FALSE; - for (j = histHeight - (int)(vscale * hist[WANT_RED][i]); - j < histHeight && !plotted; + for (j = histHeight - (int)(vscale * hist[WANT_RED][i]); + j < histHeight && !plotted; ++j) { PPM_PUTR(pixels[j][i], maxval); plotted = dots; @@ -446,8 +446,8 @@ ppmHist(FILE * const ifP, unsigned int j; bool plotted; plotted = FALSE; - for (j = histHeight - (int)(vscale * hist[WANT_GRN][i]); - j < histHeight && !plotted; + for (j = histHeight - (int)(vscale * hist[WANT_GRN][i]); + j < histHeight && !plotted; ++j) { PPM_PUTG(pixels[j][i], maxval); plotted = dots; @@ -457,8 +457,8 @@ ppmHist(FILE * const ifP, unsigned int j; bool plotted; plotted = FALSE; - for (j = histHeight - (int)(vscale * hist[WANT_BLU][i]); - j < histHeight && !plotted; + for (j = histHeight - (int)(vscale * hist[WANT_BLU][i]); + j < histHeight && !plotted; ++j) { PPM_PUTB(pixels[j][i], maxval); plotted = dots; |