Commit a8eb67946b2c15ae3975cd8eee9430e5aba18c5a

Authored by Josh Klontz
1 parent 922d0217

introduced NormalizeTransform::squareRoot

Showing 1 changed file with 19 additions and 1 deletions
openbr/plugins/normalize.cpp
... ... @@ -64,6 +64,8 @@ class NormalizeTransform : public UntrainableTransform
64 64 BR_PROPERTY(int, alpha, 1)
65 65 Q_PROPERTY(int beta READ get_beta WRITE set_beta RESET reset_beta STORED false)
66 66 BR_PROPERTY(int, beta, 0)
  67 + Q_PROPERTY(bool squareRoot READ get_squareRoot WRITE set_squareRoot RESET reset_squareRoot STORED false)
  68 + BR_PROPERTY(bool, squareRoot, false)
67 69  
68 70 public:
69 71 /*!< */
... ... @@ -75,14 +77,30 @@ public:
75 77 private:
76 78 BR_PROPERTY(NormType, normType, L2)
77 79  
  80 + static void signedSquareRoot(Mat &m)
  81 + {
  82 + for (int i=0; i<m.rows; i++)
  83 + for (int j=0; j<m.cols; j++) {
  84 + float &val = m.at<float>(i, j);
  85 + val = sqrtf(fabsf(val)) * (val >= 0 ? 1 : -1);
  86 + }
  87 + }
  88 +
78 89 void project(const Template &src, Template &dst) const
79 90 {
80   - if (!ByRow) normalize(src, dst, alpha, beta, normType, CV_32F);
  91 + if (!ByRow) {
  92 + normalize(src, dst, alpha, beta, normType, CV_32F);
  93 + if (squareRoot)
  94 + signedSquareRoot(dst);
  95 + }
  96 +
81 97 else {
82 98 dst = src;
83 99 for (int i=0; i<dst.m().rows; i++) {
84 100 Mat temp;
85 101 cv::normalize(dst.m().row(i), temp, alpha, beta, normType);
  102 + if (squareRoot)
  103 + signedSquareRoot(temp);
86 104 temp.copyTo(dst.m().row(i));
87 105 }
88 106 }
... ...