00001 /*!@file Envision/envision.c */ 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: Rob Peters <rjpeters at usc dot edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Envision/envision.c $ 00035 // $Id: envision.c 8341 2007-05-04 18:49:06Z rjpeters $ 00036 // 00037 00038 #ifndef ENVISION_APP_ENVISION_C_DEFINED 00039 #define ENVISION_APP_ENVISION_C_DEFINED 00040 00041 #include "Envision/env_alloc.h" 00042 #include "Envision/env_c_math_ops.h" 00043 #include "Envision/env_image.h" 00044 #include "Envision/env_image_ops.h" 00045 #include "Envision/env_log.h" 00046 #include "Envision/env_mt_visual_cortex.h" 00047 #include "Envision/env_params.h" 00048 #include "Envision/env_pthread_interface.h" 00049 #include "Envision/env_stdio_interface.h" 00050 #include "Envision/env_visual_cortex.h" 00051 00052 #include <pthread.h> 00053 #include <stdio.h> 00054 #include <stdlib.h> // for atoi(), malloc(), free() 00055 00056 // ###################################################################### 00057 // Thunk to convert from env_size_t to size_t 00058 static void* malloc_thunk(env_size_t n) 00059 { 00060 return malloc(n); 00061 } 00062 00063 // ###################################################################### 00064 struct status_data 00065 { 00066 int frame_number; 00067 }; 00068 00069 static void print_chan_status(void* userdata, 00070 const char* tagName, 00071 const struct env_image* img) 00072 { 00073 struct status_data* p = (struct status_data*) userdata; 00074 00075 if (env_img_initialized(img)) 00076 { 00077 intg32 mi, ma; 00078 env_c_get_min_max(env_img_pixels(img), env_img_size(img), 00079 &mi, &ma); 00080 fprintf(stderr, 00081 "frame %06d channel status: " 00082 "%20s: range [%ld .. %ld]\n", 00083 p->frame_number, tagName, (long) mi, (long) ma); 00084 } 00085 } 00086 00087 // ###################################################################### 00088 int main(int argc, const char** argv) 00089 { 00090 if (argc != 5 && argc != 6) 00091 { 00092 fprintf(stderr, 00093 "usage: %s instem outstem firstframe lastframe ?multi-threaded?\n", 00094 argv[0]); 00095 return 1; 00096 } 00097 00098 const char* instem = argv[1]; 00099 const char* outstem = argv[2]; 00100 const int first = atoi(argv[3]); 00101 const int last = atoi(argv[4]); 00102 const int multithreaded = argc < 6 ? 0 : atoi(argv[5]); 00103 00104 // Instantiate our various ModelComponents: 00105 struct env_params envp; 00106 env_params_set_defaults(&envp); 00107 00108 envp.maxnorm_type = ENV_VCXNORM_MAXNORM; 00109 envp.scale_bits = 16; 00110 00111 env_assert_set_handler(&env_stdio_assert_handler); 00112 if (multithreaded) 00113 { 00114 env_init_pthread_alloc(); 00115 env_init_pthread_job_server(); 00116 } 00117 env_allocation_init(&malloc_thunk, &free); 00118 00119 { 00120 struct env_visual_cortex ivc; 00121 env_visual_cortex_init(&ivc, &envp); 00122 00123 env_size_t npixels = 0; 00124 00125 for (int c = first; c <= last; ++c) 00126 { 00127 struct env_dims indims; 00128 struct env_rgb_pixel* input = 0; 00129 00130 char fname[256]; 00131 snprintf(fname, sizeof(fname), 00132 "%s%06d.pnm", instem, c); 00133 input = env_stdio_parse_rgb(fname, &indims); 00134 00135 npixels = indims.w * indims.h; 00136 00137 struct env_image ivcout = env_img_initializer; 00138 struct env_image intens = env_img_initializer; 00139 struct env_image color = env_img_initializer; 00140 struct env_image ori = env_img_initializer; 00141 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00142 struct env_image flicker = env_img_initializer; 00143 struct env_image motion = env_img_initializer; 00144 #endif 00145 00146 struct status_data userdata; 00147 userdata.frame_number = c; 00148 00149 env_mt_visual_cortex_input(multithreaded, 00150 &ivc, &envp, 00151 "visualcortex", 00152 input, 0, indims, 00153 &print_chan_status, 00154 &userdata, 00155 &ivcout, 00156 &intens, &color, &ori 00157 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00158 , &flicker, &motion 00159 #endif 00160 ); 00161 00162 env_deallocate(input); 00163 input = 0; 00164 00165 env_visual_cortex_rescale_ranges( 00166 &ivcout, &intens, &color, &ori 00167 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00168 , &flicker, &motion 00169 #endif 00170 ); 00171 00172 env_stdio_write_gray(&ivcout, outstem, "vcx", c); 00173 00174 env_stdio_write_gray(&intens, outstem, "intens", c); 00175 env_stdio_write_gray(&color, outstem, "color", c); 00176 env_stdio_write_gray(&ori, outstem, "ori", c); 00177 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00178 env_stdio_write_gray(&flicker, outstem, "flicker", c); 00179 env_stdio_write_gray(&motion, outstem, "motion", c); 00180 #endif 00181 00182 env_img_make_empty(&ivcout); 00183 env_img_make_empty(&intens); 00184 env_img_make_empty(&color); 00185 env_img_make_empty(&ori); 00186 #ifdef ENV_WITH_DYNAMIC_CHANNELS 00187 env_img_make_empty(&flicker); 00188 env_img_make_empty(&motion); 00189 #endif 00190 } 00191 00192 struct env_alloc_stats stats; 00193 env_allocation_get_stats(&stats); 00194 env_stdio_print_alloc_stats(&stats, npixels ? npixels : 1); 00195 env_visual_cortex_destroy(&ivc); 00196 } 00197 00198 env_allocation_cleanup(); 00199 00200 return 0; 00201 } 00202 00203 // ###################################################################### 00204 /* So things look consistent in everyone's emacs... */ 00205 /* Local Variables: */ 00206 /* indent-tabs-mode: nil */ 00207 /* c-file-style: "linux" */ 00208 /* End: */ 00209 00210 #endif // ENVISION_APP_ENVISION_C_DEFINED