Main Page   Data Structures   File List   Data Fields   Globals  

sector.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 a sector map from from a gradient direction     */
00008 /*   image.  Each direction pixel is converted to the corresponding sector    */
00009 /*   #0-3 as shown:                                                           */
00010 /*                                                                            */
00011 /*          337.5 -  22.5 degrees   --      Sector 0                          */
00012 /*          22.5  -  67.5 degrees   --      Sector 1                          */
00013 /*          67.5  - 112.5 degrees   --      Sector 2                          */
00014 /*          112.5 - 157.5 degrees   --      Sector 3                          */
00015 /*          157.5 - 202.5 degrees   --      Sector 0                          */
00016 /*          202.5 - 247.5 degrees   --      Sector 1                          */
00017 /*          247.5 - 292.5 degrees   --      Sector 2                          */
00018 /*          292.5 - 337.5 degrees   --      Sector 3                          */
00019 /*                                                                            */
00020 /*----------------------------------------------------------------------------*/
00021 /*-Interface Information------------------------------------------------------*/
00022 void SECTOR (
00023 IMAGE  *in,     /*  I   Pointer to the input image.                           */
00024 IMAGE  **out    /*  O   Address of a pointer to the output image.             */
00025 /*----------------------------------------------------------------------------*/
00026 ) { register short i, j, k;
00027     char msg[SLEN];
00028     double theta;
00029     int sectornum;
00030 
00031     /* if (TIMES) TIMING(T_SECTOR); */
00032     if (NAMES) {
00033         MESSAGE('I',"");
00034         MESSAGE('I',"SECTOR");
00035         MESSAGE('I',"");
00036         sprintf(msg," Input image:                       %s",in->text);
00037         MESSAGE('I',msg);
00038         MESSAGE('I'," ...............");
00039     }
00040 
00041     /* check input */
00042     if (!CHECKIMG(in)) {
00043         MESSAGE('E'," Can't identify image.");
00044         goto the_end;
00045     }
00046     
00047     /* Find the min and max values in the image */
00048     RANGE(in);
00049     
00050     /* Verify that this is a gradient direction image */
00051     if (in->gmin < -2.0*PI  ||  2.0*PI < in->gmax) {
00052         MESSAGE('E'," This is not a gradient direction image!");
00053         MESSAGE('E'," Direction must be between -360 and +360 degrees.");
00054         goto the_end;
00055     }
00056 
00057     /* create image of appropriate size */
00058     if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00059     if (!*out) goto the_end;
00060 
00061 
00062     /* build sector image */
00063     for (i=0; i<in->nbnd; i++) {
00064         for (j=0; j<in->nlin; j++) {
00065             for (k=0; k<in->npix; k++) {
00066                 theta = (double)(in->data[i][j][k]);
00067                 
00068                 /* Convert to positive angle */
00069                 if (theta < 0.0) {
00070                     theta = (2.0*PI) + theta;
00071                 }
00072                 
00073                 if ((theta < (PI / 8.0))  &&  (0 <= theta)) {
00074                     sectornum = 0;
00075                 } else if ((theta <= (2*PI))  &&  (((15.0*PI)/8.0) <= theta)) {
00076                     sectornum = 0;
00077                 } else if ((theta < ((3.0*PI)/8.0))  &&  ((PI/8.0) <= theta)) {
00078                     sectornum = 1;
00079                 } else if ((theta < ((5.0*PI)/8.0))  &&  (((3.0*PI)/8.0) <= theta)) {
00080                     sectornum = 2;
00081                 } else if ((theta < ((7.0*PI)/8.0))  &&  (((5.0*PI)/8.0) <= theta)) {
00082                     sectornum = 3;
00083                 } else if ((theta < ((9.0*PI)/8.0))  &&  (((7.0*PI)/8.0) <= theta)) {
00084                     sectornum = 0;
00085                 } else if ((theta < ((11.0*PI)/8.0))  &&  (((9.0*PI)/8.0) <= theta)) {
00086                     sectornum = 1;
00087                 } else if ((theta < ((13.0*PI)/8.0))  &&  (((11.0*PI)/8.0) <= theta)) {
00088                     sectornum = 2;
00089                 } else {  /* if (theta < ((15.0*PI)/8.0)  &&  ((13.0*PI)/8.0) <= theta) */
00090                     sectornum = 3;
00091                 }
00092             
00093                 (*out)->data[i][j][k] = (PIXEL)(sectornum);
00094             }
00095         }
00096     }
00097 
00098         
00099     the_end:
00100     /* if (TIMES) TIMING(T_EXIT); */
00101 }

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