Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00036 _width = iWidth;
00037 _height = iHeight;
00038 _pixels = iPixels;
00039
00040
00041 _ii = AllocateImage(_width + 1, _height + 1);
00042
00043
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
00063
00064
00065
00066 for(unsigned int i = 0; i <= _width; ++i)
00067 _ii[0][i] = 0;
00068
00069
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
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
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 }
00091
00092
00093 double** Image::AllocateImage(unsigned int iWidth, unsigned int iHeight)
00094 {
00095
00096 double ** aImagePtr = new double* [iHeight];
00097
00098
00099 for(unsigned int i = 0; i < iHeight; ++i)
00100 aImagePtr[i] = new double[iWidth];
00101
00102
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
00113 for(unsigned int i = 0; i < iHeight; ++i)
00114 delete[] iImagePtr[i];
00115
00116
00117 delete[] iImagePtr;
00118
00119 }
00120