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

📄 embsubs.c

📁 This is code tutorial for image processing include:histogram,sketon....
💻 C
📖 第 1 页 / 共 2 页
字号:


       /***********************************************
       *
       *       file c:\cips\embsubs.c
       *
       *       Functions: This file contains
       *          detect_edges
       *          setup_masks
       *          get_edge_options
       *          perform_convolution
       *          quick_edge
       *          fix_edges
       *
       *       Purpose:
       *          These functions implement several
       *          types of basic edge detection.
       *
       *       External Calls:
       *          wtiff.c - round_off_image_size
       *                    create_file_if_needed
       *                    write_array_into_tiff_image
       *          tiff.c - read_tiff_header
       *          rtiff.c - read_tiff_image
       *          numcvrt.c - get_integer
       *
       *
       *       Modifications:
       *          3 April 1994 - created
       *
       *************************************************/

#include "cips.h"






short emboss_0_mask[3][3] =  {
       {-1,  0,  1},
       {-1,  1,  1},
       {-1,  0,  1} };

short emboss_1_mask[3][3] =  {
       { 0,  1,  1},
       {-1,  1,  1},
       {-1, -1,  0} };

short emboss_2_mask[3][3] =  {
       { 1,  1,  1},
       { 0,  1,  0},
       { 1,  1, -1} };

short emboss_3_mask[3][3] =  {
       { 1,  1,  0},
       { 1,  1, -1},
       { 0, -1, -1} };

short emboss_4_mask[3][3] =  {
       { 1,  0, -1},
       { 1,  1, -1},
       { 1,  0, -1} };

short emboss_5_mask[3][3] =  {
       { 0, -1, -1},
       { 1,  1, -1},
       { 1,  1,  0} };

short emboss_6_mask[3][3] =  {
       {-1, -1, -1},
       { 0,  1,  0},
       { 1,  1,  1} };

short emboss_7_mask[3][3] =  {
       {-1, -1,  0},
       {-1,  1,  1},
       { 0,  1,  1} };



   /***************************
   *
   *   Directions for the masks
   *  3 2 1
   *  4 x 0
   *  5 6 7
   *
   ****************************/



  /**************************************************
  *
  *   emboss_array(...
  *
  *   This function detects edges in an area of one
  *   image and sends the result to another image
  *   on disk.  It reads the input image from disk,
  *   calls a convolution function, and then writes
  *   the result out to disk.  If needed, it
  *   allocates space on disk for the output image.
  *
  ***************************************************/



emboss_array(in_name, out_name, the_image, out_image,
             il, ie, ll, le, threshold,
             high, zero, one, two, three, four,
             five, six, seven)
   char   in_name[], out_name[];
   int    high, il, ie,
          ll, le, threshold;
   int    zero, one, two, three, four, five,
          six, seven;
   short  the_image[ROWS][COLS], out_image[ROWS][COLS];

{
   int    i, j, k, length, width;
   struct tiff_header_struct image_header;


   create_file_if_needed(in_name, out_name, out_image);

   read_tiff_image(in_name, the_image, il, ie, ll, le);

   read_tiff_header(in_name, &image_header);

   emboss_convolution(the_image, out_image,
                      threshold,
                      &image_header, high,
                      zero, one, two, three,
                      four, five, six, seven);

   fix_edges(out_image, 1);

   write_array_into_tiff_image(out_name, out_image,
                               il, ie, ll, le);
}  /* ends emboss_array */







     /**********************************************************
     *
     *   emoboss_convolution(...
     *
     *   This function performs convolution between the input
     *   image and 8 3x3 masks.  The result is placed in
     *   the out_image.
     *
     ********************************************************/

emboss_convolution(image, out_image,
                   threshold, high,
                   zero, one, two, three, four,
                   five, six, seven,
                   rows, cols, bitsperpixel)
   short **image,
         **out_image;
   int   high, threshold;
   int    zero, one, two, three, four, five,
          six, seven;
   long   rows, cols, bitsperpixel;
{

   int a, b, i, is_present, j, sum;

   short  max,
          min,
          new_hi,
          new_low;

   new_hi  = 250;
   new_low = 16;
   if(bitsperpixel == 4){
       new_hi  = 10;
       new_low = 3;
   }

   min = 0;
   max = 255;
   if(bitsperpixel == 4)
      max = 16;

     /* clear output image array */
   for(i=0; i<rows; i++)
      for(j=0; j<cols; j++)
         out_image[i][j] = 0;

   printf("\n ");

   for(i=1; i<rows-1; i++){
      if( (i%10) == 0) printf("%3d", i);
      for(j=1; j<cols-1; j++){


         /******************************
         *
         *  Look at all 8 directions 
         *  convolve only if the 
         *  direction is set
         *
         ******************************/

         /* 0 direction */
      if(zero){
         sum = 0;
         for(a=-1; a<2; a++){
            for(b=-1; b<2; b++){
               sum = sum + image[i+a][j+b] *
                     emboss_0_mask[a+1][b+1];
            }
         }
            if(sum > max) sum = max;
            if(sum < 0)   sum = 0;
         if(sum > out_image[i][j])
            out_image[i][j]   = sum;
      }  /* ends if zero */


         /* 1 direction */
      if(one){
         sum = 0;
         for(a=-1; a<2; a++){
            for(b=-1; b<2; b++){
               sum = sum + image[i+a][j+b] * 
                     emboss_1_mask[a+1][b+1];
            }
         }
            if(sum > max) sum = max;
            if(sum < 0)   sum = 0;
         if(sum > out_image[i][j])
            out_image[i][j]   = sum;
      }  /* ends if one */


         /* 2 direction */
      if(two){
         sum = 0;
         for(a=-1; a<2; a++){
            for(b=-1; b<2; b++){
               sum = sum + image[i+a][j+b] * 
                     emboss_2_mask[a+1][b+1];
            }
         }
            if(sum > max) sum = max;
            if(sum < 0)   sum = 0;
         if(sum > out_image[i][j])
            out_image[i][j]   = sum;
      }  /* ends if two */


         /* 3 direction */
      if(three){
         sum = 0;
         for(a=-1; a<2; a++){
            for(b=-1; b<2; b++){
               sum = sum + image[i+a][j+b] * 
                     emboss_3_mask[a+1][b+1];
            }
         }
            if(sum > max) sum = max;
            if(sum < 0)   sum = 0;
         if(sum > out_image[i][j])
            out_image[i][j]   = sum;
      }  /* ends if three */


         /* 4 direction */
      if(four){
         sum = 0;
         for(a=-1; a<2; a++){
            for(b=-1; b<2; b++){
               sum = sum + image[i+a][j+b] * 
                     emboss_4_mask[a+1][b+1];
            }
         }
            if(sum > max) sum = max;
            if(sum < 0)   sum = 0;
         if(sum > out_image[i][j])
            out_image[i][j]   = sum;
      }  /* ends if four */


         /* 5 direction */
      if(five){
         sum = 0;
         for(a=-1; a<2; a++){
            for(b=-1; b<2; b++){
               sum = sum + image[i+a][j+b] * 
                     emboss_5_mask[a+1][b+1];
            }
         }
            if(sum > max) sum = max;
            if(sum < 0)   sum = 0;
            /* Correction 12-27-92
               see file header for

⌨️ 快捷键说明

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