/// <summary> /// foamliu, 2009/02/04, 腐蚀. /// /// </summary> /// <param name="mat">二值图像</param> /// <param name="b">结构元素</param> public static void Erosion(int[][] mat, StructuringElement strel, out int[][] output) { //int width = mat.Length; //int height = mat[0].Length; //output = new int[width][]; //for (int i = 0; i < width; i++) //{ // output[i] = new int[height]; //} //int m = b.Width; //int n = b.height; //for (int y = 0; y < height; y++) //{ // for (int x = 0; x < width; x++) // { // if (mat[x][y] != 1) // continue; // for (int j = -n; j <= n; j++) // { // for (int i = -m; i <= m; i++) // { // if (b.B(i, j) == 0) // continue; // if (Util.GetPixel(mat,x + i,y + j) == 0) // goto next; // } // } // output[x][y] = 1; // next: ; // } //} // foamliu, 2009/02/06, 改用二值图像库中的算法. // // 先把 strel 求转置 // StructuringElement trans = StructuringElement.Transposition(strel); BinaryImageLib.MinkowskiSubtraction(mat, trans, out output); }
/// <summary> /// foamliu, 2009/02/04, 灰度值腐蚀. /// /// </summary> /// <param name="mat">灰度图像</param> /// <param name="b">结构元素</param> public static void Erosion(int[][] mat, StructuringElement strel, out int[][] output) { //int width = mat.Length; //int height = mat[0].Length; //output = new int[width][]; //for (int i = 0; i < width; i++) //{ // output[i] = new int[height]; //} //int m = b.Length; //int n = b[0].Length; //for (int y = 0; y < height; y++) //{ // for (int x = 0; x < width; x++) // { // int min = int.MaxValue; // for (int j = 0; j < n; j++) // { // for (int i = 0; i < m; i++) // { // int matxy = Util.GetPixel(mat, x - i, y - j); // if (matxy + b[i][j] < min) // { // min = matxy + b[i][j]; // } // } // } // output[x][y] = min; // } //} // foamliu, 2009/02/06, 改用二值图像库中的算法. // // 先把 strel 求转置 // StructuringElement trans = StructuringElement.Transposition(strel); GrayScaleImageLib.MinkowskiSubtraction(mat, trans, out output); }