filtercolorcube.cc

 1 const char *help = "\
 2 progname: filtercolorcube.cc\n\
 3 code2html: This program reads a ppm image and filter it using a colorcube.\n\
 4 version: Torch3 vision2.0, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "ipColorCube.h"
 9 #include "DiskXFile.h"
10 #include "xtprobeImageDiskXFile.h"
11 #include "CmdLine.h"
12 
13 using namespace Torch;
14 
15 int main(int argc, char **argv)
16 {
17 	char *image_filename;
18 	char *colorcube_filename;
19 	bool verbose;
20   
21 	// Construct the command line
22   	CmdLine cmd;
23 	cmd.setBOption("write log", false);
24 	
25   	// Put the help line at the beginning
26   	cmd.info(help);
27 
28   	cmd.addText("\nArguments:");
29   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
30   	cmd.addSCmdArg("colorcube filename", &colorcube_filename, "colorcube filename");
31   	cmd.addText("\nOptions:");
32   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
33 
34 	cmd.read(argc, argv);
35 
36 
37 	Image *image_in = NULL;
38 	Image *image_out = NULL;
39 
40 	image_in = new ImageRgb();
41 	image_in->setBOption("verbose", verbose);
42 	
43 	ImageDiskXFile *image_loader = new xtprobeImageDiskXFile(image_filename, "r");
44 	image_in->loadImageXFile(image_loader);
45 	delete image_loader;
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 ipColorCube(image_in->width, image_in->height, "rgb");
58 	imachine->setBOption("verbose", verbose);
59 	imachine->load(colorcube_filename);
60 	imachine->process(image_in);
61 	
62 	image_out = new ImageRgb();
63 	image_out->setBOption("verbose", verbose);
64 
65 	image_out->copyFrom(image_in->width, image_in->height, imachine->seq_out->frames[0], "rgb");
66 	
67 	DiskXFile *image_file = new DiskXFile("filter.ppm", "w");
68 	image_out->saveXFile(image_file);
69 	delete image_file;
70 
71 	delete imachine;
72 	delete image_out;
73 	delete image_in;
74 
75 	return(0);
76 }