00001 /*!@file Channels/SubmapAlgorithmBiased.C Compute SingleChannel submaps with Bayesian biasing */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00005 // by the 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: Lior Elazary <elazary@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Channels/SubmapAlgorithmBiased.C $ 00035 // $Id: SubmapAlgorithmBiased.C 9714 2008-04-29 06:48:56Z itti $ 00036 // 00037 00038 #ifndef CHANNELS_SUBMAPALGORITHMBIASED_C_DEFINED 00039 #define CHANNELS_SUBMAPALGORITHMBIASED_C_DEFINED 00040 00041 #include "Channels/SubmapAlgorithmBiased.H" 00042 00043 #include "Channels/ChannelVisitor.H" 00044 #include "Channels/ComplexChannel.H" 00045 #include "Channels/SingleChannel.H" 00046 #include "Image/Image.H" 00047 #include "Image/ShapeOps.H" 00048 00049 #include "GUI/DebugWin.H" 00050 namespace 00051 { 00052 class Installer : public ChannelVisitor 00053 { 00054 OptionManager& itsMgr; 00055 00056 public: 00057 Installer(OptionManager& mgr) : itsMgr(mgr) {} 00058 00059 virtual ~Installer() {} 00060 00061 virtual void visitChannelBase(ChannelBase& chan) 00062 { 00063 // nothing to do here 00064 } 00065 00066 virtual void visitSingleChannel(SingleChannel& chan) 00067 { 00068 nub::ref<SubmapAlgorithmBiased> algo 00069 (new SubmapAlgorithmBiased(itsMgr)); 00070 00071 chan.setSubmapAlgorithm(algo); 00072 } 00073 00074 virtual void visitComplexChannel(ComplexChannel& chan) 00075 { 00076 for (uint i = 0; i < chan.numChans(); ++i) 00077 chan.subChan(i)->accept(*this); 00078 } 00079 }; 00080 } 00081 00082 // ###################################################################### 00083 SubmapAlgorithmBiased::SubmapAlgorithmBiased(OptionManager& mgr, 00084 const std::string& descrName, 00085 const std::string& tagName) 00086 : 00087 SubmapAlgorithm(mgr, descrName, tagName) 00088 {} 00089 00090 // ###################################################################### 00091 SubmapAlgorithmBiased::~SubmapAlgorithmBiased() 00092 {} 00093 00094 // ###################################################################### 00095 Image<float> SubmapAlgorithmBiased::compute(const SingleChannel& chan, 00096 const uint i) 00097 { 00098 Image<float> submap = chan.getRawCSmap(i); 00099 00100 // resize submap to fixed scale if necessary: 00101 if (submap.getWidth() > chan.getMapDims().w()) 00102 submap = downSize(submap, chan.getMapDims()); 00103 else if (submap.getWidth() < chan.getMapDims().w()) 00104 submap = rescale(submap, chan.getMapDims()); 00105 00106 LFATAL("This is being reworked... stay tuned"); 00107 00108 /* 00109 // bias the submap if we have a mean and sigma 00110 LINFO("Mean %f var %f", chan.getMean(i), chan.getSigmaSq(i)); 00111 if (chan.getMean(i) > 0 && chan.getSigmaSq(i) > 0) 00112 { 00113 double mean = chan.getMean(i); 00114 double var = chan.getSigmaSq(i); 00115 00116 for(int y=0; y<submap.getHeight(); y++) 00117 for(int x=0; x<submap.getWidth(); x++) 00118 { 00119 double val = submap.getVal(x, y); 00120 double delta = -(val - mean) * (val - mean); 00121 //Calc the normal dist 00122 double newVal = exp(delta/(2*var))/(sqrt(2*M_PI*var)); 00123 00124 // submap.setVal(x, y, newVal*10000); 00125 submap.setVal(x, y, log(newVal)+10000); 00126 } 00127 } 00128 00129 Image<float> biasMask = chan.getBiasMask(); 00130 if (biasMask.initialized()) //bias based on a mask 00131 { 00132 //rescale the mask to the submap scale TODO: can be done more effiently 00133 biasMask = rescale(biasMask, submap.getDims()); 00134 submap *= biasMask; 00135 } 00136 // now do the standard processing 00137 submap = chan.postProcessMap(submap, i); 00138 00139 */ 00140 return submap; 00141 } 00142 00143 // ###################################################################### 00144 void setSubmapAlgorithmBiased(ChannelBase& chan) 00145 { 00146 Installer inst(chan.getManager()); 00147 chan.accept(inst); 00148 } 00149 00150 // ###################################################################### 00151 /* So things look consistent in everyone's emacs... */ 00152 /* Local Variables: */ 00153 /* mode: c++ */ 00154 /* indent-tabs-mode: nil */ 00155 /* End: */ 00156 00157 #endif // CHANNELS_SUBMAPALGORITHMBIASED_C_DEFINED