📄 main.c
字号:
/* * -*- Mode: ANSI C -*- * $Id: main.c,v 1.59 1996/11/20 20:19:43 fernande Exp $ * $Source: /sgi.acct/sweldens/cvs/liftpack/main.c,v $ * Author: Gabriel Fernandez * * >>> Fast Lifted Wavelet Transform on the Interval <<< * (command line parser) * * This file processes the command line in order to set the options * needed by the Fast Lifted Wavelet Transform. * * Some values are assumed by default. The following paragraphs give * a general description on how the program works. * * The forward transform is executed by default, unless the -i option * is specified. If user wants both transforms to be executed, then use * the -b option with a value of 1.0. * * The -b applies the Beta value to the result of the forward transform * and, then, executes the inverse to see the effects. If the -i option * is written after the -b option, the forward transform is not executed, * i.e., the Beta operator is applied directly to the original dataset * and, then, the inverse transform is executed. * * Four (4) vaninshing moments for the Dual wavelets and * (2) for the Real wavelet are assumed, unless the values are changed * with the -N and -n options. * * The final values are not scaled, unles the -s option is used. This * option scales the values by shifting everything into a positive domain * and by truncating any value grater than 255 into 255. * * All files are assumed to be placed in a the directory pointed out by * the variable DATADIR defined in the file $FLWTHOME/include/flwtdef.h. * * There is no default input file and the output file name is out.type, * where type is pbm, pgm, ppm, txt, wgm, or wpm. */#include <stdio.h>#include "flwtdef.h" /* types and general definitions */static char *useStr[] = {"",">>> Wavelet Transform on the Interval using the Lifting Scheme <<<",""," .-."," / | \\"," .-. / -+- \\ .-."," `-' | `-'","","usage: liftpack [options] infile","where options are:","-c shows software copyright","-e shows a list of examples","-f calls the filter application program interface","-g <int> sets value of gamma correction for scaling (default 1)","-h displays this help message","-i execute the inverse transform (default FALSE)","-j <int> sets maximum number of levels of the transform (default 999)","-l shows software license","-M input or output file is in Mallat format (default FALSE)", "-n <int> sets number of real vanishing moments (defaul 4)","-N <int> sets number of dual vanishing moments (default 2)","-o <outfile> sets the output file name (default out.dat)","-p prints intermediate results and coefficents","-P generates the best wavelet packet basis (default FALSE)","-s executes the scaling of the output file","-t <type> force type of output file (default same as input)","-w <cols> <rows> <x> <y> creates an image of rows by cols with zeros and puts"," a one in position (x,y) (using C notation). Then,"," executes the inverse calculation (default 0 0 0 0)."," This option creates either the wavelet function"," or the scaling function depending on where you put"," the 1.","","infile determines the input file (no default value is set)","","All input and output data files are assumed to be located in ./" DATADIR,"The available formats to read and write files are:"," pbm - portable bitmap file format (raw and ascii)"," pgm - portable graymap file format (raw and ascii)"," ppm - portable pixmap file format (raw and ascii)",/* " gif - ", *//* " bmp - ", */" txt - plain ASCII file format (floating point precision)"," wgm - wavelet graymap file format (flwt and packets)"," wpm - wavelet pixmap file format (flwt and packets)","",REVDATE,'\0'};static char *cpStr[] = {#include "copyrinc.h"'\0'};static char *lcStr[] = {#include "liceninc.h"'\0'};static char *egStr[] = {">>> Wavelet Transform on the Interval using the Lifting Scheme <<<","","Examples:","","Forward transform : liftpack -o out.wtf lena.pgm","(N=4, N~=2, forward, not scaling, output in 'out.wtf', input in 'lena.pgm')","","Forward transform : liftpack -o out.wtf -N 6 -n 4 lena.pgm","(forward, not scaling, output in 'out.wtf', N=6, N~=4, input in 'lena.pgm')","","Inverse transform : liftpack -i -s -t pgm -o out.pgm out.wtf","(N=4, N~=2, inverse, scaling, output in 'out.pgm', input in 'out.wtf')","","Inverse transform : liftpack -i -s -N 6 -n 4 -t pgm -o out.pgm out.wtf","(inverse, scaling, N=6, N~=4, output in 'out.pgm', input in 'out.wtf')","","Invertible example : liftpack -t txt -o out.wtf lena.pgm"," liftpack -i -s -t pgm -o lenainv.pgm out.wtf","('lenainv.pgm' and 'lena.pgm' contain exactly the same data)","","To see wavelet function : liftpack -w 544 544 256 256","(N=4, N~=2, inverse, scaling, output in 'out.dat', input is a 544x544 ""image of zeros with a one in 256x256)","","To apply filter operator : liftpack -f -s lena.pgm","(N=4, N~=2, forward+inverse, filter operator, scaling, output in ""'out.dat', input in 'lena.pgm'","",'\0'};/* do not edit anything above this line *//* System header files */#include <string.h> /* strcpy(), strcmp() *//* FLWT header files */#include <cost.h> /* cost functions */#include <flwterr.h> /* Error() function */#include <flwtapi.h> /* FLWTAPI() function */#include <flwtfilt.h> /* FilterQuery() function */#include <memchk.h> /* PrintLeaks() function */#include <util.h> /* ODD() and EVEN() macros *//* Prototypes for Private Static Functions */static void Usage (void);static void Examples (void);static void Copyright (void);static void License (void);/* code */intmain ( int argc, char **argv ){ static ParamStruct param; /* used to store all the needed options */ /* Assign default values */ param.sizeX = param.sizeY = param.x = param.y = 0; param.levels = 999; param.gamma = 1; param.N = 2; param.nTilde = 4; param.mode = FORWARD; param.mallat = FALSE; param.packets = FALSE; param.print = FALSE; param.scale = FALSE; strcpy (param.infile, ""); sprintf (param.outfile, "%sout.dat", DATADIR); /* Checking existence of data directory */ if ( strcmp( (char *)DATADIR, "" ) && ( fopen(DATADIR, "r") == NULL ) ) { Error ("main", NO_DIR, ABORT, DATADIR); } /* Parsing command line */ while (--argc) { ++argv; if (*argv[0] == '-') { switch (argv[0][1]) { case 'c': /* displays software copyright */ Copyright (); /* NOTREACHED */ break; case 'e': /* displays examples */ Examples (); /* NOTREACHED */ break; case 'f': /* apply filter to input */ param.mode = FILTER; param.beta = FilterQuery(); break; case 'g': /* sets the value of the Gamma factor */ if ( argv[1] == NULL ) Error ("main", MISSING_PARAMETER, ABORT); else param.gamma = (int) atoi (argv[1]); argc--; argv++; break; case 'h': /* displays a help message */ Usage (); /* NOTREACHED */ break; case 'i': /* apply Inverse transform */ param.mode = INVERSE; break; case 'j': /* maximum level of the transform */ param.levels = (int) atoi (argv[1]); if (param.levels <= 0) { Error ("main", INVALID_RELATIONAL_INT, ABORT, "J", ">", 0); } argc--; argv++; break; case 'l': /* displays software license */ License (); /* NOTREACHED */ break; case 'M': /* set Mallat format to TRUE */ param.mallat = TRUE; break; case 'n': /* number of lifting coefficients */ if ( argv[1] == NULL ) Error ("main", MISSING_PARAMETER, ABORT); else param.nTilde = (int) atoi (argv[1]); argc--; argv++; break; case 'N': /* number of filter coefficients */ if ( argv[1] == NULL ) Error ("main", MISSING_PARAMETER, ABORT); else param.N = (int) atoi (argv[1]); argc--; argv++; break; case 'o': /* changes output file name */ if (argv[1] == NULL) { Error ("main", MISSING_PARAMETER, ABORT); } else { sprintf (param.outfile, "%s%s", DATADIR, argv[1]); } argc--; argv++; break; case 'p': /* print coefficients */ param.print = TRUE; break; case 'P': /* generate wavelet packets */ param.packets = TRUE; break; case 's': /* scales values between 0 and 255 */ param.scale = TRUE; break; case 't': /* set output file type */ if (argv[1] == NULL) { Error ("main", MISSING_PARAMETER, ABORT); } else { strncpy (param.frmType, argv[1], MAX_FILETYPE-1); } argc--; argv++; break; case 'w': /* calculate wavelet function */ param.mode = WAVELET; if ( argv[1] == NULL || argv[2] == NULL || argv[3] == NULL || argv[4] == NULL ) Error ("main", MISSING_PARAMETER, ABORT); else { param.sizeX = (int) atoi (argv[1]); param.sizeY = (int) atoi (argv[2]); param.x = (int) atoi (argv[3]); param.y = (int) atoi (argv[4]); } argc--; argv++; break; default: Error ("main", IGNORE, RETURN, *argv); break; } } else { sprintf (param.infile, "%s%s", DATADIR, *argv); } } /* Check for input file */ if ( !strcmp (param.infile, "") ) { Usage (); /* NOTREACHED */ } /* Check for value of N and nTilde */ /* if N is odd, then nTilde must be odd */ /* if N is even, then nTilde must be even */ if ( ODD(param.N) ) { param.nTilde = 1; } if ( ODD(param.nTilde) ) { param.N = 1; } /* Print Variables Configuration */ fprintf( stdout, "\n>> liftpack %s <<\n", VERSTR ); fprintf( stdout, ">> Variables Configuration <<\n" ); fprintf( stdout, "Input file [%s]\n", (param.mode==WAVELET) ? "None" : param.infile ); fprintf( stdout, "Output file [%s]\n", param.outfile ); if (param.scale) fprintf (stdout, "Gamma value [%d]\n", param.gamma); if (param.mode == FILTER) { fprintf (stdout, "Filter operator [%s]\n", (param.beta.mode == LINEAR) ? "Linear" : (param.beta.mode == CIRCULAR) ? "Circular" : (param.beta.mode == RECTANGULAR) ? "Rectangular" : "Function" ); if ( param.beta.mode == LINEAR ) { fprintf (stdout, "Beta value for X [%g]\n", param.beta.val1); fprintf (stdout, "Beta value for Y [%g]\n", param.beta.val2); } else if ( param.beta.mode == FUNCTION ) { fprintf (stdout, "Filter Function [%s]\n", param.beta.func); fprintf (stdout, "Min. Beta value [%g]\n", param.beta.val1); fprintf (stdout, "Max. Beta value [%g]\n", param.beta.val2); } else { fprintf (stdout, "Beta value in middle [%g]\n", param.beta.val1); fprintf (stdout, "Beta value in border [%g]\n", param.beta.val2); } } if (param.mode == WAVELET) fprintf (stdout, "Wavelet function " "[True] Size[%dx%d] Place[%dx%d]\n", param.sizeX, param.sizeY, param.x, param.y); if (param.packets) { fprintf (stdout, "Wavelet packets [True]\n"); if (param.mode != INVERSE) { SetInfoCost( 0, (Flt)999, param.print ); /* set info cost function */ } } fprintf (stdout, "Print coefficients [%s]\n", param.print ? "True" : "False"); fprintf (stdout, "Scale values [%s]\n", param.scale ? "True" : "False"); fprintf (stdout, "Dual Vanishing Moments [%d]\n", param.N); fprintf (stdout, "Real Vanishing Moments [%d]\n", param.nTilde); fprintf (stdout, "Maximum level [%d]\n", param.levels); /* Let the flwt API to manage all the options */ FLWTAPI (param); /* Print memory leaks, if any */ PrintLeaks (); /* Finish process */ fprintf (stderr, "\nDone!\n"); return (SUCCESS); /* everything went fine */}/** Private fucntions **//* Display help message */static voidUsage (void){ char buf[BUFSIZ]; int i; setbuf (stderr, buf); for ( i = 0 ; useStr[i] != NULL ; i++ ) fprintf (stdout, "%s\n", useStr[i]); exit (SUCCESS);}/* Display examples */static voidExamples (void){ char buf[BUFSIZ]; int i; setbuf (stderr, buf); for ( i = 0 ; egStr[i] != NULL ; i++ ) fprintf (stdout, "%s\n", egStr[i]); exit (SUCCESS);}/* Display software copyright */static voidCopyright (void){ char buf[BUFSIZ]; int i; setbuf (stderr, buf); for ( i = 0 ; cpStr[i] != NULL ; i++ ) fprintf (stdout, "%s\n", cpStr[i]); exit (SUCCESS);}/* Display software license */static voidLicense (void){ char buf[BUFSIZ]; int i; setbuf (stderr, buf); for ( i = 0 ; lcStr[i] != NULL ; i++ ) fprintf (stdout, "%s\n", lcStr[i]); exit (SUCCESS);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -