core/vil1/vil1_clamp_image.cxx

Go to the documentation of this file.
00001 // This is core/vil1/vil1_clamp_image.cxx
00002 #ifdef VCL_NEEDS_PRAGMA_INTERFACE
00003 #pragma implementation
00004 #endif
00005 
00006 #include "vil1_clamp_image.h"
00007 #include <vil1/vil1_image.h>
00008 #include <vil1/vil1_rgb.h>
00009 #include <vxl_config.h>
00010 
00011 #undef VIL1_CLAMP_IMAGE_THRESHOLD
00012 #define VIL1_CLAMP_IMAGE_THRESHOLD(V, L, H) \
00013   if (V > H) V = H; \
00014   else if (V < L) V = L
00015 
00016 template <class T>
00017 bool vil1_clamp_image(vil1_image const& base, double low, double high,
00018                       T *buf, int x0, int y0, int w, int h)
00019 {
00020   if (!base.get_section(buf, x0, y0, w, h)) return false;
00021 
00022   unsigned size = w*h;
00023   T low_thresh = T(low);
00024   T high_thresh = T(high);
00025   for (unsigned pos=0; pos < size; ++pos) {
00026     VIL1_CLAMP_IMAGE_THRESHOLD(buf[pos], low_thresh, high_thresh);
00027   }
00028   return true;
00029 }
00030 
00031 #undef VIL1_INSTANTIATE_CLAMP_IMAGE
00032 #define VIL1_INSTANTIATE_CLAMP_IMAGE(T) \
00033 template bool vil1_clamp_image(vil1_image const& base, double low, double high, \
00034                                T *buf, int x0, int y0, int w, int h)
00035 
00036 #undef VIL1_SPECIALIZE_CLAMP_IMAGE_RGB
00037 #define VIL1_SPECIALIZE_CLAMP_IMAGE_RGB(T) \
00038 VCL_DEFINE_SPECIALIZATION \
00039 bool vil1_clamp_image(vil1_image const& base, double low, double high, \
00040                       vil1_rgb<T> *buf, int x0, int y0, int w, int h) \
00041 { \
00042   if (!base.get_section(buf, x0, y0, w, h)) return false; \
00043   unsigned size = w*h; \
00044   T low_thresh = T(low); \
00045   T high_thresh = T(high); \
00046   for (unsigned pos=0; pos < size; ++pos) { \
00047     VIL1_CLAMP_IMAGE_THRESHOLD(buf[pos].r, low_thresh, high_thresh); \
00048     VIL1_CLAMP_IMAGE_THRESHOLD(buf[pos].g, low_thresh, high_thresh); \
00049     VIL1_CLAMP_IMAGE_THRESHOLD(buf[pos].b, low_thresh, high_thresh); \
00050   } \
00051   return true; \
00052 }
00053 
00054 VIL1_INSTANTIATE_CLAMP_IMAGE(vxl_byte);
00055 VIL1_INSTANTIATE_CLAMP_IMAGE(float);
00056 VIL1_INSTANTIATE_CLAMP_IMAGE(double);
00057 
00058 VIL1_SPECIALIZE_CLAMP_IMAGE_RGB(vxl_byte);
00059 VIL1_SPECIALIZE_CLAMP_IMAGE_RGB(float);
00060 VIL1_SPECIALIZE_CLAMP_IMAGE_RGB(double);

Generated on Mon Mar 8 05:09:32 2010 for core/vil1 by  doxygen 1.5.1