00001 /*!@file AppMedia/app-fft-movie.C Simple application to display the 00002 frame-by-frame fft magnitude and phase of a movie. */ 00003 00004 // //////////////////////////////////////////////////////////////////// // 00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00006 // by the 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: 00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppMedia/app-fft-movie.C $ 00036 // $Id: app-fft-movie.C 5804 2005-10-28 18:18:44Z rjpeters $ 00037 // 00038 00039 #ifndef APPMEDIA_APP_FFT_MOVIE_C_DEFINED 00040 #define APPMEDIA_APP_FFT_MOVIE_C_DEFINED 00041 00042 #include "Component/ModelManager.H" 00043 #include "GUI/ImageDisplayStream.H" 00044 #include "Image/ColorOps.H" 00045 #include "Image/Convolver.H" 00046 #include "Image/Coords.H" 00047 #include "Image/CutPaste.H" 00048 #include "Image/DrawOps.H" 00049 #include "Image/FilterOps.H" 00050 #include "Image/FourierEngine.H" 00051 #include "Image/MathOps.H" 00052 #include "Image/Pixels.H" 00053 #include "Media/MPEGStream.H" 00054 #include "rutz/trace.h" 00055 00056 int main(int argc, const char** argv) 00057 { 00058 ModelManager mgr(argv[0]); 00059 00060 nub::soft_ref<InputMPEGStream> ims(new InputMPEGStream(mgr)); 00061 00062 mgr.addSubComponent(ims); 00063 mgr.exportOptions(MC_RECURSE); 00064 00065 if (mgr.parseCommandLine(argc, argv, "infile.mpg", 1, 1) == false) 00066 return 1; 00067 00068 mgr.start(); 00069 00070 const std::string infile = mgr.getExtraArg(0); 00071 00072 ims->setFileName(infile); 00073 00074 nub::soft_ref<ImageDisplayStream> ids(new ImageDisplayStream(mgr)); 00075 00076 Image<float> box(15, 15, NO_INIT); 00077 box.clear(1.0f/(15*15)); 00078 00079 LINFO("box sum: %g", sum(box)); 00080 00081 FourierEngine<double> eng(ims->peekDims()); 00082 FourierInvEngine<double> ieng(ims->peekDims()); 00083 00084 Convolver conv(box, ims->peekDims()); 00085 00086 while (true) 00087 { 00088 const Image<PixRGB<byte> > img = ims->readRGB(); 00089 00090 if (!img.initialized()) 00091 break; 00092 00093 const Image<float> lum = luminance(Image<PixRGB<float> >(img)); 00094 00095 Image<complexd> res = eng.fft(Image<double>(lum)); 00096 00097 const Image<double> rt = ieng.ifft(res) / img.getSize(); 00098 00099 const Image<double> logmag = logmagnitude(res); 00100 const Image<double> phz = phase(res); 00101 const Image<double> cart = cartesian(logmag, Dims(256, 256)); 00102 00103 ids->writeRGB(img, "input"); 00104 ids->writeFloat(logmag, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE, 00105 "logmag-fft-input"); 00106 ids->writeFloat(phz, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE, 00107 "phase-fft-input"); 00108 ids->writeFloat(cart, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE, 00109 "cartesian-logmag-fft-input"); 00110 00111 const Image<float> c1 = conv.spatialConvolve(lum); 00112 00113 const Image<float> c2 = conv.fftConvolve(lum); 00114 00115 ids->writeFloat(c1, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE, 00116 "c1"); 00117 ids->writeFloat(c2, FLOAT_NORM_0_255 | FLOAT_NORM_WITH_SCALE, 00118 "c2"); 00119 00120 LINFO("rms conv diff: %e corrcoef: %e", 00121 RMSerr(c1, c2), corrcoef(c1, c2)); 00122 00123 LINFO("rms roundtrip fft->ifft diff: %e", 00124 RMSerr(Image<float>(rt), lum)); 00125 } 00126 00127 mgr.stop(); 00128 } 00129 00130 // ###################################################################### 00131 /* So things look consistent in everyone's emacs... */ 00132 /* Local Variables: */ 00133 /* indent-tabs-mode: nil */ 00134 /* End: */ 00135 00136 #endif // APPMEDIA_APP_FFT_MOVIE_C_DEFINED