xlist2pgm.cc

 1 const char *help = "\
 2 progname: xlist2pgm.cc\n\
 3 code2html: This program reads a list of image and saves them 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 "FileListCmdOption.h"
11 #include "CmdLine.h"
12 
13 using namespace Torch;
14 
15 int main(int argc, char **argv)
16 {
17 	bool verbose;
18 	bool savepgm;
19 
20 	FileListCmdOption imagelist("imagelist", "the list of image filename or one image filename");
21 	imagelist.isArgument(true);
22 
23 	// Construct the command line
24   	CmdLine cmd;
25 	cmd.setBOption("write log", false);
26 	
27   	// Put the help line at the beginning
28   	cmd.info(help);
29 
30   	cmd.addText("\nArguments:");
31 	cmd.addCmdOption(&imagelist);
32   	cmd.addText("\nOptions:");
33   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
34   	cmd.addBCmdOption("-savepgm", &savepgm, false, "save as pgm");
35 
36 	cmd.read(argc, argv);
37 
38   	ImageDiskXFile *image_file = NULL;
39 	Image *grayimage = NULL;
40 
41 	grayimage = new ImageGray();
42 	grayimage->setBOption("verbose", verbose);
43 
44 	for(int i = 0 ; i < imagelist.n_files ; i++)
45 	{
46 		image_file = new xtprobeImageDiskXFile(imagelist.file_names[i], "r");
47 		grayimage->loadImageXFile(image_file);
48 		delete image_file;
49 
50 		if(verbose)
51 		{
52 			print("Image info (%s):\n", imagelist.file_names[i]);
53 			print("   width = %d\n", grayimage->width);
54 			print("   height = %d\n", grayimage->height);
55 			print("   format = %s (%d)\n", grayimage->coding, grayimage->n_planes);
56 		}
57 	
58 		if(savepgm)
59 			grayimage->save("gray.pgm");
60 	}
61 	
62 	delete grayimage;
63 
64 	return(0);
65 }