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

Generated on Wed Apr 9 08:56:05 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002