00001 /*!@file AppMedia/app-create-thumbnails.C Create small images from originals */ 00002 00003 ////////////////////////////////////////////////////////////////////////// 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 ////////////////////////////////////////////////////////////////////////// 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 ////////////////////////////////////////////////////////////////////////// 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 ////////////////////////////////////////////////////////////////////////// 00032 // 00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/app-create-thumbnails.C $ 00035 // $Id: app-create-thumbnails.C 13712 2010-07-28 21:00:40Z itti $ 00036 // 00037 00038 #include "Image/Image.H" 00039 #include "Image/FilterOps.H" 00040 #include "Image/ShapeOps.H" 00041 #include "Image/Pixels.H" 00042 #include "Raster/Raster.H" 00043 00044 #include <cstdio> 00045 00046 #define TSIZEX 64 00047 #define TBORDER 2 00048 #define TSIZEY (TSIZEX + TBORDER) 00049 #define TNAME "thumbnails.ppm" 00050 00051 int main(int argc, char** argv) 00052 { 00053 PixRGB<byte> cpix(255, 0, 0); 00054 00055 if (argc == 1) 00056 { 00057 LERROR("USAGE: %s <image.ppm> .. <image.ppm>\n" 00058 " puts the thumbnails in 'thumbnails.ppm'\n", argv[0]); 00059 return 1; 00060 } 00061 00062 Image< PixRGB<byte> > thumb(TSIZEX * (argc - 1) + TBORDER * (argc - 2), 00063 TSIZEY, ZEROS); 00064 00065 for (int i = 1; i < argc; i ++) 00066 { 00067 bool compressed = false; 00068 if (argv[i][strlen(argv[i])-1] == 'z') { 00069 char t[1000]; sprintf(t, "gunzip %s",argv[i]); 00070 if (system(t)) LERROR("Error in system()"); 00071 argv[i][strlen(argv[i])-3]='\0'; compressed = true; 00072 } 00073 Image< PixRGB<byte> > tmp = Raster::ReadRGB(argv[i]); 00074 if (compressed) { 00075 char t[1000]; sprintf(t, "gzip -9 %s", argv[i]); 00076 if (system(t)) LERROR("Error in system()"); 00077 } 00078 00079 // low-pass filter 00080 tmp = lowPass9(lowPass9(lowPass9(tmp))); 00081 00082 // preserve aspect ratio 00083 float sx = ((float)TSIZEX) / ((float)tmp.getWidth()); 00084 float sy = ((float)TSIZEX) / ((float)tmp.getHeight()); 00085 float scale = (sx <= sy ? sx : sy); 00086 int w = (int)(scale * ((float)tmp.getWidth())); 00087 int h = (int)(scale * ((float)tmp.getHeight())); 00088 if (w > TSIZEX) w = TSIZEX; 00089 if (h > TSIZEY) h = TSIZEY; 00090 00091 int xoffset = (TSIZEX + TBORDER) * (i - 1) + (TSIZEX - w) / 2; 00092 int yoffset = (TSIZEY - h) / 2; 00093 00094 LDEBUG("%s: (%d, %d) at (%d, %d)", argv[i], w, h, xoffset, yoffset); 00095 tmp = rescale(tmp, w, h); 00096 00097 PixRGB<byte> pix; 00098 for (int yy = 0; yy < h; yy ++) 00099 for (int xx = 0; xx < w; xx ++) 00100 { 00101 tmp.getVal(xx, yy, pix); 00102 thumb.setVal(xx + xoffset, yy + yoffset, pix); 00103 } 00104 00105 // put border 00106 if (i < argc - 1) 00107 for (int yy = 0; yy < TSIZEY; yy ++) 00108 for (int xx = TSIZEX; xx < TSIZEX+TBORDER; xx ++) 00109 thumb.setVal(xx + (TSIZEX+TBORDER)*(i-1), yy, cpix); 00110 00111 } 00112 Raster::WriteRGB(thumb, TNAME, RASFMT_PNM); 00113 return 0; 00114 } 00115 00116 // ###################################################################### 00117 /* So things look consistent in everyone's emacs... */ 00118 /* Local Variables: */ 00119 /* indent-tabs-mode: nil */ 00120 /* End: */