subsamplejpeg.cc

 1 const char *help = "\
 2 progname: subsamplejpeg.cc\n\
 3 code2html: This program reads a color image and subsample it.\n\
 4 version: Torch3 vision2.1, 2004-2005\n\
 5 (c) Sebastien Marcel (marcel@idiap.ch)\n";
 6 
 7 #include "ImageRgb.h"
 8 #include "ipSubsample.h"
 9 #include "ipScale_yx.h"
10 #include "xtprobeImageDiskXFile.h"
11 #include "jpegDiskXFile.h"
12 #include "DiskXFile.h"
13 #include "CmdLine.h"
14 
15 using namespace Torch;
16 
17 int main(int argc, char **argv)
18 {
19 	char *image_filename;
20 	int width_out;
21 	int height_out;
22 	bool verbose;
23 	bool yx;
24   
25   	
26 	CmdLine cmd;
27 	cmd.setBOption("write log", false);
28   	cmd.info(help);
29   	cmd.addText("\nArguments:");
30   	cmd.addSCmdArg("image filename", &image_filename, "image filename");
31   	cmd.addICmdArg("new width", &width_out, "new width");
32   	cmd.addICmdArg("new height", &height_out, "new height");
33   	cmd.addText("\nOptions:");
34   	cmd.addBCmdOption("-verbose", &verbose, false, "verbose");
35   	cmd.addBCmdOption("-yx", &yx, false, "use yx subsampling");
36 	cmd.read(argc, argv);
37 
38 
39   	ImageDiskXFile *image_file = NULL;
40 	Image *image_in = NULL;
41 	Image *image_out = NULL;
42 
43 	image_in = new ImageRgb();
44 	image_in->setBOption("verbose", verbose);
45 
46         image_file = new xtprobeImageDiskXFile(image_filename, "r");
47         image_in->loadImageXFile(image_file);
48         delete image_file;
49 
50 	if(verbose)
51 	{
52 		print("Image info:\n");
53 		print("   width = %d\n", image_in->width);
54 		print("   height = %d\n", image_in->height);
55 		print("   format = %s (%d)\n", image_in->coding, image_in->n_planes);
56 	}
57 
58 	ipCore *submachine = NULL;
59 
60 	if(yx) submachine = new ipScale_yx(image_in->width, image_in->height, "rgb", width_out, height_out);
61 	else submachine = new ipSubsample(image_in->width, image_in->height, "rgb", width_out, height_out);
62 	submachine->setBOption("verbose", verbose);
63 	submachine->process(image_in);
64 	
65 	image_out = new ImageRgb();
66 	image_out->setBOption("verbose", verbose);
67 
68 	image_out->copyFrom(width_out, height_out, submachine->seq_out->frames[0], "rgb");
69 
70 	jpegDiskXFile *jpeg_file = new jpegDiskXFile("subsample.jpeg", "w");
71 	image_out->saveImageXFile(jpeg_file);	
72 	delete jpeg_file;
73 
74 	delete submachine;
75 	delete image_out;
76 	delete image_in;
77 
78 	return(0);
79 }