MatrixOps.H

Go to the documentation of this file.
00001 /*!@file Image/MatrixOps.H Matrix operations on Image
00002  */
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: Laurent Itti <itti@usc.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Image/MatrixOps.H $
00036 // $Id: MatrixOps.H 7963 2007-02-21 03:55:43Z itti $
00037 //
00038 
00039 #ifndef IMAGE_MATRIXOPS_H_DEFINED
00040 #define IMAGE_MATRIXOPS_H_DEFINED
00041 
00042 #include "Image/Image.H"
00043 #include "Util/Promotions.H"
00044 #include "rutz/error.h"
00045 
00046 //! Exception class thrown if a singular matrix is encountered
00047 /*! The exception object contains a copy of the singular matrix, so
00048     that the matrix can be examined, displayed, etc. for debugging
00049     purposes. */
00050 class SingularMatrixException : public rutz::error
00051 {
00052 public:
00053   SingularMatrixException(const Image<float>& m,
00054                           const rutz::file_pos& pos)
00055     :
00056     rutz::error("Matrix is singular", pos),
00057     mtx(m) {}
00058 
00059   virtual ~SingularMatrixException() throw() {}
00060 
00061   const Image<float> mtx;
00062 };
00063 
00064 //! Vector-Matrix Multiplication: y = v * M
00065 /*! @param v row vector (w x h == n x 1),
00066     @param M matrix with (w x h == p x n)
00067     @return row vector (w x h == p x 1)
00068 */
00069 template <class T>
00070 Image<typename promote_trait<T,T>::TP>
00071 vmMult(const Image<T>& v, const Image<T>& M);
00072 
00073 //! Matrix-Matrix Multiplication: C = A * B
00074 /*! The images A and B are interpreted as matrices. For multiplying a
00075     (m x n) with a (n x p) matrix, this is the generic matrix
00076     multiplication with complexity (m * n * p).*/
00077 template <class T>
00078 Image<typename promote_trait<T,T>::TP>
00079 matrixMult(const Image<T>& A, const Image<T>& B);
00080 
00081 //! Matrix-Matrix Multiplication: C = A * B
00082 /*! The images A and B are interpreted as matrices. For multiplying
00083   a (m x n) with a (n x p) matrix, this is the generic matrix multiplication
00084   with complexity (m * n * p). This version will allow you to multiply
00085   values in a matrix that lie between index endA/B and beginA/B. The
00086   destination matrix will be the same size as:
00087   (endAX - beginAX) x (endAX - beginAX)
00088   per usual the width of A (indexed between beginAX and endAX)
00089   and height of B MUST be equal. If not then
00090   perhaps use transpose...
00091   @param A input matrix 1
00092   @param B input matrix 2
00093   @param beginAX starting (width) index in matrix A
00094   @param endAX ending (width) index in matrix A
00095   @param beginBX starting (width) index in matrix B
00096   @param endBX ending (width) index in matrix B
00097   @param beginAY starting (height) index in matrix A
00098   @param endAY ending (height) index in matrix A
00099 */
00100 template <class T>
00101 Image<typename promote_trait<T,T>::TP>
00102 matrixMult(const Image<T>& A, const Image<T>& B,
00103            const uint beginAX, const uint endAX,
00104            const uint beginBX, const uint endBX,
00105            const uint beginAY, const uint endAY);
00106 
00107 //! transpose matrix M
00108 template <class T_or_RGB>
00109 Image<T_or_RGB> transpose(const Image<T_or_RGB>& M);
00110 
00111 //! flip horizontally
00112 template <class T_or_RGB>
00113 Image<T_or_RGB> flipHoriz(const Image<T_or_RGB>& img);
00114 
00115 //! flip vertically
00116 template <class T_or_RGB>
00117 Image<T_or_RGB> flipVertic(const Image<T_or_RGB>& img);
00118 
00119 //! return the identity matrix of dimensions (size x size)
00120 template <class T>
00121 Image<T> eye(const uint size);
00122 
00123 //! Compute the trace of a square matrix, i.e., sum of its diagonal elements
00124 template <class T>
00125 typename promote_trait<T,T>::TP trace(const Image<T>& M);
00126 
00127 //! Get a partial pivot and pivote a square matrix, at y
00128 /*! returns -1 if we can't find one */
00129 template <class T>
00130 int matrixPivot(Image<T>& M, const int y);
00131 
00132 //! Inverse a nonsingular square matrix
00133 template <class T>
00134 Image<typename promote_trait<T, float>::TP> matrixInv(const Image<T>& M);
00135 
00136 //! Compute dot product between two images
00137 /*! The two images must have same dims. This is just the sum of all
00138   pointwise products. */
00139 template <class T>
00140 typename promote_trait<T,T>::TP dotprod(const Image<T>& A, const Image<T>& B);
00141 
00142 //! Compute the determinant of a square matrix
00143 template <class T>
00144 typename promote_trait<T,float>::TP matrixDet(const Image<T>& M);
00145 
00146 
00147 #endif // !IMAGE_MATRIXOPS_H_DEFINED
00148 
00149 // ######################################################################
00150 /* So things look consistent in everyone's emacs... */
00151 /* Local Variables: */
00152 /* indent-tabs-mode: nil */
00153 /* End: */
Generated on Sun May 8 08:40:56 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3