gamma.cc

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