dct2D.cc

 1 const char *help = "\
 2 progname: dct2D.cc\n\
 3 code2html: This program reads a pgm image and computes its DCT 2D.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageGray.h"
 8 #include "ipDCT2D.h"
 9 #include "ipEnhanceDCT2D.h"
10 #include "DiskXFile.h"
11 #include "CmdLine.h"
12 
13 using namespace Torch;
14 
15 int main(int argc, char **argv)
16 {
17 	char *image_filename;
18 	bool verbose;
19 	bool normalise;
20 	bool enhance;
21 	real lambda;
22 	int dimDCT;
23   
24   	
25 	CmdLine cmd;
26 	cmd.setBOption("write log", false);
27   	cmd.info(help);
28   	cmd.addText("\nArguments:");
29   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
30   	cmd.addText("\nOptions:");
31   	cmd.addICmdOption("-dim", &dimDCT, 15, "DCT dimensionality");
32   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
33   	cmd.addBCmdOption("-normalise", &normalise, false, "normalise");
34   	cmd.addBCmdOption("-enhance", &enhance, false, "enhance");
35   	cmd.addRCmdOption("-lambda", &lambda, 1.5, "lambda for enhancement");
36 	cmd.read(argc, argv);
37 
38 
39 	Image *image_in = NULL;
40 
41 	image_in = new ImageGray();
42 	image_in->setBOption("verbose", verbose);
43 	image_in->load(image_filename);
44 
45 	if(verbose)
46 	{
47 		print("Image info:\n");
48 		print("   width = %d\n", image_in->width);
49 		print("   height = %d\n", image_in->height);
50 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
51 	}
52 
53 	ipCore *dct2d = NULL;
54 
55 	if(enhance) dct2d = new ipEnhanceDCT2D(image_in->width, "gray", dimDCT, lambda);
56 	else dct2d = new ipDCT2D(image_in->width, "gray", dimDCT);
57 	dct2d->setBOption("verbose", verbose);
58 	dct2d->process(image_in);
59 
60 	real *dct = dct2d->seq_out->frames[0];
61 
62 	real energy = 0;
63 	
64 	for(int i = 0; i < dct2d->seq_out->frame_size; i++)
65 	{
66 		print("[%d] = %g\n", i, dct[i]);
67 
68 		energy += dct[i] * dct[i];
69 	}
70 
71 	energy = sqrt(energy);
72 	real log_energy = energy < 1.0 ? 0.0 : (real) log(energy); 
73 
74 	print("log Energy = %g\n", log_energy);
75 	
76 	delete dct2d;
77 	delete image_in;
78 
79 	return(0);
80 }