Main Page   Data Structures   File List   Data Fields   Globals  

sector8.c

Go to the documentation of this file.
00001 #include "sadie.h"
00002 #include "proto.h"
00003 
00004 /*----------------------------------------------------------------------------*/
00005 /*-General Information--------------------------------------------------------*/
00006 /*                                                                            */
00007 /*   This function calculates the sector of an angle as shown:                */
00008 /*                                                                            */
00009 /*          0     -  22.5 degrees   --      Sector 0                          */
00010 /*          22.5  -  45.0 degrees   --      Sector 1                          */
00011 /*          45.0  -  67.5 degrees   --      Sector 2                          */
00012 /*          67.5  -  90.0 degrees   --      Sector 3                          */
00013 /*          90.0  - 112.5 degrees   --      Sector 4                          */
00014 /*          112.5 - 135.0 degrees   --      Sector 5                          */
00015 /*          135.0 - 157.5 degrees   --      Sector 6                          */
00016 /*          157.5 - 180.0 degrees   --      Sector 7                          */
00017 /*          180.0 - 202.5 degrees   --      Sector 0                          */
00018 /*          202.5 - 225.0 degrees   --      Sector 1                          */
00019 /*          225.0 - 247.5 degrees   --      Sector 2                          */
00020 /*          247.5 - 270.0 degrees   --      Sector 3                          */
00021 /*          270.0 - 292.5 degrees   --      Sector 4                          */
00022 /*          292.5 - 315.0 degrees   --      Sector 5                          */
00023 /*          315.0 - 337.5 degrees   --      Sector 6                          */
00024 /*          337.5 - 360.0 degrees   --      Sector 7                          */
00025 /*                                                                            */
00026 /*                                                                            */
00027 /*----------------------------------------------------------------------------*/
00028 /*-Interface Information------------------------------------------------------*/
00029 void SECTOR8 (
00030 IMAGE  *in,     /*  I   Pointer to the input image.                           */
00031 IMAGE  **out    /*  O   Address of a pointer to the output image.             */
00032 /*----------------------------------------------------------------------------*/
00033 ) { register short i, j, k;
00034     char msg[SLEN];
00035     double theta;
00036     int sectornum;
00037 
00038     /* if (TIMES) TIMING(T_SECTOR8); */
00039     if (NAMES) {
00040         MESSAGE('I',"");
00041         MESSAGE('I',"SECTOR8");
00042         MESSAGE('I',"");
00043         sprintf(msg," Input image:                       %s",in->text);
00044         MESSAGE('I',msg);
00045         MESSAGE('I'," ...............");
00046     }
00047 
00048     /* check input */
00049     if (!CHECKIMG(in)) {
00050         MESSAGE('E'," Can't identify image.");
00051         goto the_end;
00052     }
00053     
00054     /* Find the min and max values in the image */
00055     RANGE(in);
00056     
00057     /* Verify that this is a gradient direction image */
00058     if (in->gmin < -2.0*PI  ||  2.0*PI < in->gmax) {
00059         MESSAGE('E'," This is not a gradient direction image!");
00060         MESSAGE('E'," Direction must be between -360 and +360 degrees.");
00061         goto the_end;
00062     }
00063 
00064     /* create image of appropriate size */
00065     if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00066     if (!*out) goto the_end;
00067 
00068 
00069 
00070     /* build sector image */
00071     for (i=0; i<in->nbnd; i++) {
00072         for (j=0; j<in->nlin; j++) {
00073             for (k=0; k<in->npix; k++) {
00074                 theta = (double)(in->data[i][j][k]);
00075                 
00076                 /* Convert to positive angle */
00077                 if (theta < 0.0) {
00078                     theta = (2.0*PI) + theta;
00079                 }
00080 
00081                 if (theta < (PI / 8.0)  &&  0 <= theta) {
00082                     sectornum = 0;
00083                 } else if (theta < ((2.0*PI) / 8.0)  &&  (PI / 8.0) <= theta) {
00084                     sectornum = 1;
00085                 } else if (theta < ((3.0*PI)/8.0)  &&  ((2.0*PI)/8.0) <= theta) {
00086                     sectornum = 2;
00087                 } else if (theta < ((4.0*PI)/8.0)  &&  ((3.0*PI)/8.0) <= theta) {
00088                     sectornum = 3;
00089                 } else if (theta < ((5.0*PI)/8.0)  &&  ((4.0*PI)/8.0) <= theta) {
00090                     sectornum = 4;
00091                 } else if (theta < ((6.0*PI)/8.0)  &&  ((5.0*PI)/8.0) <= theta) {
00092                     sectornum = 5;
00093                 } else if (theta < ((7.0*PI)/8.0)  &&  ((6.0*PI)/8.0) <= theta) {
00094                     sectornum = 6;
00095                 } else if (theta < ((8.0*PI)/8.0)  &&  ((7.0*PI)/8.0) <= theta) {
00096                     sectornum = 7;
00097                 } else if (theta < ((9.0*PI)/8.0)  &&  ((8.0*PI)/8.0) <= theta) {
00098                     sectornum = 0;
00099                 } else if (theta < ((10.0*PI)/8.0)  &&  ((9.0*PI)/8.0) <= theta) {
00100                     sectornum = 1;
00101                 } else if (theta < ((11.0*PI)/8.0)  &&  ((10.0*PI)/8.0) <= theta) {
00102                     sectornum = 2;
00103                 } else if (theta < ((12.0*PI)/8.0)  &&  ((11.0*PI)/8.0) <= theta) {
00104                     sectornum = 3;
00105                 } else if (theta < ((13.0*PI)/8.0)  &&  ((12.0*PI)/8.0) <= theta) {
00106                     sectornum = 4;
00107                 } else if (theta < ((14.0*PI)/8.0)  &&  ((13.0*PI)/8.0) <= theta) {
00108                     sectornum = 5;
00109                 } else if (theta < ((15.0*PI)/8.0)  &&  ((14.0*PI)/8.0) <= theta) {
00110                     sectornum = 6;
00111                 } else {  /* if (theta <= (2.0*PI)  &&  ((15.0*PI)/8.0) <= theta) */
00112                     sectornum = 7;
00113                 }
00114             
00115                 (*out)->data[i][j][k] = (PIXEL)(sectornum);
00116             }
00117         }
00118     }
00119 
00120 
00121         
00122     the_end:
00123     /* if (TIMES) TIMING(T_EXIT); */
00124 }
00125 

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