src/Perturb.cpp
/**
 * \brief Find Mat value at point (x,y) via bilinear interpolation.
 * https://en.wikipedia.org/wiki/Bilinear_interpolation
 */
\brief Find Mat value at point (x,y) via bilinear interpolation.
\ brief Find Mat value at point ( x y ) via bilinear interpolation .
float Perturb::interp(const cv::Mat& img, const float point_x, const float point_y)
{
  float x = clamp(point_x, 0, static_cast<float>(img.cols - 2));
  float y = clamp(point_y, 0, static_cast<float>(img.rows - 2));
  float xi[2] = { floor(x), floor(x + 1) };
  float yi[2] = { floor(y), floor(y + 1) };
  auto f = [&](int cx, int cy) {
    return img.at<float>(static_cast<int>(yi[cy]), static_cast<int>(xi[cx]));
  };
  float fxy0 = (xi[1] - x) * f(0, 0) + (x - xi[0]) * f(1, 0);
  float fxy1 = (xi[1] - x) * f(0, 1) + (x - xi[0]) * f(1, 1);
  float value = (yi[1] - y) * fxy1 + (y - yi[0]) * fxy1;
  return value;
}
float Perturb :: interp ( const cv :: Mat & img , const float point_x , const float point_y ) { float x = clamp ( point_x , 0 , static_cast < float > ( img . cols - 2 ) ) ; float y = clamp ( point_y , 0 , static_cast < float > ( img . rows - 2 ) ) ; float xi [ 2 ] = { floor ( x ) , floor ( x + 1 ) } ; float yi [ 2 ] = { floor ( y ) , floor ( y + 1 ) } ; auto f = [ & ] ( int cx , int cy ) { return img . at < float > ( static_cast < int > ( yi [ cy ] ) , static_cast < int > ( xi [ cx ] ) ) ; } ; float fxy0 = ( xi [ 1 ] - x ) * f ( 0 , 0 ) + ( x - xi [ 0 ] ) * f ( 1 , 0 ) ; float fxy1 = ( xi [ 1 ] - x ) * f ( 0 , 1 ) + ( x - xi [ 0 ] ) * f ( 1 , 1 ) ; float value = ( yi [ 1 ] - y ) * fxy1 + ( y - yi [ 0 ] ) * fxy1 ; return value ; }
\brief Find Mat value at point (x,y) via bilinear interpolation.
\ brief Find Mat value at point ( x y ) via bilinear interpolation .