Image.cpp
Go to the documentation of this file.
00001 /*
00002 * This file is part of Parallel SURF, which implements the SURF algorithm
00003 * using multi-threading.
00004 *
00005 * Copyright (C) 2010 David Gossow
00006 *
00007 * It is based on the SURF implementation included in Pan-o-matic 0.9.4, 
00008 * written by Anael Orlinski.
00009 * 
00010 * Parallel SURF is free software; you can redistribute it and/or modify
00011 * it under the terms of the GNU General Public License as published by
00012 * the Free Software Foundation; either version 3 of the License, or
00013 * (at your option) any later version.
00014 * 
00015 * Parallel SURF is distributed in the hope that it will be useful,
00016 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 * GNU General Public License for more details.
00019 * 
00020 * You should have received a copy of the GNU General Public License
00021 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 
00024 #include "Image.h"
00025 
00026 using namespace parallelsurf;
00027 
00028 Image::Image(const unsigned char **iPixels, unsigned int iWidth, unsigned int iHeight)
00029 {
00030   init(iPixels, iWidth, iHeight);
00031 }
00032 
00033 void Image::init(const unsigned char **iPixels, unsigned int iWidth, unsigned int iHeight)
00034 {
00035   // store values
00036   _width = iWidth;
00037   _height = iHeight;
00038   _pixels = iPixels;
00039 
00040   // allocate the integral image data
00041   _ii = AllocateImage(_width + 1, _height + 1);
00042 
00043   // create the integral image
00044   buildIntegralImage();
00045 }
00046 
00047 void Image::clean()
00048 {
00049   if (_ii)
00050     DeallocateImage(_ii, _height + 1);
00051   _ii = 0;
00052 }
00053 
00054 
00055 Image::~Image()
00056 {
00057   clean();
00058 }
00059 
00060 void Image::buildIntegralImage()
00061 {
00062   // to make easier the later computation, shift the image by 1 pix (x and y)
00063   // so the image has a size of +1 for width and height compared to orig image.
00064 
00065   // fill first line with zero
00066   for(unsigned int i = 0; i <= _width; ++i)
00067     _ii[0][i] = 0;
00068 
00069   // fill first row with zero
00070   for(unsigned int i = 0; i <= _height; ++i)
00071     _ii[i][0] = 0;
00072 
00073   static const double norm=1.0 / 255.0;
00074 
00075   // compute all the others pixels
00076   for(unsigned int i = 1; i <= _height; ++i)
00077     for(unsigned int j = 1; j <= _width; ++j)
00078       _ii[i][j] = norm*double(_pixels[i-1][j-1]) + _ii[i-1][j] + _ii[i][j-1] - _ii[i-1][j-1];
00079 /*
00080   //implementation suited for parallelized computation:
00081   // compute all the others pixels
00082   for(unsigned int i = 1; i <= _height; ++i)
00083     for(unsigned int j = 1; j <= _width; ++j)
00084       _ii[i][j] = norm*double(_pixels[i-1][j-1]) + _ii[i][j-1];
00085     
00086   for(unsigned int j = 1; j <= _width; ++j)
00087     for(unsigned int i = 1; i <= _height; ++i)
00088       _ii[i][j] += _ii[i-1][j];
00089     */
00090 }
00091 
00092 // allocate and deallocate pixels
00093 double** Image::AllocateImage(unsigned int iWidth, unsigned int iHeight)
00094 {
00095   // create the lines holder
00096   double ** aImagePtr = new double* [iHeight];
00097 
00098   // create the lines
00099   for(unsigned int i = 0; i < iHeight; ++i)
00100     aImagePtr[i] = new double[iWidth];
00101 
00102   // initialize image
00103   for(unsigned x = 0; x < iHeight; x++)
00104     for(unsigned y = 0; y < iWidth; y++)
00105         aImagePtr[x][y] = 0;
00106 
00107   return aImagePtr;
00108 }
00109 
00110 void Image::DeallocateImage(double **iImagePtr, unsigned int iHeight)
00111 {
00112   // delete the lines
00113   for(unsigned int i = 0; i < iHeight; ++i)
00114     delete[] iImagePtr[i];
00115 
00116   // delete the lines holder
00117   delete[] iImagePtr;
00118 
00119 }
00120 


or_libs
Author(s): raphael
autogenerated on Mon Oct 6 2014 02:53:18