Main Page   Data Structures   File List   Data Fields   Globals  

maxgraddir.c

Go to the documentation of this file.
00001 #include "sadie.h"
00002 #include "proto.h"
00003 
00004 /*----------------------------------------------------------------------------*/
00005 /*-General Information--------------------------------------------------------*/
00006 /*                                                                            */
00007 /*   This procedure takes as input a gradient magnitude and a gradient        */
00008 /*   direction image.  Gradient directions are quantized into eight discrete  */
00009 /*   directions, and the average gradient magnitude of each sector is         */
00010 /*   computed on a pixel-by-pixel basis.  The sector with the highest         */
00011 /*   gradient magnitude generally corresponds to the orientation of tree      */
00012 /*   rings in the image.  See W. S. Conner's thesis for more information on   */
00013 /*   determining the average orientation of tree rings within a region of     */
00014 /*   interest.                                                                */
00015 /*                                                                            */
00016 /*          337.5 -  22.5 degrees   --      Sector 1                          */
00017 /*          22.5  -  67.5 degrees   --      Sector 2                          */
00018 /*          67.5  - 112.5 degrees   --      Sector 3                          */
00019 /*          112.5 - 157.5 degrees   --      Sector 4                          */
00020 /*          157.5 - 202.5 degrees   --      Sector 5                          */
00021 /*          202.5 - 247.5 degrees   --      Sector 6                          */
00022 /*          247.5 - 292.5 degrees   --      Sector 7                          */
00023 /*          292.5 - 337.5 degrees   --      Sector 8                          */
00024 /*                                                                            */
00025 /*----------------------------------------------------------------------------*/
00026 /*-Interface Information------------------------------------------------------*/
00027 void MAXGRADDIR (
00028 IMAGE  *mag,    /*  I   Pointer to the input gradient magnitude image.        */
00029 IMAGE  *dir    /*  I   Pointer to the input gradient direction image.         */
00030 /*----------------------------------------------------------------------------*/
00031 ) { register short i, j, k;
00032     char msg[SLEN];
00033     double theta;
00034     int sectornum;
00035     int count[8];
00036     PIXEL value[8];
00037 
00038     /* if (TIMES) TIMING(T_SECTOR); */
00039     if (NAMES) {
00040         MESSAGE('I',"");
00041         MESSAGE('I',"MAXGRADDIR");
00042         MESSAGE('I',"");
00043         sprintf(msg," Input mag:                       %s",mag->text);
00044         MESSAGE('I',msg);
00045         sprintf(msg," Input dir:                       %s",dir->text);
00046         MESSAGE('I',msg);
00047         MESSAGE('I'," ...............");
00048     }
00049 
00050     /* check input */
00051     if (!CHECKIMG(mag)) {
00052         MESSAGE('E'," Can't identify image.");
00053         goto the_end;
00054     }
00055     if (!CHECKIMG(dir)) {
00056         MESSAGE('E'," Can't identify image.");
00057         goto the_end;
00058     }
00059     if (dir->nbnd != mag->nbnd  ||  dir->nlin != mag->nlin  ||  dir->npix != mag->npix) {
00060         MESSAGE('E'," Input images must be the same size.");
00061         goto the_end;
00062     }
00063     
00064     /* Find the min and max values in the dir image */
00065     RANGE(dir);
00066     
00067     /* Verify that this is a gradient direction image */
00068     if (dir->gmin < -2.0*PI  ||  2.0*PI < dir->gmax) {
00069         MESSAGE('E'," This is not a gradient direction image!");
00070         MESSAGE('E'," Direction must be between -360 and +360 degrees.");
00071         goto the_end;
00072     }
00073 
00074     for (i=0; i<8; i++) {
00075         count[i]  = 0;
00076         value[i]  = (PIXEL)0.0;
00077     }
00078 
00079     for (i=0; i<dir->nbnd; i++) {
00080         for (j=0; j<dir->nlin; j++) {
00081             for (k=0; k<dir->npix; k++) {
00082                 theta = (double)(dir->data[i][j][k]);
00083                 
00084                 /* Convert to positive angle */
00085                 if (theta < 0.0) {
00086                     theta = (2.0*PI) + theta;
00087                 }
00088                 
00089                 if ((theta < (PI / 8.0))  &&  (0 <= theta)) {
00090                     sectornum = 0;
00091                 } else if ((theta <= (2*PI))  &&  (((15.0*PI)/8.0) <= theta)) {
00092                     sectornum = 0;
00093                 } else if ((theta < ((3.0*PI)/8.0))  &&  ((PI/8.0) <= theta)) {
00094                     sectornum = 1;
00095                 } else if ((theta < ((5.0*PI)/8.0))  &&  (((3.0*PI)/8.0) <= theta)) {
00096                     sectornum = 2;
00097                 } else if ((theta < ((7.0*PI)/8.0))  &&  (((5.0*PI)/8.0) <= theta)) {
00098                     sectornum = 3;
00099                 } else if ((theta < ((9.0*PI)/8.0))  &&  (((7.0*PI)/8.0) <= theta)) {
00100                     sectornum = 4;
00101                 } else if ((theta < ((11.0*PI)/8.0))  &&  (((9.0*PI)/8.0) <= theta)) {
00102                     sectornum = 5;
00103                 } else if ((theta < ((13.0*PI)/8.0))  &&  (((11.0*PI)/8.0) <= theta)) {
00104                     sectornum = 6;
00105                 } else {  /* if (theta < ((15.0*PI)/8.0)  &&  ((13.0*PI)/8.0) <= theta) */
00106                     sectornum = 7;
00107                 }
00108             
00109                 count[sectornum] += 1;
00110                 value[sectornum] += mag->data[i][j][k];
00111             }
00112         }
00113     }
00114 
00115     for (i=0; i<8; i++) {
00116         if (count[i] <= 0) {
00117             printf("Direction %d %5.4f\n",i+1,0.0);
00118         } else {
00119             printf("Direction %d %5.4f\n",i+1,value[i]/(PIXEL)count[i]);
00120         }
00121     }
00122 
00123         
00124     the_end:
00125     /* if (TIMES) TIMING(T_EXIT); */
00126 }

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