flipmirrorpgm.cc

 1 const char *help = "\
 2 progname: flipmirrorpgm.cc\n\
 3 code2html: This program reads a pgm image and flip and mirror 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 "ipFlip.h"
 9 #include "ipMirror.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   
20 	// Construct the command line
21   	CmdLine cmd;
22 	cmd.setBOption("write log", false);
23 	
24   	// Put the help line at the beginning
25   	cmd.info(help);
26 
27   	cmd.addText("\nArguments:");
28   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
29   	cmd.addText("\nOptions:");
30   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
31 
32 	cmd.read(argc, argv);
33 
34 
35   	DiskXFile *image_file = NULL;
36 	Image *image_in = NULL;
37 	Image *image_out = NULL;
38 
39 	image_in = new ImageGray();
40 	image_in->setBOption("verbose", verbose);
41 	
42 	image_file = new DiskXFile(image_filename, "r");
43 	image_in->loadXFile(image_file);
44 	delete image_file;
45 
46 	if(verbose)
47 	{
48 		print("Image info:\n");
49 		print("   width = %d\n", image_in->width);
50 		print("   height = %d\n", image_in->height);
51 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
52 	}
53 
54 	ipCore *imachine = NULL;
55 
56 	imachine = new ipFlip(image_in->width, image_in->height, "gray");
57 	imachine->setBOption("verbose", verbose);
58 	imachine->process(image_in);
59 	
60 	image_out = new ImageGray();
61 	image_out->setBOption("verbose", verbose);
62 
63 	image_out->copyFrom(image_in->width, image_in->height, imachine->seq_out->frames[0], "gray");
64 	
65 	image_file = new DiskXFile("flip.pgm", "w");
66 	image_out->saveXFile(image_file);
67 	delete image_file;
68 
69 	delete imachine;
70 
71 	imachine = new ipMirror(image_in->width, image_in->height, "gray");
72 	imachine->setBOption("verbose", verbose);
73 	imachine->process(image_in);
74 
75 	image_out->copyFrom(image_in->width, image_in->height, imachine->seq_out->frames[0], "gray");
76 	
77 	image_file = new DiskXFile("mirror.pgm", "w");
78 	image_out->saveXFile(image_file);
79 	delete image_file;
80 	delete image_out;
81 	delete image_in;
82 
83 	return(0);
84 }