Esempio n. 1
0
        public Mat Recovery(ComplexMoments decomposition)
        {
            var result = Mat.Zeros(Polynomials[0][0].Item1.Mat.Rows, Polynomials[0][0].Item1.Mat.Cols, DepthType.Cv64F, 1);
            for (var n = 0; n < Polynomials.Count; ++n)
            for (var m = 0; m < n + 1; ++m)
            {
                if ((n - m) % 2 == 0)
                    result += Polynomials[n][m].Item1.Mat * decomposition.Real.GetValue(n, m) + Polynomials[n][m].Item2.Mat * decomposition.Image.GetValue(n, m);
            }

            return result;
        }
Esempio n. 2
0
 public ComplexMoments Decompose(Mat blob)
 {
     var result = new ComplexMoments
     {
             Real = Mat.Zeros(Polynomials.Count, Polynomials.Count, DepthType.Cv64F, 1),
             Image = Mat.Zeros(Polynomials.Count, Polynomials.Count, DepthType.Cv64F, 1),
             Abs = Mat.Zeros(Polynomials.Count, Polynomials.Count, DepthType.Cv64F, 1),
             Phase = Mat.Zeros(Polynomials.Count, Polynomials.Count, DepthType.Cv64F, 1)
     };
     var tmpBlob = new Mat();
     _ = new Point[1];
     blob.MinMax(out var min, out var max, out _, out _);
     var alpha = 255 / (max[0] - min[0]);
     var beta = -255 * min[0] / ((max[0] - min[0]));
     blob.ConvertTo(tmpBlob, DepthType.Cv64F, alpha, beta);
     double tmpRealDenominator = 0;
     double tmpImageDenominator = 0;
     double tmpAbsDenominator = 0;
     for (var n = 0; n < Polynomials.Count; ++n)
     for (var m = 0; m < n+1; ++m)
     {
         if ((n - m) % 2 != 0) continue;
         var tmpMoment = tmpBlob.Dot(Polynomials[n][m].Item1);
         result.Real.SetValue(n, m, Math.Abs(tmpMoment) > 1e-20 ? tmpMoment : 0);
         tmpMoment = tmpBlob.Dot(Polynomials[n][m].Item2);
         result.Image.SetValue(n, m, Math.Abs(tmpMoment) > 1e-20 ? tmpMoment : 0);
         var tmpReal = result.Real.GetValue(n, m);
         var tmpImage = result.Image.GetValue(n, m);
         tmpRealDenominator += tmpReal* tmpReal;
         tmpImageDenominator += tmpImage * tmpImage;
         double tmpAbs = Math.Sqrt(tmpReal * tmpReal + tmpImage * tmpImage);
         tmpAbsDenominator += tmpAbs * tmpAbs;
         result.Abs.SetValue(m, n, tmpAbs);
         double tmpAngle = Math.Atan2(tmpImage, tmpReal);
         result.Phase.SetValue(m, n, tmpAngle);
     }
     //for (var n = 0; n < Polynomials.Count; ++n)
     //    for (var m = 0; m < n + 1; ++m)
     //    {
     //        if ((n - m) % 2 != 0) continue;
     //        double tmpMoment = result.Real.GetValue(n, m) / Math.Sqrt(tmpRealDenominator);
     //        result.Real.SetValue(n, m, tmpMoment);
     //        tmpMoment = result.Image.GetValue(n, m) / Math.Sqrt(tmpImageDenominator);
     //        result.Image.SetValue(n, m, tmpMoment);
     //        tmpMoment = result.Abs.GetValue(n, m) / Math.Sqrt(tmpAbsDenominator);
     //        result.Abs.SetValue(m, n, tmpMoment);
     //    }
     return result;
 }
Esempio n. 3
0
 public static List <double> ToListOfDouble(this ComplexMoments cm)
 {
     return(cm.Abs.GetData().OfType <double>().ToList());
 }