00001 /*!@file AppPsycho/app-randomize-luminance.C Generates stimuli with randomized 00002 luminance drawn from a uniform distribution with mean based on 00003 standard flicker photometry results, and variance 5*/ 00004 00005 // //////////////////////////////////////////////////////////////////// // 00006 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00007 // University of Southern California (USC) and the iLab at USC. // 00008 // See http://iLab.usc.edu for information about this project. // 00009 // //////////////////////////////////////////////////////////////////// // 00010 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00011 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00012 // in Visual Environments, and Applications'' by Christof Koch and // 00013 // Laurent Itti, California Institute of Technology, 2001 (patent // 00014 // pending; application number 09/912,225 filed July 23, 2001; see // 00015 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00016 // //////////////////////////////////////////////////////////////////// // 00017 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00018 // // 00019 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00020 // redistribute it and/or modify it under the terms of the GNU General // 00021 // Public License as published by the Free Software Foundation; either // 00022 // version 2 of the License, or (at your option) any later version. // 00023 // // 00024 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00025 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00026 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00027 // PURPOSE. See the GNU General Public License for more details. // 00028 // // 00029 // You should have received a copy of the GNU General Public License // 00030 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00031 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00032 // Boston, MA 02111-1307 USA. // 00033 // //////////////////////////////////////////////////////////////////// // 00034 // 00035 // Primary maintainer for this file: Vidhya Navalpakkam <navalpak@usc.edu> 00036 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppPsycho/app-randomize-luminance.C $ 00037 // $Id: app-randomize-luminance.C 12074 2009-11-24 07:51:51Z itti $ 00038 // 00039 00040 #include "Image/Image.H" 00041 #include "Component/ModelManager.H" 00042 #include "Image/Pixels.H" 00043 #include "Raster/Raster.H" 00044 00045 #include <cstdio> 00046 00047 // ###################################################################### 00048 00049 int main(const int argc, const char **argv) 00050 { 00051 MYLOGVERB = LOG_INFO; // suppress debug messages 00052 00053 // Instantiate a ModelManager: 00054 ModelManager manager("Generate randomized luminance stimuli"); 00055 00056 // Parse command-line: 00057 if (manager.parseCommandLine(argc, argv, 00058 "<target.ppm> " 00059 " <luminRef> <lumin2> <lumin3>" 00060 " <satRef> <sat2> <sat3>" 00061 " <perceptIncrement>", 1, -1)==false) 00062 return(1); 00063 00064 // let's get all our ModelComponent instances started: 00065 manager.start(); 00066 00067 // load up the frame and show a fixation cross on a blank screen: 00068 LINFO("Loading '%s'...", manager.getExtraArg(0).c_str()); 00069 Image< PixRGB<byte> > stim = 00070 Raster::ReadRGB(manager.getExtraArg(0)); 00071 00072 // read the luminance and saturation value of S1, S2 and S3 00073 int lumin[3]; float sat[3]; 00074 lumin[0] = manager.getExtraArgAs<int>(1); 00075 lumin[1] = manager.getExtraArgAs<int>(2); 00076 lumin[2] = manager.getExtraArgAs<int>(3); 00077 sat[0] = manager.getExtraArgAs<float>(4); 00078 sat[1] = manager.getExtraArgAs<float>(5); 00079 sat[2] = manager.getExtraArgAs<float>(6); 00080 const char* name = manager.getExtraArg(7).c_str(); 00081 float perceptIncrement = manager.getExtraArgAs<float>(8); 00082 int perceptLum = 0, refLum = 0; 00083 // generate stimuli with randomized luminance 00084 for (int i = 0; i < 3; i ++){ 00085 for (int j = 0; j < 3; j++) { 00086 // generate stimuli with the following lumin based on weber's law 00087 if (j == 0){ 00088 perceptLum = (int) (lumin[i]/(1+perceptIncrement)); 00089 refLum = (int) (lumin[0]/(1+perceptIncrement)); 00090 } 00091 else if (j == 1){ 00092 perceptLum = lumin[i]; 00093 refLum = lumin[0]; 00094 } 00095 else if (j == 2){ 00096 perceptLum = (int) (lumin[i] * (1+perceptIncrement)); 00097 refLum = (int) (lumin[0] * (1+perceptIncrement)); 00098 } 00099 // generate the r, g, b values for drawing the stimuli 00100 int red = (int) (perceptLum / (1.0f - 0.7875*sat[i])); 00101 int green = (int) ((perceptLum - 0.2125*red)/0.7875); 00102 PixRGB<byte> zero(0, 0, 0); 00103 // since the stimuli is red saturated, blue = green 00104 PixRGB<byte> rgb(red, green, green); 00105 int w = stim.getWidth(), h = stim.getHeight(); 00106 Image< PixRGB<byte> > target(w, h, ZEROS); 00107 // regenerate the image 00108 for (int x = 0; x < w; x++) 00109 for (int y = 0; y < h; y ++) { 00110 if (stim.getVal(x,y) == zero); // do nothing 00111 else { 00112 stim.setVal(x, y, rgb); 00113 // target undergoes 180 deg. rotation and (w,h)px translation 00114 target.setVal(w-x, h-y, rgb); 00115 } 00116 } 00117 // print this image to file 00118 char fileName[30]; 00119 sprintf (fileName, "%s_%.2f_%d.ppm", name, sat[i], refLum); 00120 LINFO ("%s: [r,g,b] = %d, %d, %d", fileName, red, green, green); 00121 Raster::WriteRGB (stim, fileName); 00122 sprintf (fileName, "t_sat_%.2f_%d.ppm", sat[i], refLum); 00123 LINFO ("%s: [r,g,b] = %d, %d, %d", fileName, red, green, green); 00124 Raster::WriteRGB (target, fileName); 00125 } 00126 } 00127 00128 // stop all our ModelComponents 00129 manager.stop(); 00130 00131 // all done! 00132 return 0; 00133 } 00134 00135 // ###################################################################### 00136 /* So things look consistent in everyone's emacs... */ 00137 /* Local Variables: */ 00138 /* indent-tabs-mode: nil */ 00139 /* End: */