Listing 5 erode_image_array — the erosion subroutine

    /*******************************************
    *
    *   erode_image_array (..
    *
    *   This function erodes pixels. If a pixel
    *   equals value and has more than threshold
    *   neighbors equal to 0, then set that
    *   pixel in the output to 0.
    *
    *******************************************/

erode_image_array(the_image, out_image, value, threshold)
   short the_image[ROWS][COLS], out_image[ROWS][COLS],
   threshold, value;
{
   int   a, b, count, i, j, k,
        length, width;

     /***************************
     *
     *   Loop over image array
     *
     ****************************/

   for(i=0; i<ROWS; i++)
      for(j=0; j<COLS; j++)
         out_image[i][j] = the_image[i][j];

   printf("\n");

   for(i=1; i<ROWS-1; i++){
      if( (i%10) == 0) printf("%3d", i);
      for(j=1; j<COLS-1; j++){
         if(the_image[i][j] == value){
            count = 0;
            for(a=-1; a<=1; a++){
               for(b=-1; b<=1; b++){
                    if(the_image[i+a][j+b] == 0)
                       count++;
               }  /* ends loop over b */
            }  /* ends loop over a */
            if(count > threshold) out_image[i][j] = 0;
         }  /* ends if the_image == value */
      }  /* ends loop over j */
   }  /* ends loop over i */

)  /* ends erode_image_array */

/* End of File */