00001 /*!@file AppPsycho/calibrateLuminance.C Match the luminance of 2 stimuli using 00002 standard flicker photometry */ 00003 00004 // //////////////////////////////////////////////////////////////////// // 00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00006 // University of Southern California (USC) and the iLab at USC. // 00007 // See http://iLab.usc.edu for information about this project. // 00008 // //////////////////////////////////////////////////////////////////// // 00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00011 // in Visual Environments, and Applications'' by Christof Koch and // 00012 // Laurent Itti, California Institute of Technology, 2001 (patent // 00013 // pending; application number 09/912,225 filed July 23, 2001; see // 00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00015 // //////////////////////////////////////////////////////////////////// // 00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00017 // // 00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00019 // redistribute it and/or modify it under the terms of the GNU General // 00020 // Public License as published by the Free Software Foundation; either // 00021 // version 2 of the License, or (at your option) any later version. // 00022 // // 00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00026 // PURPOSE. See the GNU General Public License for more details. // 00027 // // 00028 // You should have received a copy of the GNU General Public License // 00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00031 // Boston, MA 02111-1307 USA. // 00032 // //////////////////////////////////////////////////////////////////// // 00033 // 00034 // Primary maintainer for this file: Vidhya Navalpakkam <navalpak@usc.edu> 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppPsycho/calibrateLuminance.C $ 00036 // $Id: calibrateLuminance.C 8426 2007-05-24 06:57:57Z itti $ 00037 // 00038 00039 #include "Component/ModelManager.H" 00040 #include "Image/Image.H" 00041 #include "Psycho/PsychoDisplay.H" 00042 #include "GUI/GUIOpts.H" 00043 #include "Raster/Raster.H" 00044 #include "Util/Types.H" 00045 #include <cstdlib> 00046 00047 // ###################################################################### 00048 // regenerates the test stimuli by changing the luminance 00049 void updateLuminance(Image< PixRGB<byte> >& s2, int lumin, const float sat); 00050 extern "C" int main(const int argc, char** argv) 00051 { 00052 MYLOGVERB = LOG_INFO; // suppress debug messages 00053 00054 // Instantiate a ModelManager: 00055 ModelManager manager("Calibrate luminance"); 00056 00057 // Instantiate our various ModelComponents: 00058 nub::soft_ref<PsychoDisplay> d(new PsychoDisplay(manager)); 00059 manager.addSubComponent(d); 00060 00061 // set some display params 00062 manager.setOptionValString(&OPT_SDLdisplayDims, "1280x1024"); 00063 d->setModelParamVal("PsychoDisplayBackgroundColor", PixRGB<byte>(0)); 00064 d->setModelParamVal("PsychoDisplayTextColor", PixRGB<byte>(255)); 00065 d->setModelParamVal("PsychoDisplayBlack", PixRGB<byte>(255)); 00066 d->setModelParamVal("PsychoDisplayWhite", PixRGB<byte>(128)); 00067 d->setModelParamVal("PsychoDisplayFixSiz", 5); 00068 d->setModelParamVal("PsychoDisplayFixThick", 5); 00069 00070 // Parse command-line: 00071 if (manager.parseCommandLine(argc, argv, 00072 "<img1.ppm> <img2.ppm>" 00073 " <luminance2> <saturation2> ", 1, -1)==false) 00074 return(1); 00075 00076 // let's get all our ModelComponent instances started: 00077 manager.start(); 00078 00079 // load up the frame and show a fixation cross on a blank screen: 00080 d->clearScreen(); 00081 LINFO("Loading '%s'...", manager.getExtraArg(0).c_str()); 00082 Image< PixRGB<byte> > s1 = 00083 Raster::ReadRGB(manager.getExtraArg(0)); 00084 LINFO("Loading '%s'...", manager.getExtraArg(1).c_str()); 00085 Image< PixRGB<byte> > s2 = 00086 Raster::ReadRGB(manager.getExtraArg(1)); 00087 00088 // read the luminance and saturation value of S2 00089 int lumin = manager.getExtraArgAs<int>(2); 00090 float sat = manager.getExtraArgAs<float>(3); 00091 00092 SDL_Surface *surf1 = d->makeBlittableSurface(s1, false); 00093 SDL_Surface *surf2 = d->makeBlittableSurface(s2, false); 00094 00095 LINFO("stimuli ready."); 00096 00097 // ready to go whenever the user is ready: 00098 d->displayText("hit any key when ready"); 00099 d->waitForKey(); 00100 d->waitNextRequestedVsync(false, true); 00101 while (true) { 00102 d->clearScreen(); 00103 d->displayFixation(); 00104 // let's alternate between stimuli S1 and S2 for 4 sec 00105 for (int j = 0; j < 9; j ++) { 00106 d->displaySurface(surf1, -2, true); 00107 d->waitFrames(3); 00108 d->displaySurface(surf2, -2, true); 00109 d->waitFrames(3); 00110 } 00111 d->displaySurface(surf1, -2, true); 00112 00113 // do the stimuli match in luminance 00114 d->displayText("Press <+><NUM> to increase luminance," 00115 " <-><NUM> to decrease luminance" 00116 " and <ENTER> to accept"); 00117 int c1 = d->waitForKey(); 00118 int c2 = d->waitForKey(); 00119 if (c1 == 43){ 00120 // increase the luminance of S2 00121 SDL_FreeSurface(surf2); 00122 lumin += c2 - 48; 00123 updateLuminance(s2, lumin, sat); 00124 surf2 = d->makeBlittableSurface(s2, false); 00125 } 00126 else if (c1 == 45){ 00127 // decrease the luminance of S2 00128 SDL_FreeSurface(surf2); 00129 lumin -= c2 - 48; 00130 updateLuminance(s2, lumin, sat); 00131 surf2 = d->makeBlittableSurface(s2, false); 00132 } 00133 else break; // accept values and proceed 00134 } 00135 00136 d->clearScreen(); 00137 00138 // free the image: 00139 SDL_FreeSurface(surf1); 00140 SDL_FreeSurface(surf2); 00141 00142 d->clearScreen(); 00143 d->displayText("Experiment complete. Thank you!"); 00144 d->waitForKey(); 00145 00146 // stop all our ModelComponents 00147 manager.stop(); 00148 00149 // all done! 00150 return 0; 00151 } 00152 // ###################################################################### 00153 void updateLuminance(Image< PixRGB<byte> >& s2, int lumin, const float sat){ 00154 LINFO ("test luminance = %d", lumin); 00155 // change the r, g, b values used to draw the stimuli 00156 int red = (int)(lumin / (1.0f - 0.7875*sat)); 00157 int green = (int) ((lumin - 0.2125*red)/0.7875); 00158 PixRGB<byte> zero(0, 0, 0); 00159 // since the stimuli is red saturated, blue = green 00160 LINFO ("r, g, b = %d, %d, %d", red, green, green); 00161 PixRGB<byte> rgb(red, green, green); 00162 int w = s2.getWidth(), h = s2.getHeight(); 00163 // regenerate the image 00164 for (int x = 0; x < w; x++) 00165 for (int y = 0; y < h; y ++) { 00166 if (s2.getVal(x,y) == zero); // do nothing 00167 else s2.setVal(x, y, rgb); 00168 } 00169 } 00170 00171 00172 // ###################################################################### 00173 /* So things look consistent in everyone's emacs... */ 00174 /* Local Variables: */ 00175 /* indent-tabs-mode: nil */ 00176 /* End: */