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
00038 #ifndef IMAGE_INTEGERMATHOPS_H_DEFINED
00039 #define IMAGE_INTEGERMATHOPS_H_DEFINED
00040
00041 #include "Image/Image.H"
00042 #include "Image/ImageSet.H"
00043 #include "Image/PyrBuilder.H"
00044 #include "Image/fancynorm.H"
00045 #include "Image/integer_math.h"
00046
00047 #include <deque>
00048
00049 template <int tabsiz_, int nbits_>
00050 class IntgTrigTable
00051 {
00052 public:
00053 enum { tabsiz = tabsiz_ };
00054 enum { nbits = nbits_ };
00055
00056 IntgTrigTable()
00057 {
00058 for (int i = 0; i < tabsiz; ++i)
00059 {
00060 const double arg = (2.0*M_PI*i) / double(tabsiz);
00061 #ifdef HAVE_SINCOS
00062 double sinarg, cosarg;
00063 sincos(arg, &sinarg, &cosarg);
00064 #else
00065 double sinarg = sin(arg);
00066 double cosarg = cos(arg);
00067 #endif
00068 sintab[i] = int(sinarg * (1 << nbits));
00069 costab[i] = int(cosarg * (1 << nbits));
00070 }
00071 }
00072
00073 int indexDegrees(const double deg)
00074 {
00075 int idx = int((deg * tabsiz) / 360.0) % tabsiz;
00076 if (idx < 0) idx += tabsiz;
00077 return idx;
00078 }
00079
00080 int indexRadians(const double rad)
00081 {
00082 int idx = int((rad * tabsiz) / (2.0*M_PI)) % tabsiz;
00083 if (idx < 0) idx += tabsiz;
00084 return idx;
00085 }
00086
00087 int sintab[tabsiz];
00088 int costab[tabsiz];
00089
00090 private:
00091
00092 bool inited;
00093 };
00094
00095
00096
00097
00098 int intgScaleFromByte(const byte* src, const uint nbits);
00099
00100
00101
00102
00103 int intgScaleFromFloat(const float* src, const uint nbits);
00104
00105
00106
00107
00108 Image<int> intgScaleFromByte(const Image<byte>* src, const uint nbits);
00109
00110
00111
00112
00113 Image<int> intgScaleFromFloat(const Image<float>* src, const uint nbits);
00114
00115
00116
00117
00118 Image<PixRGB<int> > intgScaleFromByte(const Image<PixRGB<byte> >* src, const uint nbits);
00119
00120
00121 Image<int> intgScaleLuminanceFromByte(const Image<PixRGB<byte> >* src, const uint nbits);
00122
00123
00124
00125
00126 Image<PixRGB<int> > intgScaleFromFloat(const Image<PixRGB<float> >* src, const uint nbits);
00127
00128
00129
00130
00131 Image<float> intgScaleToFloat(const Image<int>* src, const uint nbits);
00132
00133 Image<int> intgLowPass5xDecX(const Image<int>& src,
00134 const integer_math* imath);
00135
00136 Image<int> intgLowPass5yDecY(const Image<int>& src,
00137 const integer_math* imath);
00138
00139 Image<int> intgXFilterClean(const Image<int>& src,
00140 const int* hFilt, const int hfs,
00141 const int shiftbits,
00142 const integer_math* imath);
00143
00144 Image<int> intgYFilterClean(const Image<int>& src,
00145 const int* vFilt, const int vfs,
00146 const int shiftbits,
00147 const integer_math* imath);
00148
00149 Image<int> intgLowPass9x(const Image<int>& src,
00150 const integer_math* imath);
00151 Image<int> intgLowPass9y(const Image<int>& src,
00152 const integer_math* imath);
00153 Image<int> intgLowPassX(int filterSize, const Image<int>& src,
00154 const integer_math* imath);
00155 Image<int> intgLowPassY(int filterSize, const Image<int>& src,
00156 const integer_math* imath);
00157 Image<int> intgLowPass(int filterSize, const Image<int>& src,
00158 const integer_math* imath);
00159 Image<int> intgQuadEnergy(const Image<int>& img1, const Image<int>& img2);
00160 Image<int> intgOrientedFilter(const Image<int>& src,
00161 const float k, const float theta,
00162 const integer_math* imath);
00163 void intgInplaceAttenuateBorders(Image<int>& a, int size);
00164 ImageSet<int> intgBuildPyrLaplacian(const Image<int>& image,
00165 int firstlevel, int depth,
00166 int filterSize,
00167 const integer_math* imath);
00168 ImageSet<int> intgBuildPyrOrientedFromLaplacian(const ImageSet<int>& lplc,
00169 const int filterSize,
00170 const float theta,
00171 const integer_math* imath);
00172 ImageSet<int> intgBuildPyrOriented(const Image<int>& image,
00173 int firstlevel, int depth,
00174 int filterSize, float theta,
00175 const integer_math* imath);
00176 ImageSet<int> intgBuildPyrGaussian(const Image<int>& image,
00177 int depth, int filterSize,
00178 const integer_math* imath);
00179
00180 Image<int> intgDownSize(const Image<int>& src, const Dims& dims,
00181 const int filterWidth,
00182 const integer_math* imath);
00183 Image<int> intgRescale(const Image<int>& src, const Dims& dims);
00184 void intgInplaceAddBGnoise(Image<int>& src, int max);
00185 Image<int> intgMaxNormalize(const Image<int>& src, int min, int max,
00186 MaxNormType typ);
00187 Image<int> intgMaxNormalizeNone(const Image<int>& src, int min, int max);
00188 Image<int> intgMaxNormalizeStd(const Image<int>& src, int min, int max);
00189 Image<int> intgCenterSurround(const ImageSet<int>& pyr,
00190 int lev1, int lev2, bool absol,
00191 const ImageSet<int>* clipPyr);
00192
00193 void intgDoLowThresh(ImageSet<int>& pyr, int thresh, int newval = 0);
00194
00195 void intgDoLowThreshAbs(ImageSet<int>& pyr, int thresh, int newval = 0);
00196
00197 void intgDoRectify(ImageSet<int>& pyr);
00198
00199 void intgInplaceNormalize(Image<int>& dst,
00200 const int nmin, const int nmax,
00201 int* actualmin, int* actualmax);
00202
00203 Image<int> intgCenterSurround(const Image<int>& center,
00204 const Image<int>& surround,
00205 const bool absol);
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223 void intgGetRGBY(const Image<PixRGB<byte> >& src,
00224 Image<int>& rg,
00225 Image<int>& by, const int threshfactor,
00226 const uint inputbits);
00227
00228 Image<int> intgShiftImage(const Image<int>& srcImg,
00229 const int dxnumer, const int dynumer,
00230 const uint denombits);
00231
00232
00233
00234 class IntgGaussianPyrBuilder : public PyrBuilder<int>
00235 {
00236 public:
00237
00238 IntgGaussianPyrBuilder(const int filter_size,
00239 const integer_math* imath);
00240
00241
00242
00243
00244 virtual IntgGaussianPyrBuilder* clone() const;
00245
00246
00247 virtual ImageSet<int> build(const Image<int>& img,
00248 const int firstlevel, const int depth,
00249 PyramidCache<int>* cache = 0);
00250
00251 private:
00252 const int itsFiltSize;
00253 const integer_math* const itsImath;
00254 };
00255
00256
00257
00258
00259 class IntgOrientedPyrBuilder : public PyrBuilder<int>
00260 {
00261 public:
00262
00263 IntgOrientedPyrBuilder(const int filter_size, const float theta,
00264 const integer_math* imath);
00265
00266
00267
00268
00269 virtual IntgOrientedPyrBuilder* clone() const;
00270
00271
00272 virtual ImageSet<int> build(const Image<int>& img,
00273 const int firstlevel, const int depth,
00274 PyramidCache<int>* cache = 0);
00275
00276 private:
00277 const int itsFiltSize;
00278 const float itsAngle;
00279 const integer_math* const itsImath;
00280 };
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 class IntgReichardtPyrBuilder : public PyrBuilder<int>
00291 {
00292 public:
00293
00294
00295
00296
00297
00298
00299
00300
00301 IntgReichardtPyrBuilder(const int dxnumer, const int dynumer,
00302 const uint denombits,
00303 const integer_math* imath);
00304
00305
00306
00307
00308
00309 virtual IntgReichardtPyrBuilder* clone() const;
00310
00311
00312 virtual ImageSet<int> build(const Image<int>& image,
00313 const int firstlevel, const int depth,
00314 PyramidCache<int>* cache = 0);
00315
00316
00317 virtual void reset();
00318
00319 private:
00320 const int itsDXnumer;
00321 const int itsDYnumer;
00322 const uint itsDenomBits;
00323 const integer_math* const itsImath;
00324 std::deque< ImageSet<int> > shifted, unshifted;
00325 };
00326
00327
00328
00329
00330
00331
00332
00333
00334 #endif // IMAGE_INTEGERMATHOPS_H_DEFINED