00001 /* 00002 * Filtered Image Rescaling 00003 * 00004 * by Dale Schumacher 00005 * 00006 */ 00007 00008 /* 00009 Additional changes by Ray Gardener, Daylon Graphics Ltd. 00010 December 4, 1999 00011 00012 Additional changes by Rob Peters, University of Southern California 00013 August 23, 2007 00014 00015 Summary: 00016 00017 - Horizontal filter contributions are calculated on the fly, 00018 as each column is mapped from src to dst image. This lets 00019 us omit having to allocate a temporary full horizontal stretch 00020 of the src image. 00021 00022 - If none of the src pixels within a sampling region differ, 00023 then the output pixel is forced to equal (any of) the source pixel. 00024 This ensures that filters do not corrupt areas of constant color. 00025 00026 - Filter weight contribution results, after summing, are 00027 rounded to the nearest pixel color value instead of 00028 being casted to T (usually an int or char). Otherwise, 00029 artifacting occurs. 00030 */ 00031 00032 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/app-fzoom.C $ 00033 // $Id: app-fzoom.C 8722 2007-08-25 00:42:17Z rjpeters $ 00034 00035 #include "Image/Image.H" 00036 #include "Image/ShapeOps.H" 00037 #include "Raster/Raster.H" 00038 #include "Util/Assert.H" 00039 #include "Util/CpuTimer.H" 00040 #include "Util/StringUtil.H" 00041 #include "Util/Types.H" 00042 #include "Util/log.H" 00043 #include "Util/sformat.H" 00044 00045 #include <stdio.h> 00046 #include <stdlib.h> 00047 #include <string.h> 00048 #include <math.h> 00049 #include <unistd.h> // for getopt() et al 00050 #include <vector> 00051 00052 00053 /* 00054 * command line interface 00055 */ 00056 00057 static 00058 void 00059 usage(const char* argv0) 00060 { 00061 fprintf(stderr, "usage: %s [-options] input output\n", argv0); 00062 fprintf(stderr, "\ 00063 options:\n\ 00064 -x xsize output x size\n\ 00065 -y ysize output y size\n\ 00066 -f filter filter type\n\ 00067 {b=box, t=triangle, q=bell, B=B-spline, h=hermite, l=Lanczos3, m=Mitchell}\n\ 00068 input, output files to read/write.\n\ 00069 "); 00070 exit(1); 00071 } 00072 00073 int 00074 main(int argc, char* argv[]) 00075 { 00076 int c; 00077 int xsize = 0, ysize = 0; 00078 00079 RescaleType ftype = RESCALE_FILTER_TRIANGLE; 00080 00081 while ((c = getopt(argc, argv, "x:y:f:")) != EOF) { 00082 switch(c) { 00083 case 'x': xsize = atoi(optarg); break; 00084 case 'y': ysize = atoi(optarg); break; 00085 case 'f': ftype = getRescaleTypeFromChar(*optarg); break; 00086 case '?': usage(argv[0]); 00087 default: usage(argv[0]); 00088 } 00089 } 00090 00091 if ((argc - optind) != 2) usage(argv[0]); 00092 const char* srcfile = argv[optind]; 00093 const char* dstfile = argv[optind + 1]; 00094 00095 const Image<byte> src = Raster::ReadGray(srcfile); 00096 00097 const Dims newdims(xsize <= 0 ? src.getWidth() : xsize, 00098 ysize <= 0 ? src.getHeight() : ysize); 00099 00100 CpuTimer tm; 00101 00102 const Image<byte> dst = rescale(src, newdims, ftype); 00103 00104 tm.mark(); 00105 tm.report(sformat("%8s %dx%d -> %dx%d", 00106 convertToString(ftype).c_str(), 00107 src.getWidth(), src.getHeight(), 00108 newdims.w(), newdims.h()).c_str()); 00109 00110 Raster::WriteGray(dst, dstfile); 00111 00112 return 0; 00113 } 00114 00115 // ###################################################################### 00116 /* So things look consistent in everyone's emacs... */ 00117 /* Local Variables: */ 00118 /* indent-tabs-mode: nil */ 00119 /* c-file-style: "linux" */ 00120 /* End: */