《Image Warping Using Few Anchor Points and Radial Function》论文实现

《Image Warping Using Few Anchor Points and Radial Functions》achive based OpenCv 、Eigen and Qt

  • (vector blod)
  • paper
    [paper Download](Image Warping Using Few Anchor Points and Radial Functions "paper Download")
  • Tools
    • Eigen
    • OpenCV
  • Concepts
    • radial basic function transformation(RBFT)
    • affine transformation
    • radial transformation
    • radial basic function
    • Euclidean
    • thin-plate spline
    • Gaussians function
  • Important Equation
    • T(xi)=yi for i=1,2,3,……N.——** Equation(1) **
    • T(x)=A(x)+R(x)——** Equation(2) **
    • A(x)=Mx+b ,2D Affine transformation,M is 2 x 2 real Matrix—— ** Equation(3) **
    • R(x)=(Rx(x),Ry(x)),Rx and Ry are both radial functions of the form radial function
      g:is aunivariate function,termed the radial basis function
      ||·||:Euclidean norm
      ai & bi: is determined by Anchor Points——** Equation(4) **
    • R(xi)=yi-A(xi),i=1,2,3,……N.——** Equation(5) **
    • ——** Equation(6) **
    • Gaussian function:——** Equation(7) **
    • thin-plate spline:——** Equation(8) **
  • Thinking
    1. load Image
      load Image
    2. get Anchor points by User Interactive
      get anchor points
    3. Analysis source Point and target Point
    4. Controlling the affine component A(x) accoring to the number of anchor points,by Equation(3)
    5. determining the radial component R(x),by Equation(4),Equation(5)
    6. Apply T(x) to every pixel in this image
  • Question and Answer(Q&A)
    • Q1:How to save Image?
    • A1:Translate cv::Mat to Eigen::MatrixXd(3,width*height).
    • Q2:How to save "M" Matrix in Equation(3)?
    • A2:Using Eigen::MartrixXd(2,3).
    • Q3:How to Calcualte "R" Matrix in Equation(2)?
    • A3:Reference Equation(4) and Equation(5).
    • Q4:How to calculate g(x) in Equation(4)?
    • A4:thin-plate spline or Gaussian function.
    • Q5:How to save coordinate before transform?
    • A5:Using MatrixXd(2,1).
    • Q6:How to save coordinate after transform?
    • A6:Using MatrixXd(2,1).
    • Q7:How to save source points and target points?
    • A7:Using Eigen::MatrixXd(2,N)
    • Q8:How to save corespondence between source coordinate and target coordinate?
    • A8: Qt::QList<Line*> lineList;Line is line for start point to end point for anchor pairs.
  • Achieve
    • WarpingRBF.h
  1. //WarpingRBF.h
  2. #ifndef WARPINGRBF_H
  3. #define WARPINGRBF_H
  4. #include<opencv2/opencv.hpp>
  5. #include<QList>
  6. #include<Eigen/Eigen>
  7. #include"line.h"
  8. class WarpingRBF
  9. {
  10. public:
  11. enum GFuncType{
  12. Gaussian_Radio_Function,
  13. Thin_Plate_spline,//r^2log(r)
  14. Gaussian_Radial
  15. };
  16. public:
  17. WarpingRBF();
  18. WarpingRBF(const QList<Line*> & lineList,
  19. const int&N);
  20. public:
  21. void SolveRBF();
  22. void SetImage(const cv::Mat &sourceImage);
  23. void SetGFunc(const GFuncType &gfunctype);
  24. protected:
  25. void InitData();
  26. void InitSourceAndTargetMaritrix(const QList<Line*> &list,
  27. Eigen::MatrixXd &Source_M,
  28. Eigen::MatrixXd &Target_M);
  29. void InitImageMatrix(const cv::Mat &sourceImage,
  30. const int&height,
  31. const int &width,
  32. Eigen::MatrixXd &Image_M);
  33. void CalculateAffineMat(const Eigen::MatrixXd &Source_M,
  34. const Eigen::MatrixXd &Target_M,
  35. const int &N,
  36. cv::Mat &Affine_Mat);
  37. void AffineTranslate(const cv::Mat &srcImage,
  38. const cv::Mat &Affine_Mat,
  39. Eigen::MatrixXd &AfterAffine_M);
  40. void RadioTranslate(const Eigen::MatrixXd &Image_M,
  41. const Eigen::MatrixXd &Source_M,
  42. const Eigen::MatrixXd &Target_M,
  43. const GFuncType &gfunctype,
  44. const cv::Mat &Affine_Mat,
  45. const int &N,
  46. const int &height,
  47. const int &width,
  48. Eigen::MatrixXd &AfterRadio_M);
  49. void RBFTranslate(const Eigen::MatrixXd AfterAffine_M,
  50. const Eigen::MatrixXd AfterRadio_M,
  51. Eigen::MatrixXd Image_M);
  52. void ApplyChangeOnImage(cv::Mat &dstImage,const Eigen::MatrixXd Image_M);
  53. double GetEulaNorm(const Eigen::MatrixXd X_M);//(2*1)--(x,y)^T
  54. private:
  55. cv::Mat srcImage,dstImage,Affine_Mat;
  56. int height,width;
  57. Eigen::MatrixXd Image_M,Source_M,Target_M,AfterAffine_M,AfterRadio_M;
  58. GFuncType gfunctype;
  59. int N;//number of Anchor Points
  60. QList<Line*> lineList;
  61. };
  • Line.h
  1. #ifndef LINE_H
  2. #define LINE_H
  3. #include<QPoint>
  4. class Line
  5. {
  6. public:
  7. Line();
  8. Line(QPoint start,QPoint end);
  9. void SetStart(QPoint start);
  10. void SetEnd(QPoint End);
  11. QPoint end,start;
  12. private:
  13. };
  14. #endif // LINE_H




posted @ 2016-10-09 11:43  livera  阅读(721)  评论(0编辑  收藏  举报