enhancepgm.cc

 1 const char *help = "\
 2 progname: enhancepgm.cc\n\
 3 code2html: This program reads a pgm image and enhance it using histogram equalization.\n\
 4 version: Torch3 vision2.0, 2003-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageGray.h"
 8 #include "ipHistoEqual.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   
19 	
20   	CmdLine cmd;
21 	cmd.setBOption("write log", false);
22   	cmd.info(help);
23   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
24   	cmd.addText("\nOptions:");
25   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
26 	cmd.read(argc, argv);
27 
28 
29   	DiskXFile *image_file = NULL;
30 	Image *image_in = NULL;
31 	Image *image_out = NULL;
32 
33 	image_in = new ImageGray();
34 	image_in->setBOption("verbose", verbose);
35 	
36 	image_file = new DiskXFile(image_filename, "r");
37 	image_in->loadXFile(image_file);
38 	delete image_file;
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 *enhance = NULL;
49 
50 	enhance = new ipHistoEqual(image_in->width, image_in->height, "gray");
51 	enhance->setBOption("verbose", verbose);
52 	enhance->process(image_in);
53 	
54 	image_out = new ImageGray();
55 	image_out->setBOption("verbose", verbose);
56 
57 	image_out->copyFrom(image_in->width, image_in->height, enhance->seq_out->frames[0], "gray");
58 	
59 	image_file = new DiskXFile("enhance.pgm", "w");
60 	image_out->saveXFile(image_file);
61 	delete image_file;
62 
63 	delete enhance;
64 	delete image_out;
65 	delete image_in;
66 
67 	return(0);
68 }