Main Page   Data Structures   File List   Data Fields   Globals  

edge.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 static PIXEL maskv[][3][3] =
00004   { {{1.0, 2.0, 1.0}, {0.0, 0.0, 0.0}, {-1.0, -2.0, -1.0}},
00005 {{1.0, 1.0, 1.0}, {0.0, 0.0, 0.0}, {-1.0, -1.0, -1.0}},
00006 {{1.0, 1.0, 1.0}, {-1.0, -1.0, -1.0}, {0.0, 0.0, 0.0}},
00007 {{0.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, -1.0}},
00008 {{0.0, 1.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, 0.0}},
00009 {{1.0, 1.0, 1.0}, {1.0, -2.0, 1.0}, {-1.0, -1.0, -1.0}}
00010 };
00011 static PIXEL maskh[][3][3] =
00012   { {{-1.0, 0.0, 1.0}, {-2.0, 0.0, 2.0}, {-1.0, 0.0, 1.0}},
00013 {{-1.0, 0.0, 1.0}, {-1.0, 0.0, 1.0}, {-1.0, 0.0, 1.0}},
00014 {{0.0, -1.0, 1.0}, {0.0, -1.0, 1.0}, {0.0, -1.0, 1.0}},
00015 {{0.0, 0.0, 0.0}, {0.0, 0.0, 1.0}, {0.0, -1.0, 0.0}},
00016 {{0.0, 0.0, 0.0}, {0.0, -1.0, 1.0}, {0.0, 0.0, 0.0}},
00017 {{-1.0, 1.0, 1.0}, {-1.0, -2.0, 1.0}, {-1.0, 1.0, 1.0}}
00018 };
00019 
00020 /*-Copyright Information------------------------------------------------------*/
00021 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00022 /*----------------------------------------------------------------------------*/
00023 /*-General Information--------------------------------------------------------*/
00024 /*                                                                            */
00025 /*   This function computes a two-dimensional gradient (magnitude and         */
00026 /*   direction) of an image, using standard operators.                        */
00027 /*                                                                            */
00028 /*----------------------------------------------------------------------------*/
00029 /*-Background Information-----------------------------------------------------*/
00030 /*                                                                            */
00031 /*   Robinson, G.S.:                                                          */
00032 /*   "Detection and Coding of Edges Using Directional Masks."                 */
00033 /*   Optical Engineering, Vol. 16, No. 6 (Nov/Dec 1977), pp. 590-585          */
00034 /*                                                                            */
00035 /*----------------------------------------------------------------------------*/
00036 /*-Interface Information------------------------------------------------------*/
00037 void
00038 EDGE (IMAGE * in,               /*  I   Pointer to the input image.                           */
00039       short option,             /*  I   Switch, indicating the gradient operator:             */
00040       /*      SOBEL                                                 */
00041       /*      NLEV1                                                 */
00042       /*      NLEV3                                                 */
00043       /*      ROBERTS1                                              */
00044       /*      ROBERTS3                                              */
00045       /*      PREWITT                                               */
00046       IMAGE ** out1,            /*  O   Address of a pointer to the output image              */
00047       /*      containing the gradient magnitude.                    */
00048       IMAGE ** out2             /*  O   Address of a pointer to the output image              */
00049       /*      containing the gradient direction.                    */
00050 /*----------------------------------------------------------------------------*/
00051   )
00052 {
00053   char msg[SLEN];
00054 
00055   if (TIMES)
00056     TIMING (T_EDGE);
00057   if (NAMES)
00058     {
00059       MESSAGE ('I', "");
00060       MESSAGE ('I', "EDGE");
00061       MESSAGE ('I', "");
00062       sprintf (msg, " Input image:   %s", in->text);
00063       MESSAGE ('I', msg);
00064       if (option == SOBEL)
00065         {
00066           MESSAGE ('I', " SOBEL gradient operator");
00067         }
00068       else if (option == SOBEL2)
00069         {
00070           MESSAGE ('I', " SOBEL2 gradient operator");
00071         }
00072       else if (option == SOBEL3)
00073         {
00074           MESSAGE ('I', " SOBEL3 gradient operator");
00075         }
00076       else if (option == ROBERTS)
00077         {
00078           MESSAGE ('I', " ROBERTS gradient operator");
00079         }
00080       else if (option == ROBERTS2)
00081         {
00082           MESSAGE ('I', " ROBERTS2 gradient operator");
00083         }
00084       else if (option == PREWITT)
00085         {
00086           MESSAGE ('I', " PREWITT gradient operator");
00087         }
00088       MESSAGE ('I', " ...............");
00089     }
00090 
00091   /* check input */
00092   if (!CHECKIMG (in))
00093     {
00094       MESSAGE ('E', " Can't identify image.");
00095       goto the_end;
00096     }
00097   else if (option != SOBEL && option != SOBEL2 && option != SOBEL3
00098            && option != ROBERTS && option != ROBERTS2 && option != PREWITT)
00099     {
00100       MESSAGE ('E',
00101                " Option must be one of SOBEL, SOBEL2, SOBEL3, ROBERTS, ROBERTS2, or PREWITT.");
00102       goto the_end;
00103     }
00104 
00105   /* compute 2D-gradient of the image */
00106   GRADIENT (in, (PIXEL *) maskv[option], (PIXEL *) maskh[option], 3, out1,
00107             out2);
00108 
00109 the_end:
00110   if (TIMES)
00111     TIMING (T_EXIT);
00112 }

Generated on Sun May 18 15:36:09 2003 for tclSadie by doxygen1.3