lightnormpgm.cc

 1 const char *help = "\
 2 progname: lightnormpgm.cc\n\
 3 code2html: This program reads a pgm image and normalizes it.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageGray.h"
 8 #include "ipNormBestFitLinear.h"
 9 #include "ipNormMeanLight.h"
10 #include "ipNormMeanStdvLight.h"
11 #include "DiskXFile.h"
12 #include "CmdLine.h"
13 
14 using namespace Torch;
15 
16 int main(int argc, char **argv)
17 {
18 	char *image_filename;
19 	bool verbose;
20  	bool linear;
21 	bool meanstdv;
22 	
23 	// Construct the command line
24   	CmdLine cmd;
25 	cmd.setBOption("write log", false);
26 	
27   	// Put the help line at the beginning
28   	cmd.info(help);
29 
30   	cmd.addText("\nArguments:");
31   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
32   	cmd.addText("\nOptions:");
33   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
34   	cmd.addBCmdOption("-linear", &linear, false, "linear light plane normalisation");
35   	cmd.addBCmdOption("-meanstdv", &meanstdv, false, "meanstdv light plane normalisation");
36 
37 	cmd.read(argc, argv);
38 
39 
40   	DiskXFile *image_file = NULL;
41 	Image *image_in = NULL;
42 	Image *image_out = NULL;
43 
44 	image_in = new ImageGray();
45 	image_in->setBOption("verbose", verbose);
46 	
47 	image_file = new DiskXFile(image_filename, "r");
48 	image_in->loadXFile(image_file);
49 	delete image_file;
50 
51 	if(verbose)
52 	{
53 		print("Image info:\n");
54 		print("   width = %d\n", image_in->width);
55 		print("   height = %d\n", image_in->height);
56 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
57 	}
58 
59 	ipCore *imachine = NULL;
60 
61 	if(linear) imachine = new ipNormBestFitLinear(image_in->width, image_in->height, "gray");
62 	else if(meanstdv) imachine = new ipNormMeanStdvLight(image_in->width, image_in->height, "gray");
63 	else imachine = new ipNormMeanLight(image_in->width, image_in->height, "gray");
64 
65 	imachine->setBOption("verbose", verbose);
66 	imachine->process(image_in);
67 	
68 	image_out = new ImageGray();
69 	image_out->setBOption("verbose", verbose);
70 
71 	image_out->copyFrom(image_in->width, image_in->height, imachine->seq_out->frames[0], "gray");
72 	image_out->save("lightnorm.pgm");
73 
74 	image_out->copyFrom(image_in->width, image_in->height, imachine->seq_out->frames[1], "gray");
75 	image_out->save("lightplane.pgm");
76 
77 	delete imachine;
78 	delete image_out;
79 	delete image_in;
80 
81 	return(0);
82 }