Esempio n. 1
0
        public static Emgu.CV.Matrix <int> HotMatrix(Emgu.CV.Matrix <int> y_label, int ClassCount)
        {
            var HotVector = new Emgu.CV.Matrix <int>(y_label.Rows, ClassCount);

            HotVector.SetZero();
            for (int row = 0; row < y_label.Rows; row++)
            {
                HotVector[row, y_label[row, 0]] = 1;
            }
            return(HotVector);
        }
Esempio n. 2
0
        public static Emgu.CV.Matrix <int> Matrix2OneHotEncoding(Emgu.CV.Matrix <int> matrix, int ClassCount)
        {
            Emgu.CV.Matrix <int> HotVector = new Emgu.CV.Matrix <int>(matrix.Rows, ClassCount);
            HotVector.SetZero();
            for (int row = 0; row < matrix.Height; row++)
            {
                var col = (int)(matrix[row, 0]);
                HotVector[row, col] = 1;
            }

            return(HotVector);
        }
Esempio n. 3
0
        public static Emgu.CV.Matrix <int> DecodeHotMatrix(Emgu.CV.Matrix <int> y_label)
        {
            var DecodedMatrix = new Emgu.CV.Matrix <int>(y_label.Rows, 1);

            DecodedMatrix.SetZero();
            for (int row = 0; row < y_label.Rows; row++)
            {
                for (int col = 0; col < y_label.Cols; col++)
                {
                    if (y_label[row, col] == 1)
                    {
                        DecodedMatrix[row, 0] = col;
                        break;
                    }
                }
            }
            return(DecodedMatrix);
        }
Esempio n. 4
0
        public static Emgu.CV.Matrix <double> LAMP(Emgu.CV.Matrix <double> X, int[] idx, Emgu.CV.Matrix <double> Ys)
        {
            //if (!s_CheckInputErrorsLAMP(X, cp_index, Ys)) {
            //  fprintf(stderr, "ERROR: lamp - Invalid input.\n");
            //  return Mat::zeros(1, 1, CV_8UC1);
            //}

            double tol = 1E-003;

            // Building an array with the indices of the points to be projected.
            //std::vector<int> proj_idx(X.rows);
            //for (int i = 0; i < X.rows; ++i)
            //  proj_idx[i] = i;
            //for (int i = 0; i < cp_index.size(); ++i)
            //  proj_idx[cp_index[i]] = -1;
            //

            // Building the control points and projected points matrices.
            Emgu.CV.Matrix <double> Xs = new Emgu.CV.Matrix <double>(idx.Length, X.Cols);
            Xs.SetZero();

            Emgu.CV.Matrix <double> Y = new Emgu.CV.Matrix <double>(X.Rows, Ys.Cols);
            Y.SetZero();

            //for (int i = 0; i < Xs.rows; ++i) {
            //  X.row(cp_index[i]).copyTo(Xs.row(i));
            //  Ys.row(i).copyTo(Y.row(cp_index[i]));
            //}
            //
            //Mat alpha = Mat::zeros(1, cp_index.size(), CV_32FC1);
            //for (int i = 0; i < X.rows; ++i) {
            //  if (proj_idx[i] == -1)
            //    continue;
            //
            //  // Building the weights of each control point over the current point.
            //  for (int j = 0; j < cp_index.size(); ++j)
            //    alpha.at<float>(0, j) = 1 / cv::max(cv::norm(Xs.row(j), X.row(proj_idx[i])), tol);
            //
            //  float sum_alpha = cv::sum(alpha)[0];
            //
            //  Mat T = Mat::zeros(Xs.rows, Xs.cols, Xs.depth());
            //  for (int k = 0; k < Xs.cols; ++k)
            //    T.col(k) = Xs.col(k).mul(alpha.t());
            //
            //  // Building the x-tilde and y-tilde variables (Eq. 3).
            //  Mat Xtil;
            //  cv::reduce(T, Xtil, 0, CV_REDUCE_SUM);
            //  Xtil = Xtil * (1 / sum_alpha);
            //
            //  T = Mat::zeros(Ys.rows, Ys.cols, Ys.depth());
            //  for (int k = 0; k < Ys.cols; ++k)
            //    T.col(k) = Ys.col(k).mul(alpha.t());
            //
            //  Mat Ytil;
            //  cv::reduce(T, Ytil, 0, CV_REDUCE_SUM);
            //  Ytil = Ytil * (1 / sum_alpha);
            //
            //  // Building the x-hat and y-hat variables (Eq. 4).
            //  Mat Xhat = Mat::zeros(Xs.rows, Xs.cols, Xs.depth());
            //  for (int k = 0; k < Xs.rows; ++k)
            //    Xhat.row(k) = Xs.row(k) - Xtil;
            //
            //  Mat Yhat = Mat::zeros(Ys.rows, Ys.cols, Ys.depth());
            //  for (int k = 0; k < Ys.rows; ++k)
            //    Yhat.row(k) = Ys.row(k) - Ytil;
            //
            //  // Building the A and B matrices (Eq. 6) and calculating the SVD of t(A) * B.
            //  Mat sqrt_alpha;
            //  cv::sqrt(alpha, sqrt_alpha);
            //  sqrt_alpha = sqrt_alpha.t();
            //
            //  Mat A;
            //  Xhat.copyTo(A);
            //  for (int k = 0; k < A.cols; ++k)
            //    A.col(k) = A.col(k).mul(sqrt_alpha);
            //
            //  Mat B;
            //  Yhat.copyTo(B);
            //  for (int k = 0; k < B.cols; k++)
            //    B.col(k) = B.col(k).mul(sqrt_alpha);
            //
            //  cv::SVD udv(A.t() * B);
            //
            //  // Calculating the affine transform matrix (Eq. 7).
            //  Mat M = udv.u * udv.vt;
            //
            //  // Projecting X[i] using the matrix M (Eq 8)
            //  Y.row(proj_idx[i]) = (X.row(proj_idx[i]) - Xtil) * M + Ytil;
            //}
            return(Y);
        }
        public static void RecursiveGrowing(System.Drawing.Point seed, Image <Gray, Byte> _img, Image <Gray, Byte> _mask)
        {
            Emgu.CV.Matrix <byte> mat1 = new Emgu.CV.Matrix <Byte>(_img.Height, _img.Width);
            Emgu.CV.Matrix <Byte> mat2 = new Emgu.CV.Matrix <Byte>(_img.Height, _img.Width);
            mat1.SetZero();
            mat2.SetZero();

            //Emgu.CV.Structure.MCvConnectedComp conn = new Emgu.CV.Structure.MCvConnectedComp();


            //CvInvoke.FloodFill(_img, mask, seed, new MCvScalar(128), out rect, new MCvScalar(1), new MCvScalar(1), Emgu.CV.CvEnum.Connectivity.EightConnected);

            //Console.WriteLine("Rectangle {0},{1}", rect.Width, rect.Height);

            //Emgu.CV.Structure.MCvSeq components = new Emgu.CV.Structure.MCvConnectedComp <MCvConnectedComp>(new MemStorage());

            //  Emgu.CV.CvInvoke.cvPyrSegmentation(image, result, storage, out components._ptr, 4, 255, 30);
            //CvInvoke.sh



            // Set the seed
            _mask.Data[seed.X, seed.Y, 0] = 1; // Set to 1

            mat1[seed.X, seed.Y] = 1;
            mat2[seed.X, seed.Y] = 1;


            int iter = 0;

            while (iter < 1)
            {
                // Dilation
                _mask.Dilate(1);

                //System.Drawing.Point[] points = GetNeighbors(System.Drawing.Point loc, System.Drawing.Size size)

                iter++;
            }



            // recurse left
            //_row = _row - 1;
            //if ((_imData[_row, _col].Intensity != 0) && (_imMask[_row, _col].Intensity == 0))
            //{
            //    RecursiveGrowing(_row, _col, _imData, _imMask);
            //}

            // recurse right
            //_row = _row - 1;
            //if ((_img[_row, _col].Intensity != 0) && (_imMask[_row, _col].Intensity == 0))
            //{
            //    RecursiveGrowing(_row, _col, _img, _imMask);
            //}

            //// recurse up
            //_col = _col - 1;
            //_row = _row - 1;
            //if ((_imData[_row, _col].Intensity != 0) && (_imMask[_row, _col].Intensity == 0))
            //{
            //    RecursiveGrowing(_row, _col, _imData, _imMask);
            //}

            // recurse down
            //_col = _col - 1;
            //if ((_img[_row, _col].Intensity != 0) && (_imMask[_row, _col].Intensity == 0))
            //{
            //    RecursiveGrowing(_row, _col, _img, _imMask);
            //}
        }