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 "DiskXFile.h"
10 #include "CmdLine.h"
11 
12 using namespace Torch;
13 
14 int main(int argc, char **argv)
15 {
16 	char *image_filename;
17 	bool verbose;
18 	bool normalise;
19 	int dimDCT;
20   
21   	
22 	CmdLine cmd;
23 	cmd.setBOption("write log", false);
24   	cmd.info(help);
25   	cmd.addText("\nArguments:");
26   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
27   	cmd.addText("\nOptions:");
28   	cmd.addICmdOption("-dim", &dimDCT, 15, "DCT dimensionality");
29   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
30   	cmd.addBCmdOption("-normalise", &normalise, false, "normalise");
31 	cmd.read(argc, argv);
32 
33 
34 	Image *image_in = NULL;
35 
36 	image_in = new ImageGray();
37 	image_in->setBOption("verbose", verbose);
38 	image_in->load(image_filename);
39 
40 	if(verbose)
41 	{
42 		print("Image info:\n");
43 		print("   width = %d\n", image_in->width);
44 		print("   height = %d\n", image_in->height);
45 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
46 	}
47 
48 	ipCore *dct2d = NULL;
49 
50 	dct2d = new ipDCT2D(image_in->width, "gray", dimDCT);
51 	dct2d->setBOption("verbose", verbose);
52 	dct2d->process(image_in);
53 
54 	real *dct = dct2d->seq_out->frames[0];
55 
56 	real energy = 0;
57 	
58 	for(int i = 0; i < dct2d->seq_out->frame_size; i++)
59 	{
60 		print("[%d] = %g\n", i, dct[i]);
61 
62 		energy += dct[i] * dct[i];
63 	}
64 
65 	energy = sqrt(energy);
66 	real log_energy = energy < 1.0 ? 0.0 : (real) log(energy); 
67 
68 	print("log Energy = %g\n", log_energy);
69 	
70 	delete dct2d;
71 	delete image_in;
72 
73 	return(0);
74 }