Hugin trunk 0.1
Loading...
Searching...
No Matches
ContrastFilter.cpp
Go to the documentation of this file.
1/* Import from Gabor API
2
3Copyright (c) 2002-3 Adriaan Tijsseling
4
5
6 All Rights Reserved
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
20*/
21
22/*
23 Description: Abstract class for contrast filter
24 Original Author: Yasunobu Honma
25 Modifications by: Adriaan Tijsseling (AGT)
26*/
27
28#include "ContrastFilter.h"
29
30namespace celeste
31{
32float CONTRAST[9][9] = {
33 {
34 -0.00601522f,
35 -0.00815698f,
36 -0.00576532f,
37 -0.000761649f,
38 0.00105624f,
39 -0.000761649f,
40 -0.00576532f,
41 -0.00815698f,
42 -0.00601522f
43 },
44
45 {
46 -0.00815698f,
47 -0.00235211f,
48 0.00300229f,
49 -0.0157626f,
50 -0.0304662f,
51 -0.0157626f,
52 0.00300229f,
53 -0.00235211f,
54 -0.00815698f
55 },
56
57 {
58 -0.00576532f,
59 0.00300229f,
60 -0.0505102f,
61 -0.115416f,
62 -0.115769f,
63 -0.115416f,
64 -0.0505102f,
65 0.00300229f,
66 -0.00576532f
67 },
68
69 {
70 -0.000761649f,
71 -0.0157626f,
72 -0.115416f,
73 0.0361012f,
74 0.273771f,
75 0.0361012f,
76 -0.115416f,
77 -0.0157626f,
78 -0.000761649f
79 },
80
81 {
82 0.00105624f,
83 -0.0304662f,
84 -0.115769f,
85 0.273771f,
86 0.719623f,
87 0.273771f,
88 -0.115769f,
89 -0.0304662f,
90 0.00105624f
91 },
92
93 {
94 -0.000761649f,
95 -0.0157626f,
96 -0.115416f,
97 0.0361012f,
98 0.273771f,
99 0.0361012f,
100 -0.115416f,
101 -0.0157626f,
102 -0.000761649f
103 },
104
105 {
106 -0.00576532f,
107 0.00300229f,
108 -0.0505102f,
109 -0.115416f,
110 -0.115769f,
111 -0.115416f,
112 -0.0505102f,
113 0.00300229f,
114 -0.00576532f
115 },
116
117 {
118 -0.00815698f,
119 -0.00235211f,
120 0.00300229f,
121 -0.0157626f,
122 -0.0304662f,
123 -0.0157626f,
124 0.00300229f,
125 -0.00235211f,
126 -0.00815698f
127 },
128
129 {
130 -0.00601522f,
131 -0.00815698f,
132 -0.00576532f,
133 -0.000761649f,
134 0.00105624f,
135 -0.000761649f,
136 -0.00576532f,
137 -0.00815698f,
138 -0.00601522f
139 }};
140
141// construct class and apply filter
142ContrastFilter::ContrastFilter( float **img, int height, int width )
143{
144 mHeight = height-8;
145 mWidth = width-8;
146
147 mContrast = new float*[mHeight];
148 for ( int i = 0; i < mHeight; i++ )
149 {
150 mContrast[i] = new float[mWidth];
151 for ( int j = 0; j < mWidth; j++ )
152 mContrast[i][j] = 0.0;
153 }
154
155 ApplyFilter( img, height, width );
156}
157
158
159// free memory
161{
162 if( mContrast != NULL )
163 {
164 for( int y = 0; y < mHeight; y++ )
165 delete[] mContrast[y];
166 delete[] mContrast;
167 }
168}
169
170
171// apply filter to image
172void ContrastFilter::ApplyFilter( float** img, int height, int width )
173{
174 int x, y, i, j;//, k, l;
175 float tmp;
176
177 for( i = 0; i < height-8; i++ )
178 for( j = 0; j < width-8; j++ )
179 {
180 tmp = 0.0;
181 for( x = 0; x < 9; x++ )
182 for( y = 0; y < 9; y++)
183 tmp += CONTRAST[x][y] * img[i+x][j+y];
184 mContrast[i][j] = tmp;
185 }
186}
187
188
189// write out contrast data to pgm file
190void ContrastFilter::Save( char* file )
191{
192 PGMImage pgmI;
193 char tmpName[256];
194
195 strcpy( tmpName, file );
196 strcat( tmpName, "-contrast.pgm" );
197 pgmI.WriteScaled( tmpName, mContrast, mHeight, mWidth );
198}
199
200}; // namespace
void ApplyFilter(float **img, int height, int width)
void WriteScaled(char *filename, float **output, int height, int width)
Definition PGMImage.cpp:334
float CONTRAST[9][9]