public void InitGVF() { NcvMatrix f = new NcvMatrix(m_Cols, m_Rows); u = new NcvMatrix(m_Cols, m_Rows); v = new NcvMatrix(m_Cols, m_Rows); Console.WriteLine(" Compute edge map ..."); for (int y = 0; y < m_Rows; y++) { for (int x = 0; x < m_Cols; x++) { f[x, y] = 1 - mat[x][y] / 255.0; } } //Logger.Info("f=" + f.ToString()); Console.WriteLine(" Compute GVF ..."); GvfSnakeUtility.GVFC(m_Rows, m_Cols, f, ref u, ref v, 0.2, 80); //Logger.Info("u=" + u.ToString()); //Logger.Info("v=" + v.ToString()); Console.WriteLine(" Nomalizing the GVF external force ..."); px = new double[m_Cols * m_Rows]; py = new double[m_Cols * m_Rows]; mag = new NcvMatrix(m_Cols, m_Rows); for (int y = 0; y < m_Rows; y++) { for (int x = 0; x < m_Cols; x++) { int i = x * m_Rows + y; mag[x, y] = System.Math.Sqrt(u[x, y] * u[x, y] + v[x, y] * v[x, y]); px[i] = u[x, y] / (mag[x, y] + 1e-10); py[i] = v[x, y] / (mag[x, y] + 1e-10); } } //Logger.Info("px=" + px.ToString()); //Logger.Info("px=" + px.ToString()); }
/// <summary> /// 初始化梯度向量场 (Gradient Vector Field) /// </summary> public void InitGVF() { //mat = GrayScaleProcessor.Gaussian(mat, 2.5); //Convolution conv = new Convolution(); //conv.CalculateEdge(mat, ConvKernel.Sobel_Gx, ConvKernel.Sobel_Gy, out grad_mag, ConvNorm.Norm_2); double[] f = new double[m_Cols * m_Rows]; u = new double[m_Cols * m_Rows]; v = new double[m_Cols * m_Rows]; Console.WriteLine(" Compute edge map ..."); for (int y = 0; y < m_Rows; y++) { for (int x = 0; x < m_Cols; x++) { int i = x * m_Rows + y; f[i] = 1 - (double)mat[x][y] / 255; } } Console.WriteLine(" Compute GVF ..."); GvfSnakeUtility.GVFC(m_Rows, m_Cols, f, ref u, ref v, 0.2, 80); Console.WriteLine(" Nomalizing the GVF external force ..."); px = new double[m_Cols * m_Rows]; py = new double[m_Cols * m_Rows]; mag = new double[m_Cols * m_Rows]; for (int y = 0; y < m_Rows; y++) { for (int x = 0; x < m_Cols; x++) { int i = x * m_Rows + y; mag[i] = System.Math.Sqrt(u[i] * u[i] + v[i] * v[i]); px[i] = u[i] / (mag[i] + 1e-10); py[i] = v[i] / (mag[i] + 1e-10); } } }