x2pgm.cc

 1 const char *help = "\
 2 progname: x2pgm.cc\n\
 3 code2html: This program reads an image and saves it as a pgm.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageGray.h"
 8 #include "xtprobeImageDiskXFile.h"
 9 
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 	// Construct the command line
20   	CmdLine cmd;
21 	cmd.setBOption("write log", false);
22 	
23   	// Put the help line at the beginning
24   	cmd.info(help);
25 
26   	cmd.addText("\nArguments:");
27   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
28   	cmd.addText("\nOptions:");
29   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
30 
31 	cmd.read(argc, argv);
32 
33   	ImageDiskXFile *image_file = NULL;
34 	Image *grayimage = NULL;
35 
36 	grayimage = new ImageGray();
37 	grayimage->setBOption("verbose", verbose);
38 
39 	image_file = new xtprobeImageDiskXFile(image_filename, "r");
40 	grayimage->loadImageXFile(image_file);
41 	delete image_file;
42 
43 	if(verbose)
44 	{
45 		print("Image info:\n");
46 		print("   width = %d\n", grayimage->width);
47 		print("   height = %d\n", grayimage->height);
48 		print("   format = %s (%d)\n", grayimage->coding, grayimage->n_planes);
49 	}
50 	
51 	grayimage->save("gray.pgm");
52 	
53 	delete grayimage;
54 
55 	return(0);
56 }