📄 wpt_bitalloc.c
字号:
/****************************************************************************** * * Copyright Jill R. Goldschneider, 1998 * * This work was partially supported by a NASA Graduate Student * Fellowship in Global Change Research, an NSF Young Investigator Award, * and U.~S. Army Research Grant DAAH004-96-1-0255. * *****************************************************************************//****************************************************************************** * * FILE wpt_bitalloc.c * AUTHOR Jill R. Goldschneider * DATE February 1997 * REVISIONS February 1998 - update documentation * DESCRIPTION main function call * *****************************************************************************/#include "wpt.h"/****************************************************************************** * DOCUMENTATION ******************************************************** ****************************************************************************** NAME main DESCRIPTION Command-line interface to systematic joint best-basis selection and optimal bit allocation algorithm. ARGUMENTS IARG argc IARG argv RETURN ALGORITHM The command-line interface is of the form ``{\tt wpt_bitalloc -c list_of_codebooks -l level -d dimension -r stopping_rate}'' where \\ ``-c'' required the prefix used for the codebook files, \\ ``-l'' is the number of levels of wavelet packet decomposition, \\ ``-d'' is the number of subbands per node (4 for images), and \\ ``-r'' is the desired stopping rate in bits per pixel. \\ \\ This program can produce any tree from (rate 0, highest distortion) to (highest rate, 0 distortion), where the rate is the average number of bits per pixel and the distortion the average mean squared error per pixel. NOTE This prints the slope, rate, and distortion of each iteration of the joint best-basis selection and optimal bit allocation to stdout. \\ \\ The codebook file names should be codebookfilename.$i$.$j$.$k$... where codebookfilename is used for the 0 level codebook, and $i$ is the $i$th subband of the decomposition of the original data, and $j$ is the $j$th subband of the decomposition of the $i$th subband, and so on. \\ \\ The codebook files should contain a list of GBFOS optimal points including rate, distortion, slope, subtree number, and number of nodes. These files can be generated by directing the output of prune into a file. \\ \\ Several files are output, each containing a script to assist encoding, decoding, and reconstruction of test data. The scripts use programs from the tsvq code. AUTHOR Jill R. Goldschneider******************************************************************************/void main(int argc, char *argv[]){ TreeNode *root; /* root of codebook tree */ char codebookname[NAME_MAX]; /* name of codebook file */ char outputname[NAME_MAX]; /* name of output file */ char shortname[NAME_MAX]; /* name of output file */ char option; /* used for command lint interpretation */ FILE *outputfile; /* output file */ double rate; /* current rate */ double stoppingrate; /* stopping rate */ double distortion; /* distortion of codebook and training set */ float userrate; /* rate needs to be read as float */ /* assign defaults */ strcpy(codebookname, DEF_codebookname); programname = *argv; treedim = DEF_treedim; treelevel = DEF_treelevels; userrate = DEF_rate; stoppingrate = (double) userrate; /* if no options entered, list all of the defaults */ if (argc == 1) { printf("%s %s %s\n", USAGE, programname, HOWTOUSE_WPT); printf("\nOPTIONS DESCRIPTIONS DEFAULTS\n"); printf("-c list of codebooks %s\n", codebookname); printf("-l levels of decomposition %d\n", treelevel); printf("-d tree dimension %d\n", treedim); printf("-r stopping rate (bits per pixel) %g\n", userrate); printf("\n"); fflush(stdout); exit(0); } /* read and interpret command line arguments */ while (--argc && ++argv) { if (*argv[0]=='-' && (strlen(*argv)==2)) { /* each option has 1 letter */ option = *++argv[0]; if (--argc && ++argv) { /* examine the option */ switch(option) { /* examine the option letter */ case 'c': strncpy(shortname, *argv, NAME_MAX); sprintf(codebookname, "%s", shortname); break; case 'l': sscanf(*argv, "%d", &treelevel); break; case 'd': sscanf(*argv, "%d", &treedim); break; case 'r': sscanf(*argv, "%f", &userrate); stoppingrate = ((double) userrate); break; default: fprintf(stderr, "%s: %c: %s\n", programname, option, NOTOPTION); exit(1); break; } } else { fprintf(stderr, "%s %s %s\n", USAGE, programname, HOWTOUSE_WPT); exit(2); } } else if (*argv[0] == '-') { /* user entered unknown option */ ++argv[0]; fprintf(stderr, "%s: %s: %s\n", programname, *argv, NOTOPTION); exit(3); } else { /* user entered unknown string */ fprintf(stderr, "%s: %s: %s\n", programname, *argv, NOTOPTION); exit(4); } } /* user entered invalid arguments */ if (treedim <= 0 || treelevel < 0 || userrate < 0){ fprintf(stderr, "%s %s %s\n", USAGE, programname, HOWTOUSE_WPT); exit(5); } /* user did not enter an file names */ if (strlen(codebookname) == 0) { fprintf(stderr, "%s %s %s\n", USAGE, programname, HOWTOUSE_WPT); } printf("\nOPTIONS DESCRIPTIONS SETTINGS\n"); printf("-c list of codebooks %s\n", codebookname); printf("-l level of decomposition %d\n", treelevel); printf("-d tree dimension %d\n", treedim); printf("-r stopping rate %g\n", stoppingrate); /* create the root of the main tree, and construct the tree. This includes reading the rate-distortion data. */ if(!(root = create_root())) exit(6); if(!(construct_tree(root, codebookname))) exit(8); /* initialize the tree, and pruning */ initialize_tree(root); wpt_bitalloc(root, stoppingrate, &(rate), &(distortion)); /* open the output files here */ /* first make the select and encoding script */ sprintf(outputname, "%s.l%d.rate%g.sh", shortname, treelevel, stoppingrate); if(!(outputfile = fopen(outputname, "w"))) { fprintf(stderr, "%s: %s: %s\n", programname, outputname, NOTFOUND); exit(7); } /* then put in text for the script */ fprintf(outputfile, "#!/bin/sh -x\n\n"); fprintf(outputfile, "# design rate = %15f actual rate = %15f distortion = %15f\n\n", stoppingrate, rate, distortion); map_tree(root, outputfile, shortname); fprintf(outputfile, "\n\n# encode the image next\n\n"); encode_tree(root, outputfile, shortname); fclose(outputfile); /* second make the unblocking script */ sprintf(outputname, "%s.l%d.unblock.rate%g.sh", shortname, treelevel, stoppingrate); if(!(outputfile = fopen(outputname, "w"))) { fprintf(stderr, "%s: %s: %s\n", programname, outputname, NOTFOUND); exit(8); } /* then put in text for the script */ fprintf(outputfile, "#!/bin/sh -x\n\n"); unblock_tree(root, outputfile); fclose(outputfile); /* third make the matlab script to read the subbands and rebuild the image*/ sprintf(outputname, "%s.l%d.rate%g.m", shortname, treelevel, stoppingrate); if(!(outputfile = fopen(outputname, "w"))) { fprintf(stderr, "%s: %s: %s\n", programname, outputname, NOTFOUND); exit(9); } /* then put in text for the script */ fprintf(outputfile, "s8 = MakeONFilter('Symmlet',8);\n\n"); rebuild_tree(root, outputfile); /* assume image is 512 by 512 and 8bpp, modify as needed */ fprintf(outputfile, "\nx = readimage('timage',512,512,'double');\n"); fprintf(outputfile, "x = floor(x+0.5);\n"); fprintf(outputfile, "x = x.*(x>0);\n"); fprintf(outputfile, "x = x.*(x<256);\n"); fprintf(outputfile, "writeimage(x,'final_image','uchar');\n"); fclose(outputfile); exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -