00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef IMAGE_LOWPASSLPT_C_DEFINED
00038 #define IMAGE_LOWPASSLPT_C_DEFINED
00039
00040 #include "Image/LowPassLpt.H"
00041
00042 #include "Image/Convolutions.H"
00043 #include "Image/LowPass.H"
00044 #include "Image/Image.H"
00045 #include "Image/Kernels.H"
00046 #include "Image/Pixels.H"
00047 #include "rutz/trace.h"
00048
00049
00050 template <class T_or_RGB>
00051 Image<typename promote_trait<T_or_RGB, float>::TP>
00052 lowPassLpt(const Image<T_or_RGB>& src, const uint taps, BorderPolicy policy)
00053 {
00054 if (taps == 5)
00055 if (policy == CROSS_HEMI)
00056 return lowPassLpt5w(lowPass5x(src));
00057 else if (policy == SEPARATE_HEMI)
00058 return lowPass5y(lowPassLpt5r(src));
00059 else
00060 return lowPassLpt5w(lowPassLpt5r(src));
00061 else if (taps == 3)
00062 if (policy == CROSS_HEMI)
00063 return lowPassLpt3w(lowPass3x(src));
00064 else if (policy == SEPARATE_HEMI)
00065 return lowPass3y(lowPassLpt3r(src));
00066 else
00067 return lowPassLpt3w(lowPassLpt3r(src));
00068 else
00069 return Image<typename promote_trait<T_or_RGB, float>::TP>();
00070 }
00071
00072
00073
00074 template <class T_or_RGB>
00075 Image<typename promote_trait<T_or_RGB, float>::TP>
00076 lowPassLpt3(const Image<T_or_RGB>& src, BorderPolicy policy)
00077 {
00078 if (policy == CROSS_HEMI)
00079 return lowPassLpt3w(lowPass3x(src));
00080 else if (policy == SEPARATE_HEMI)
00081 return lowPass3y(lowPassLpt3r(src));
00082 else
00083 return lowPassLpt3w(lowPassLpt3r(src));
00084 }
00085
00086
00087 template <class T_or_RGB>
00088 Image<typename promote_trait<T_or_RGB, float>::TP>
00089 lowPassLpt3r(const Image<T_or_RGB>& src)
00090 {
00091
00092
00093 GVX_TRACE(__PRETTY_FUNCTION__);
00094 const int w = src.getWidth(), h = src.getHeight(),
00095 hf = w / 2, h2 = 2*h;
00096
00097
00098
00099
00100
00101 typedef typename promote_trait<T_or_RGB, float>::TP TF;
00102 const Image<TF> source = src;
00103 if (w < 2)
00104 return source;
00105
00106 Image<TF> result(w, h, NO_INIT);
00107 typename Image<TF>::const_iterator sptr = source.begin();
00108 typename Image<TF>::iterator dptr = result.beginw();
00109
00110
00111
00112
00113
00114
00115
00116 for (int j = 0; j < h2; j ++)
00117 {
00118
00119 *dptr++ = sptr[0] * (2.0F / 3.0F) + sptr[1] * (1.0F / 3.0F);
00120
00121
00122 for (int i = 0; i < hf - 2; i ++)
00123 {
00124 *dptr++ = (sptr[0] + sptr[2]) * 0.25F + sptr[1] * 0.5F;
00125 sptr++;
00126 }
00127
00128
00129 *dptr++ = sptr[0] * (1.0F / 3.0F) + sptr[1] * (2.0F / 3.0F);
00130 sptr += 2;
00131 }
00132 return result;
00133 }
00134
00135
00136 template <class T_or_RGB>
00137 Image<typename promote_trait<T_or_RGB, float>::TP>
00138 lowPassLpt3w(const Image<T_or_RGB>& src)
00139 {
00140 GVX_TRACE(__PRETTY_FUNCTION__);
00141 const int w = src.getWidth(), h = src.getHeight();
00142
00143
00144
00145
00146
00147 typedef typename promote_trait<T_or_RGB, float>::TP TF;
00148 const Image<TF> source = src;
00149 if (h < 2)
00150 return source;
00151 Image<TF> result(w, h, NO_INIT);
00152 typename Image<TF>::const_iterator sptr = source.begin(),
00153 sptrh = source.begin() + w - 1;
00154 typename Image<TF>::iterator dptr = result.beginw();
00155 const int w2 = w * 2;
00156
00157
00158
00159
00160 for (int i = 0; i < w; i ++)
00161 {
00162
00163 *dptr++ = (sptrh[0] + sptr[w]) * 0.25F + sptr[0] * 0.5F;
00164 ++sptr;
00165 --sptrh;
00166 }
00167 sptr -= w;
00168
00169
00170 for (int j = 0; j < h - 2; j ++)
00171 for (int i = 0; i < w; i ++)
00172 {
00173 *dptr++ = (sptr[0] + sptr[w2]) * 0.25F + sptr[w] * 0.5F;
00174 ++sptr;
00175 }
00176
00177
00178 sptrh += w*h-1;
00179 for (int i = 0; i < w; i ++)
00180 {
00181 *dptr++ = (sptr[0] + sptrh[0]) * 0.25F + sptr[w] * 0.5F;
00182 ++sptr;
00183 --sptrh;
00184 }
00185
00186
00187 return result;
00188 }
00189
00190
00191 template <class T_or_RGB>
00192 Image<typename promote_trait<T_or_RGB, float>::TP>
00193 lowPassLpt5(const Image<T_or_RGB>& src, BorderPolicy policy)
00194 {
00195 if (policy == CROSS_HEMI)
00196 return lowPassLpt5w(lowPass5x(src));
00197 else if (policy == SEPARATE_HEMI)
00198 return lowPass5y(lowPassLpt5r(src));
00199 else
00200 return lowPassLpt5w(lowPassLpt5r(src));
00201 }
00202
00203
00204 template <class T_or_RGB>
00205 Image<typename promote_trait<T_or_RGB, float>::TP>
00206 lowPassLpt5r(const Image<T_or_RGB>& src)
00207 {
00208
00209
00210 GVX_TRACE(__PRETTY_FUNCTION__);
00211 const int w = src.getWidth(), h = src.getHeight(),
00212 hf = w/2, h2 = 2*h;
00213
00214
00215
00216
00217
00218 typedef typename promote_trait<T_or_RGB, float>::TP TF;
00219 const Image<TF> source = src;
00220 if (w < 4)
00221 return source;
00222 Image<TF> result(w, h, NO_INIT);
00223 typename Image<TF>::const_iterator sptr = source.begin();
00224 typename Image<TF>::iterator dptr = result.beginw();
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234 for (int j = 0; j < h2; j ++)
00235 {
00236
00237 *dptr++ = sptr[0] * (6.0F / 11.0F) +
00238 sptr[1] * (4.0F / 11.0F) +
00239 sptr[2] * (1.0F / 11.0F);
00240
00241
00242 *dptr++ = (sptr[0] + sptr[2]) * (4.0F / 15.0F) +
00243 sptr[1] * (6.0F / 15.0F) +
00244 sptr[3] * (1.0F / 15.0F);
00245
00246
00247 for (int i = 0; i < hf - 4; i ++)
00248 {
00249 *dptr++ = (sptr[0] + sptr[4]) * (1.0F / 16.0F) +
00250 (sptr[1] + sptr[3]) * (4.0F / 16.0F) +
00251 sptr[2] * (6.0F / 16.0F);
00252 ++sptr;
00253 }
00254
00255
00256 *dptr++ = sptr[0] * (1.0F / 15.0F) +
00257 (sptr[1] + sptr[3]) * (4.0F / 15.0F) +
00258 sptr[2] * (6.0F / 15.0F);
00259 ++sptr;
00260
00261
00262 *dptr++ = sptr[0] * (1.0F / 11.0F) +
00263 sptr[1] * (4.0F / 11.0F) +
00264 sptr[2] * (6.0F / 11.0F);
00265 sptr += 3;
00266 }
00267 return result;
00268 }
00269
00270
00271 template <class T_or_RGB>
00272 Image<typename promote_trait<T_or_RGB, float>::TP>
00273 lowPassLpt5w(const Image<T_or_RGB>& src)
00274 {
00275 GVX_TRACE(__PRETTY_FUNCTION__);
00276 const int w = src.getWidth(), h = src.getHeight();
00277
00278
00279
00280
00281
00282 typedef typename promote_trait<T_or_RGB, float>::TP TF;
00283 const Image<TF> source = src;
00284 if (h < 4)
00285 return source;
00286 Image<TF> result(w, h, NO_INIT);
00287 typename Image<TF>::const_iterator sptr = source.begin(),
00288 sptrh = source.begin()+w-1;
00289 typename Image<TF>::iterator dptr = result.beginw();
00290
00291
00292 const int w2 = w * 2, w3 = w * 3, w4 = w * 4;
00293
00294
00295 for (int i = 0; i < w; i ++)
00296 {
00297 *dptr++ = sptr[0] * (6.0F / 16.0F) +
00298 (sptr[w] + sptrh[0] ) * (4.0F / 16.0F) +
00299 (sptr[w2] + sptrh[w2] ) * (1.0F / 16.0F);
00300 ++sptr;
00301 --sptrh;
00302 }
00303 sptr -= w;
00304 sptrh += w;
00305
00306
00307 for (int i = 0; i < w; i ++)
00308 {
00309 *dptr++ = (sptr[0] + sptr[w2]) * (4.0F / 16.0F) +
00310 sptr[w] * (6.0F / 16.0F) +
00311 (sptr[w3] + sptrh[0]) * (1.0F / 16.0F);
00312 ++sptr;
00313 --sptrh;
00314 }
00315 sptr -= w;
00316
00317
00318 for (int j = 0; j < h - 4; j ++)
00319 for (int i = 0; i < w; i ++)
00320 {
00321 *dptr++ = (sptr[ 0] + sptr[w4]) * (1.0F / 16.0F) +
00322 (sptr[ w] + sptr[w3]) * (4.0F / 16.0F) +
00323 sptr[w2] * (6.0F / 16.0F);
00324 sptr++;
00325 }
00326
00327 sptrh = source.end();
00328
00329 for (int i = 0; i < w; i ++)
00330 {
00331 *dptr++ = (sptr[0] + sptrh[0]) * (1.0F / 16.0F) +
00332 (sptr[w] + sptr[w3]) * (4.0F / 16.0F) +
00333 sptr[w2] * (6.0F / 16.0F);
00334 ++sptr;
00335 --sptrh;
00336 }
00337 --sptrh;
00338
00339 for (int i = 0; i < w; i ++)
00340 {
00341 *dptr++ = (sptr[0] + sptrh[0]) * (1.0F / 16.0F) +
00342 (sptr[w] + sptrh[w]) * (4.0F / 16.0F) +
00343 sptr[w2] * (6.0F / 16.0F);
00344 ++sptr;
00345 --sptrh;
00346 }
00347
00348 return result;
00349 }
00350
00351
00352
00353
00354 #include "inst/Image/LowPassLpt.I"
00355
00356 template
00357 Image<promote_trait<double, float>::TP>
00358 lowPassLpt(const Image<double>& src, const uint taps,
00359 BorderPolicy policy);
00360
00361 template
00362 Image<promote_trait<double, float>::TP>
00363 lowPassLpt3(const Image<double>& src, BorderPolicy policy);
00364
00365 template
00366 Image<promote_trait<double, float>::TP>
00367 lowPassLpt3r(const Image<double>& src);
00368
00369 template
00370 Image<promote_trait<double, float>::TP>
00371 lowPassLpt3w(const Image<double>& src);
00372
00373 template
00374 Image<promote_trait<double, float>::TP>
00375 lowPassLpt5(const Image<double>& src, BorderPolicy policy);
00376
00377 template
00378 Image<promote_trait<double, float>::TP>
00379 lowPassLpt5r(const Image<double>& src);
00380
00381 template
00382 Image<promote_trait<double, float>::TP>
00383 lowPassLpt5w(const Image<double>& src);
00384
00385
00386
00387
00388
00389
00390
00391
00392 #endif // IMAGE_LOWPASSLPT_C_DEFINED