Image.cpp

Go to the documentation of this file.
00001 /*
00002 * Copyright (C) 2007-2008 Anael Orlinski
00003 *
00004 * This file is part of Panomatic.
00005 *
00006 * Panomatic is free software; you can redistribute it and/or modify
00007 * it under the terms of the GNU General Public License as published by
00008 * the Free Software Foundation; either version 2 of the License, or
00009 * (at your option) any later version.
00010 *
00011 * Panomatic is distributed in the hope that it will be useful,
00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 * GNU General Public License for more details.
00015 *
00016 * You should have received a copy of the GNU General Public License
00017 * along with Panomatic; if not, write to the Free Software
00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 */
00020 
00021 #include <iostream>
00022 #include <vector>
00023 
00024 #include "Image.h"
00025 
00026 using namespace lfeat;
00027 using namespace std;
00028 
00029 Image::Image(vigra::DImage &img)
00030 {
00031     init(img);
00032 }
00033 
00034 void Image::init(vigra::DImage &img)
00035 {
00036     // store values
00037     _width = img.width();
00038     _height = img.height();
00039 
00040     // allocate the integral image data
00041     _ii = AllocateImage(_width + 1, _height + 1);
00042 
00043     // create the integral image
00044     buildIntegralImage(img);
00045 }
00046 
00047 void Image::clean()
00048 {
00049     if (_ii)
00050     {
00051         DeallocateImage(_ii, _height + 1);
00052     }
00053     else if (_ii)
00054     {
00055         delete[] _ii;
00056     }
00057     _ii = 0;
00058 }
00059 
00060 Image::~Image()
00061 {
00062     clean();
00063 }
00064 
00065 void Image::buildIntegralImage(vigra::DImage &img)
00066 {
00067     // to make easier the later computation, shift the image by 1 pix (x and y)
00068     // so the image has a size of +1 for width and height compared to orig image.
00069 
00070     // fill first line with zero
00071     for(unsigned int i = 0; i <= _width; ++i)
00072     {
00073         _ii[0][i] = 0;
00074     }
00075 
00076     // fill first row with zero
00077     for(unsigned int i = 0; i <= _height; ++i)
00078     {
00079         _ii[i][0] = 0;
00080     }
00081 
00082     // compute all the others pixels
00083     for(unsigned int i = 1; i <= _height; ++i)
00084         for(unsigned int j = 1; j <= _width; ++j)
00085         {
00086             _ii[i][j] = img[i-1][j-1] + _ii[i-1][j] + _ii[i][j-1] - _ii[i-1][j-1];
00087         }
00088 
00089 }
00090 
00091 // allocate and deallocate pixels
00092 double** Image::AllocateImage(unsigned int iWidth, unsigned int iHeight)
00093 {
00094     // create the lines holder
00095     double** aImagePtr = new double* [iHeight];
00096 
00097     // create the lines
00098     for(unsigned int i = 0; i < iHeight; ++i)
00099     {
00100         aImagePtr[i] = new double[iWidth];
00101     }
00102 
00103     return aImagePtr;
00104 }
00105 
00106 void Image::DeallocateImage(double** iImagePtr, unsigned int iHeight)
00107 {
00108     // delete the lines
00109     for(unsigned int i = 0; i < iHeight; ++i)
00110     {
00111         delete[] iImagePtr[i];
00112     }
00113 
00114     // delete the lines holder
00115     delete[] iImagePtr;
00116 }

Generated on Thu Aug 21 01:25:41 2014 for Hugintrunk by  doxygen 1.3.9.1