⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ed.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 2 页
字号:
         out_image[i][j] = min;
      }  /* ends loop over j */
   }  /* ends loop over i */

   /*****
   fix_edges(out_image, 3, rows, cols);
   ***/

}  /* ends mask_erosion */



     /***********************************************
     *
     *   copy_3_x_3(a, b)
     *
     *   This function copies a 3x3 array of shorts
     *   from one array to another.  It copies array
     *   b into array a.
     *
     ***********************************************/

copy_3_x_3(a, b)
   short a[3][3], b[3][3];
{
   int i, j;
   for(i=0; i<3; i++)
      for(j=0; j<3; j++)
         a[i][j] = b[i][j];
}  /* ends copy_3_x_3 */




     /*******************************************
     *
     *   opening(...
     *
     *   Opening is erosion followed by dilation.
     *   This routine will use the mask erosion
     *   and dilation.  You could use the other
     *   types and you could mix the two types.
     *
     *   The number parameter specifies how
     *   erosions to perform before doing one
     *   dilation.
     *
     *******************************************/

opening(the_image, out_image,
        value, mask_type, number,
        rows, cols)
   int    number;
   int    mask_type;
   short  **the_image,
          **out_image,
          value;
   long   cols, rows;
{
   int    a, b, count, i, j, k;
   short  mask[3][3], max;

      /**************************************
      *
      *   Copy the 3x3 erosion-dilation mask
      *   specified by the mask_type.
      *
      ***************************************/

   switch(mask_type){
      case 1:
         copy_3_x_3(mask, edmask1);
         break;
      case 2:
         copy_3_x_3(mask, edmask2);
         break;
      case 3:
         copy_3_x_3(mask, edmask3);
         break;
      case 4:
         copy_3_x_3(mask, edmask4);
         break;
      default:
         printf("\nInvalid mask type, using mask 4");
         copy_3_x_3(mask, edmask4);
         break;
   }

   for(i=0; i<rows; i++)
      for(j=0; j<cols; j++)
         out_image[i][j] = the_image[i][j];

   mask_erosion(the_image, out_image, 
                value, mask_type,
                rows, cols);

   if(number > 1){
      count = 1;
      while(count < number){
         count++;
         mask_erosion(the_image, out_image, 
                      value, mask_type,
                      rows, cols);
      }  /* ends while */
   }  /* ends if number > 1 */

   mask_dilation(the_image,
                 out_image, 
                 value, mask_type,
                 rows, cols);

}  /* ends opening */





     /*******************************************
     *
     *   closing(...
     *
     *   Closing is dilation followed by erosion.
     *   This routine will use the mask erosion
     *   and dilation.  You could use the other
     *   types and you could mix the two types.
     *
     *   The number parameter specifies how
     *   dilations to perform before doing one
     *   erosion.
     *
     *******************************************/

closing(the_image, out_image,
        value, mask_type, number,
        rows, cols)
   int    number;
   int    mask_type;
   short  **the_image,
          **out_image,
          value;
   long   cols, rows;
{
   int    a, b, count, i, j, k;
   short  mask[3][3], max;
printf("\nCLOSING> value=%d mask=%d number=%d",value,mask_type,number);

      /**************************************
      *
      *   Copy the 3x3 erosion-dilation mask
      *   specified by the mask_type.
      *
      ***************************************/

   switch(mask_type){
      case 1:
         copy_3_x_3(mask, edmask1);
         break;
      case 2:
         copy_3_x_3(mask, edmask2);
         break;
      case 3:
         copy_3_x_3(mask, edmask3);
         break;
      case 4:
         copy_3_x_3(mask, edmask4);
         break;
      default:
         printf("\nInvalid mask type, using mask 4");
         copy_3_x_3(mask, edmask4);
         break;
   }

   for(i=0; i<rows; i++)
      for(j=0; j<cols; j++)
         out_image[i][j] = the_image[i][j];

   mask_dilation(the_image, out_image, 
                 value, mask_type,
                 rows, cols);

   if(number > 1){
      count = 1;
      while(count < number){
         count++;
         mask_dilation(the_image, out_image, 
                        value, mask_type,
                        rows, cols);
      }  /* ends while */
   }  /* ends if number > 1 */

   mask_erosion(the_image, out_image, 
                value, mask_type,
                rows, cols);

}  /* ends closing */




     /*******************************************
     *
     *   interior_outline(...
     *
     *   This function produces the outline of
     *   any "holes" inside an object.  The
     *   method is:
     *      output = erosion of input
     *      final output = input - output
     *
     *******************************************/

interior_outline(the_image, out_image, 
                 value, mask_type,
                 rows, cols)
   int    mask_type;
   short  **the_image,
          **out_image,
          value;
   long   cols, rows;
{
   int    a, b, count, i, j, k;
   short  mask[3][3], max;

      /**************************************
      *
      *   Copy the 3x3 erosion-dilation mask
      *   specified by the mask_type.
      *
      ***************************************/

   switch(mask_type){
      case 1:
         copy_3_x_3(mask, edmask1);
         break;
      case 2:
         copy_3_x_3(mask, edmask2);
         break;
      case 3:
         copy_3_x_3(mask, edmask3);
         break;
      case 4:
         copy_3_x_3(mask, edmask4);
         break;
      default:
         printf("\nInvalid mask type, using mask 4");
         copy_3_x_3(mask, edmask4);
         break;
   }

   mask_erosion(the_image,
                out_image, 
                value, mask_type,
                rows, cols);

   for(i=0; i<rows; i++)
      for(j=0; j<cols; j++)
         the_image[i][j] =
            the_image[i][j] - out_image[i][j];
   
   for(i=0; i<rows; i++)
      for(j=0; j<cols; j++)
         out_image[i][j] = the_image[i][j];

}  /* ends interior_outline */





     /*******************************************
     *
     *   exterior_outline(...
     *
     *   This function produces the outline of
     *   exterior of an object.  The
     *   method is:
     *      output = dilation of input
     *      final output = output - input
     *
     *******************************************/


exterior_outline(the_image, out_image,
                 value, mask_type,
                 rows, cols)
   int    mask_type;
   short  **the_image,
          **out_image,
          value;
   long   cols, rows;
{
   int    a, b, count, i, j, k;
   short  mask[3][3], max;

      /**************************************
      *
      *   Copy the 3x3 erosion-dilation mask
      *   specified by the mask_type.
      *
      ***************************************/

   switch(mask_type){
      case 1:
         copy_3_x_3(mask, edmask1);
         break;
      case 2:
         copy_3_x_3(mask, edmask2);
         break;
      case 3:
         copy_3_x_3(mask, edmask3);
         break;
      case 4:
         copy_3_x_3(mask, edmask4);
         break;
      default:
         printf("\nInvalid mask type, using mask 4");
         copy_3_x_3(mask, edmask4);
         break;
   }

   mask_dilation(the_image, out_image, 
                 value, mask_type,
                 rows, cols);

   for(i=0; i<rows; i++)
      for(j=0; j<cols; j++)
         the_image[i][j] =
            out_image[i][j] - the_image[i][j];
   
   for(i=0; i<rows; i++)
      for(j=0; j<cols; j++)
         out_image[i][j] = the_image[i][j];

}  /* ends exterior_outline */




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -