图像细化时,我想实现当没有需要删除的点时停止循环,但是这段代码一直循环,大家帮我看看是哪出问题了
 public int[,] ThiningPic(int[,] input)         //细化
       {
           int[,] result = new int[input.GetLength(0), input.GetLength(1)];
           int lWidth = input.GetLength(0);
           int lHeight = input.GetLength(1);
           bool bModified;            //脏标记 
           int i, j, n, m;            //循环变量
           //四个条件
           bool bCondition1;
           bool bCondition2;
           bool bCondition3;
           bool bCondition4;
           int nCount;    //计数器    
           int[,] neighbour = new int[5, 5];    //5×5相邻区域像素值
           bModified = true;
           while (bModified)
           {
               /***************************第一次迭代***************************************/
               MessageBox.Show("ok");
               bModified = false;
               //由于使用5×5的结构元素,为防止越界,所以不处理外围的几行和几列像素
               for (j = 2; j < lHeight - 2; j++)
               {
                   for (i = 2; i < lWidth - 2; i++)
                   {                       bCondition1 = false;
                       bCondition2 = false;
                       bCondition3 = false;
                       bCondition4 = false;                       if (input[i, j] == 0)
                       {
                           result[i, j] = 0;
                           continue;
                       }                       //获得当前点相邻的5×5区域内像素值,白色用0代表,黑色用1代表
                       for (m = 0; m < 5; m++)
                       {
                           for (n = 0; n < 5; n++)
                           {
                               if (input[i + m - 2, j + n - 2] == 1)
                                   neighbour[m, n] = 1;
                               else
                                   neighbour[m, n] = 0;
                           }
                       }                       //判断2<=NZ(P1)<=6
                       nCount = neighbour[1, 1] + neighbour[1, 2] + neighbour[1, 3]
                               + neighbour[2, 1] + neighbour[2, 3] +
                               +neighbour[3, 1] + neighbour[3, 2] + neighbour[3, 3];
                       if (nCount >= 2 && nCount <= 6)
                       {
                           bCondition1 = true;
                       }                       //判断Z0(P1)=1
                       nCount = 0;
                       if (neighbour[1, 2] == 0 && neighbour[1, 1] == 1)
                           nCount++;
                       if (neighbour[1, 1] == 0 && neighbour[2, 1] == 1)
                           nCount++;
                       if (neighbour[2, 1] == 0 && neighbour[3, 1] == 1)
                           nCount++;
                       if (neighbour[3, 1] == 0 && neighbour[3, 2] == 1)
                           nCount++;
                       if (neighbour[3, 2] == 0 && neighbour[3, 3] == 1)
                           nCount++;
                       if (neighbour[3, 3] == 0 && neighbour[2, 3] == 1)
                           nCount++;
                       if (neighbour[2, 3] == 0 && neighbour[1, 3] == 1)
                           nCount++;
                       if (neighbour[1, 3] == 0 && neighbour[1, 2] == 1)
                           nCount++;
                       if (nCount == 1)
                           bCondition2 = true;
                       //判断P2*P4*P6=0 
                       if (neighbour[1, 2] * neighbour[2, 3] * neighbour[3, 2] == 0)
                       {
                           bCondition3 = true;
                       }                       // 判断P4*P6*P8=0 
                       if (neighbour[2, 3] * neighbour[3, 2] * neighbour[2, 1] == 0)
                       {
                           bCondition4 = true;
                       }                       if (bCondition1 && bCondition2 && bCondition3 && bCondition4)
                       {
                           bModified = true;
                           result[i, j] = 0;
                       }
                       else
                       {
                           result[i, j] = 1;
                           //MessageBox.Show(i.ToString() + "," + j.ToString());
                       }
                   }
               }
               /*****************************第二次迭代***********************************/
               //由于使用5×5的结构元素,为防止越界,所以不处理外围的几行和几列像素
               for (j = 2; j < lHeight - 2; j++)
               {
                   for (i = 2; i < lWidth - 2; i++)
                   {                       bCondition1 = false;
                       bCondition2 = false;
                       bCondition3 = false;
                       bCondition4 = false;                       if (input[i, j] == 0)
                       {
                           result[i, j] = 0;
                           continue;
                       }
                       //获得当前点相邻的5×5区域内像素值,白色用0代表,黑色用1代表
                       for (m = 0; m < 5; m++)
                       {
                           for (n = 0; n < 5; n++)
                           {
                               if (input[i + m - 2, j + n - 2] == 1)
                                   neighbour[m, n] = 1;
                               else
                                   neighbour[m, n] = 0;
                           }
                       }
                       //判断2<=NZ(P1)<=6
                       nCount = neighbour[1, 1] + neighbour[1, 2] + neighbour[1, 3]
                               + neighbour[2, 1] + neighbour[2, 3] +
                               +neighbour[3, 1] + neighbour[3, 2] + neighbour[3, 3];
                       if (nCount >= 2 && nCount <= 6)
                       {
                           bCondition1 = true;
                       }
                       //判断Z0(P1)=1
                       nCount = 0;
                       if (neighbour[1, 2] == 0 && neighbour[1, 1] == 1)
                           nCount++;
                       if (neighbour[1, 1] == 0 && neighbour[2, 1] == 1)
                           nCount++;
                       if (neighbour[2, 1] == 0 && neighbour[3, 1] == 1)
                           nCount++;
                       if (neighbour[3, 1] == 0 && neighbour[3, 2] == 1)
                           nCount++;
                       if (neighbour[3, 2] == 0 && neighbour[3, 3] == 1)
                           nCount++;
                       if (neighbour[3, 3] == 0 && neighbour[2, 3] == 1)
                           nCount++;
                       if (neighbour[2, 3] == 0 && neighbour[1, 3] == 1)
                           nCount++;
                       if (neighbour[1, 3] == 0 && neighbour[1, 2] == 1)
                           nCount++;
                       if (nCount == 1)
                           bCondition2 = true;
                       //判断P2*P4*P8=0 
                       if (neighbour[1, 2] * neighbour[2, 3] * neighbour[2, 1] == 0)
                       {
                           bCondition3 = true;
                       }
                       // 判断P2*P6*P8=0 
                       if (neighbour[1, 2] * neighbour[3, 2] * neighbour[2, 1] == 0)
                       {
                           bCondition4 = true;
                       }
                       //满足四个条件则将该点置0
                       if (bCondition1 && bCondition2 && bCondition3 && bCondition4)
                       {
                           bModified = true;
                           result[i, j] = 0;
                       }
                       else
                       {
                           result[i, j] = 1;
                       }
                   }
               }           }
           return result;
       }