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 * <http://www.gnu.org/licenses/>.
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     _ii = 0;
00054 }
00055 
00056 Image::~Image()
00057 {
00058     clean();
00059 }
00060 
00061 void Image::buildIntegralImage(vigra::DImage &img)
00062 {
00063     // to make easier the later computation, shift the image by 1 pix (x and y)
00064     // so the image has a size of +1 for width and height compared to orig image.
00065 
00066     // fill first line with zero
00067     for(unsigned int i = 0; i <= _width; ++i)
00068     {
00069         _ii[0][i] = 0;
00070     }
00071 
00072     // fill first row with zero
00073     for(unsigned int i = 0; i <= _height; ++i)
00074     {
00075         _ii[i][0] = 0;
00076     }
00077 
00078     // compute all the others pixels
00079     for(unsigned int i = 1; i <= _height; ++i)
00080         for(unsigned int j = 1; j <= _width; ++j)
00081         {
00082             _ii[i][j] = img[i-1][j-1] + _ii[i-1][j] + _ii[i][j-1] - _ii[i-1][j-1];
00083         }
00084 
00085 }
00086 
00087 // allocate and deallocate pixels
00088 double** Image::AllocateImage(unsigned int iWidth, unsigned int iHeight)
00089 {
00090     // create the lines holder
00091     double** aImagePtr = new double* [iHeight];
00092 
00093     // create the lines
00094     for(unsigned int i = 0; i < iHeight; ++i)
00095     {
00096         aImagePtr[i] = new double[iWidth];
00097     }
00098 
00099     return aImagePtr;
00100 }
00101 
00102 void Image::DeallocateImage(double** iImagePtr, unsigned int iHeight)
00103 {
00104     // delete the lines
00105     for(unsigned int i = 0; i < iHeight; ++i)
00106     {
00107         delete[] iImagePtr[i];
00108     }
00109 
00110     // delete the lines holder
00111     delete[] iImagePtr;
00112 }

Generated on 31 Jul 2015 for Hugintrunk by  doxygen 1.4.7