artificialLight.cc

 1 const char *help = "\
 2 progname: artificial_light.cc\n\
 3 code2html: This program reads a pgm image (grayscale) and artificially relight it.\n\
 4 \n\
 5 version: Torch3 vision2.0, 2005\n\
 6 (c) Guillaume Heusch (heusch@idiap.ch)\n";
 7 
 8 #include "ImageGray.h"
 9 #include "DiskXFile.h"
10 #include "CmdLine.h"
11 #include "ipArtiLight.h"
12 
13 using namespace Torch;
14 
15 int main(int argc, char **argv)
16 {
17   
18   char *image_filename;
19   char *out_filename;
20 
21   bool verbose;
22   int delta;
23   
24 
25   // --------------------- COMMAND LINE -------------------------------------------------------------------------
26   CmdLine cmd;
27   cmd.setBOption("write log", false);
28   cmd.info(help);
29 
30   cmd.addText("\nArguments:");
31   cmd.addSCmdArg("image_filename", &image_filename, "input image filename");
32   cmd.addSCmdArg("out_filename", &out_filename, "processed image filename");
33 
34   cmd.addText("\nOptions:");
35   cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
36   cmd.addICmdOption("-delta", &delta, 80, "illumination delta (in pixels)");
37 
38   cmd.read(argc, argv);
39 
40   Allocator *allocator = new Allocator;
41 
42 
43   // ----------------------- LOAD IMAGE --------------------------------------------------------------------------
44   DiskXFile *image_file = NULL;
45   Image *image_in = NULL;
46 
47   image_in = new(allocator) ImageGray();
48   image_in->setBOption("verbose", verbose);
49 	
50   image_file = new(allocator) DiskXFile(image_filename, "r");
51   image_in->loadXFile(image_file);
52 
53   if(verbose)
54     {
55       print("Image info:\n");
56       print("   width = %d\n", image_in->width);
57       print("   height = %d\n", image_in->height);
58       print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
59     }
60   
61   
62 
63   // ---------------------- PROCESSING IMAGE MACHINE ------------------------------------------------------------	
64   ipCore *artiLight = NULL;
65   artiLight = new(allocator) ipArtiLight(delta, image_in->width, image_in->height, "gray");
66   artiLight->setBOption("verbose", verbose);
67   artiLight->process(image_in);
68 
69 
70   // ----------------------- SAVE IMAGE(S)  --------------------------------------------------------------------------
71   Image *image_out = NULL;
72   image_out = new(allocator) ImageGray();
73   image_out->setBOption("verbose", verbose);
74 
75   image_out->copyFrom(image_in->width, image_in->height, artiLight->seq_out->frames[0], "gray", 255);
76  
77   image_out->updatePixmapFromData();
78   image_out->save(out_filename);
79 
80   // ---------------------- CLEAN UP -----------------------------------------------------------------------------
81   delete allocator;
82   	
83   return(0);	
84 }