// foamliu, 2009/02/04, 开操作.
 //
 public static int[][] Open(int[][] mat, StructuringElement strel)
 {
     int[][] temp, output;
     Erosion(mat, strel, out temp);
     BinaryImageLib.MinkowskiAddtion(temp, strel, out output);
     return(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.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/05, 抽取骨骼.
        ///
        /// 主要参照:
        ///
        ///     佳奇发给我 Morphological Image Process 幻灯中倒数第三页: Skeleton Equations.
        ///
        /// </summary>
        public static void ExtractSkeleton(int[][] mat, StructuringElement strel, out int[][] output)
        {
            int width  = mat.Length;
            int height = mat[0].Length;

            int[][] temp = (int[][])mat.Clone();
            int     K    = CalcK(mat, strel);

            int[][] Sk;
            output = Util.BuildMatInt(width, height);

            for (int k = 1; k <= K; k++)
            {
                temp = BinaryImageLib.MinkowskiSubtraction(temp, strel);
                Sk   = BinaryImageLib.Difference(temp, BinaryImageLib.Open(temp, strel));
                BinaryImageLib.Union(output, Sk);
            }
        }
        // 计算 Skeleton Equations 中的 K.
        //
        private static int CalcK(int[][] mat, StructuringElement strel)
        {
            int[][] temp = (int[][])mat.Clone();
            int     k    = 0;

            while (true)
            {
                temp = BinaryImageLib.MinkowskiSubtraction(temp, strel);
                if (BinaryImageLib.Empty(temp))
                {
                    break;
                }
                else
                {
                    k++;
                }
            }

            return(k);
        }
 /// <summary>
 /// foamliu, 2009/02/04, 闭操作.
 /// 先执行一个膨胀操作后紧接着再用同一个结构元进行闵可夫斯基减法.
 ///
 /// </summary>
 /// <param name="mat"></param>
 /// <param name="b"></param>
 /// <param name="output"></param>
 public static void Close(int[][] mat, StructuringElement strel, out int[][] output)
 {
     int[][] temp;
     Dilation(mat, strel, out temp);
     BinaryImageLib.MinkowskiSubtraction(temp, strel, out output);
 }
 /// <summary>
 /// foamliu, 2009/02/04, 开操作.
 /// 先进行腐蚀操作再紧接着进行一个使用同样结构元的闵可夫斯基加法.
 ///
 /// </summary>
 /// <param name="mat"></param>
 /// <param name="b"></param>
 /// <param name="output"></param>
 public static void Open(int[][] mat, StructuringElement strel, out int[][] output)
 {
     int[][] temp;
     Erosion(mat, strel, out temp);
     BinaryImageLib.MinkowskiAddtion(mat, strel, out output);
 }