smoothpgm.cc

 1 const char *help = "\
 2 progname: smoothpgm.cc\n\
 3 code2html: This program reads a pgm image and smooth 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 "ipSmoothGaussian3.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 	real sigma;
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   	cmd.addRCmdOption("-sigma", &sigma, 0.25, "sigma");
32 
33 	cmd.read(argc, argv);
34 
35 
36   	DiskXFile *image_file = NULL;
37 	Image *image_in = NULL;
38 	Image *image_out = NULL;
39 
40 	image_in = new ImageGray();
41 	image_in->setBOption("verbose", verbose);
42 	
43 	image_file = new DiskXFile(image_filename, "r");
44 	image_in->loadXFile(image_file);
45 	delete image_file;
46 
47 	if(verbose)
48 	{
49 		print("Image info:\n");
50 		print("   width = %d\n", image_in->width);
51 		print("   height = %d\n", image_in->height);
52 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
53 	}
54 
55 	ipCore *imachine = NULL;
56 
57 	imachine = new ipSmoothGaussian3(image_in->width, image_in->height, "gray", sigma);
58 	imachine->setBOption("verbose", verbose);
59 	imachine->process(image_in);
60 	
61 	image_out = new ImageGray();
62 	image_out->setBOption("verbose", verbose);
63 
64 	image_out->copyFrom(image_in->width, image_in->height, imachine->seq_out->frames[0], "gray");
65 	
66 	image_file = new DiskXFile("smooth.pgm", "w");
67 	image_out->saveXFile(image_file);
68 	delete image_file;
69 
70 	delete imachine;
71 	delete image_out;
72 	delete image_in;
73 
74 	return(0);
75 }