shiftpgm.cc

 1 const char *help = "\
 2 progname: shiftpgm.cc\n\
 3 code2html: This program reads a pgm image and shift its content.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageGray.h"
 8 #include "ipShift.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 	int shiftx, shifty;
19   
20 
21   	CmdLine cmd;
22 	cmd.setBOption("write log", false);
23   	cmd.info(help);
24   	cmd.addText("\nArguments:");
25   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
26   	cmd.addICmdArg("shift x", &shiftx, "shift x");
27   	cmd.addICmdArg("shift y", &shifty, "shift y");
28   	cmd.addText("\nOptions:");
29   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
30 	cmd.read(argc, argv);
31 
32 
33   	DiskXFile *image_file = NULL;
34 	Image *image_in = NULL;
35 	Image *image_out = NULL;
36 
37 	image_in = new ImageGray();
38 	image_in->setBOption("verbose", verbose);
39 	
40 	image_file = new DiskXFile(image_filename, "r");
41 	image_in->loadXFile(image_file);
42 	delete image_file;
43 
44 	if(verbose)
45 	{
46 		print("Image info:\n");
47 		print("   width = %d\n", image_in->width);
48 		print("   height = %d\n", image_in->height);
49 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
50 	}
51 
52 	ipCore *shift = NULL;
53 
54 	shift = new ipShift(image_in->width, image_in->height, "gray");
55 	shift->setBOption("verbose", verbose);
56 	shift->setIOption("shiftx", shiftx);
57 	shift->setIOption("shifty", shifty);
58 	shift->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, shift->seq_out->frames[0], "gray");
64 	
65 	image_file = new DiskXFile("shift.pgm", "w");
66 	image_out->saveXFile(image_file);
67 	delete image_file;
68 
69 	delete shift;
70 	delete image_out;
71 	delete image_in;
72 
73 	return(0);
74 }