3
Copyright (C) 2006 Yangli Hector Yee
5
This program is free software; you can redistribute it and/or modify it under the terms of the
6
GNU General Public License as published by the Free Software Foundation; either version 2 of the License,
7
or (at your option) any later version.
9
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10
without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
See the GNU General Public License for more details.
13
You should have received a copy of the GNU General Public License along with this program;
14
if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
//////////////////////////////////////////////////////////////////////
21
// Construction/Destruction
22
//////////////////////////////////////////////////////////////////////
24
LPyramid::LPyramid(float *image, int width, int height) :
28
// Make the Laplacian pyramid by successively
29
// copying the earlier levels and blurring them
30
for (int i=0; i<MAX_PYR_LEVELS; i++) {
32
Levels[i] = Copy(image);
34
Levels[i] = new float[Width * Height];
35
Convolve(Levels[i], Levels[i - 1]);
42
for (int i=0; i<MAX_PYR_LEVELS; i++) {
43
if (Levels[i]) delete Levels[i];
47
float *LPyramid::Copy(float *img)
49
int max = Width * Height;
50
float *out = new float[max];
51
for (int i = 0; i < max; i++) out[i] = img[i];
56
void LPyramid::Convolve(float *a, float *b)
57
// convolves image b with the filter kernel and stores it in a
60
const float Kernel[] = {0.05f, 0.25f, 0.4f, 0.25f, 0.05f};
62
for (y=0; y<Height; y++) {
63
for (x=0; x<Width; x++) {
64
int index = y * Width + x;
66
for (i=-2; i<=2; i++) {
67
for (j=-2; j<=2; j++) {
72
if (nx>=Width) nx=2*Width-nx-1;
73
if (ny>=Height) ny=2*Height-ny-1;
74
a[index] += Kernel[i+2] * Kernel[j+2] * b[ny * Width + nx];
81
float LPyramid::Get_Value(int x, int y, int level)
83
int index = x + y * Width;
85
if (l > MAX_PYR_LEVELS) l = MAX_PYR_LEVELS;
86
return Levels[level][index];