TuttleOFX
1
|
00001 /** 00002 * @brief This file provides a set of reimplementations of CImg functions by means of the generic image library (gil). 00003 * Functions for interpolation 00004 */ 00005 #ifndef _TUTTLE_ANISOTROPICDIFFUSION_INTERPOLATION_HPP_ 00006 #define _TUTTLE_ANISOTROPICDIFFUSION_INTERPOLATION_HPP_ 00007 00008 #include <boost/gil/gil_all.hpp> 00009 00010 #include <cmath> 00011 00012 namespace tuttle { 00013 namespace imageUtils { 00014 00015 /** 00016 * @brief Return right pixel from unsafe coordinates 00017 * 00018 * @param[in] W input image (linear buffer, cache optimisation) 00019 * @param[in] x abscisse 00020 * @param[in] y ordinate 00021 * @param[in] c channel index 00022 * @param[in] w image width 00023 * @param[in] h image height 00024 * @param[in] nc channels number 00025 * @return right pixel 00026 */ 00027 inline const float& 00028 pix2d(const float *W, const int x, const int y, const int c, 00029 const int w, const int h, const int nc) { 00030 return W[((y < 0 ? 0 : (y >= h ? h - 1 : y)) * w + 00031 (x < 0 ? 0 : (x >= w ? w - 1 : x))) * nc + c]; 00032 } 00033 00034 /** 00035 * @brief Return right pixel from unsafe coordinates 00036 * 00037 * @param[in] myView input view 00038 * @param[in] x abscisse 00039 * @param[in] y ordinate 00040 * @param[in] c channel index 00041 * @param[in] w image width 00042 * @param[in] h image height 00043 * @param[in] nc channels number 00044 * @return right pixel 00045 */ 00046 template <typename DstView> 00047 const float 00048 pix2d(DstView &myView, const int x, const int y, 00049 const int c, const int w, const int h) { 00050 return myView((x < 0 ? 0 : (x >= w ? w - 1 : x)), 00051 (y < 0 ? 0 : (y >= h ? h - 1 : y)))[c]; 00052 } 00053 00054 /** 00055 * @brief Return interpolated pixel 00056 * 00057 * @param[in] W input image (linear buffer, cache optimisation) 00058 * @param[in] fx float abscisse 00059 * @param[in] fy float ordinate 00060 * @param[in] c channel index 00061 * @param[in] w image width 00062 * @param[in] h image height 00063 * @param[in] nc channels number 00064 * @return right pixel 00065 */ 00066 inline float 00067 linear_pix2d(const float *W, const float fx, const float fy, const int c, 00068 const int w, const int h, const int nc) { 00069 const int 00070 x = (int)fx - (fx >= 0 ? 0 : 1), nx = x + 1, 00071 y = (int)fy - (fy >= 0 ? 0 : 1), ny = y + 1; 00072 const float 00073 dx = fx-x, 00074 dy = fy-y; 00075 const float 00076 Icc = pix2d(W, x, y, c, w, h, nc), 00077 Inc = pix2d(W, nx, y, c, w, h, nc), 00078 Icn = pix2d(W, x, ny, c, w, h, nc), 00079 Inn = pix2d(W, nx, ny, c, w, h, nc); 00080 return Icc + dx * (Inc - Icc + dy * (Icc + Inn - Icn - Inc)) + dy * (Icn - Icc); 00081 } 00082 00083 /** 00084 * @brief Return interpolated pixel 00085 * 00086 * @param[in] myView input view 00087 * @param[in] fx float abscisse 00088 * @param[in] fy float ordinate 00089 * @param[in] c channel index 00090 * @param[in] w image width 00091 * @param[in] h image height 00092 * @param[in] nc channels number 00093 * @return right pixel 00094 */ 00095 template <typename DstView> 00096 float 00097 linear_pix2d(DstView &myView, const float fx, const float fy, 00098 const int c, const int w, const int h) { 00099 const int 00100 x = (int)fx - (fx >= 0 ? 0 : 1), nx = x + 1, 00101 y = (int)fy - (fy >= 0 ? 0 : 1), ny = y + 1; 00102 const float 00103 dx = fx-x, 00104 dy = fy-y; 00105 const float 00106 Icc = pix2d(myView, x, y, c, w, h), 00107 Inc = pix2d(myView, nx, y, c, w, h), 00108 Icn = pix2d(myView, x, ny, c, w, h), 00109 Inn = pix2d(myView, nx, ny, c, w, h); 00110 return Icc + dx * (Inc - Icc + dy * (Icc + Inn - Icn - Inc)) + dy * (Icn - Icc); 00111 } 00112 00113 } 00114 } 00115 00116 #endif 00117