open.cc

 1 const char *help = "\
 2 progname: open.cc\n\
 3 code2html: This program reads an image and apply open image morphology operator.\n\
 4 version: Torch3 vision2.0, 2003-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageGray.h"
 8 #include "ipOpen.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 	int iteration;
18 	int radius;
19 	int threshold;
20 	bool verbose;
21   
22 	
23   	CmdLine cmd;
24 	cmd.setBOption("write log", false);
25   	cmd.info(help);
26   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
27   	cmd.addText("\nOptions:");
28   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
29   	cmd.addICmdOption("-iteration", &iteration, 1, "iteration");
30   	cmd.addICmdOption("-radius", &radius, 1, "radius");
31   	cmd.addICmdOption("-threshold", &threshold, 100, "threshold");
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 *morph = NULL;
55 
56 	morph = new ipOpen(image_in->width, image_in->height, "gray", iteration, radius, threshold);
57 	morph->setBOption("verbose", verbose);
58 	morph->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, morph->seq_out->frames[0], "gray");
64 	
65 	image_file = new DiskXFile("open.pgm", "w");
66 	image_out->saveXFile(image_file);
67 	delete image_file;
68 
69 	delete morph;
70 	delete image_out;
71 	delete image_in;
72 
73 	return(0);
74 }