Main Page   Data Structures   File List   Data Fields   Globals  

relief.c

Go to the documentation of this file.
00001 #include "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1993 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This function calculates a shaded relief image from digital terrain data */
00009 /*   or any other surface data.                                               */
00010 /*                                                                            */
00011 /*----------------------------------------------------------------------------*/
00012 /*-Background Information-----------------------------------------------------*/
00013 /*                                                                            */
00014 /*   Woodham, Robert J.:                                                      */
00015 /*   "Using digital terrain data to model image formation in remote sensing"  */
00016 /*   SPIE, Vol. 238 (1988), pp. 361-369                                       */
00017 /*                                                                            */
00018 /*----------------------------------------------------------------------------*/
00019 /*-Interface Information------------------------------------------------------*/
00020 void RELIEF (
00021 IMAGE  *in,     /*  I   Pointer to the input image.                           */
00022 double phi,     /*  I   Horizontal illumination angle,                        */
00023                 /*      measured in radians counterclockwise from east.       */
00024                 /*      Note - for standard NCIC terrain data,                */
00025                 /*      east appears at top of the image.  In this case,      */
00026                 /*      phi for a due north azimuth would be PI/2.            */
00027 double theta,   /*  I   Vertical illumination angle,                          */
00028                 /*      measured in radians from the horizon.                 */
00029 double dist,    /*  I   Distance between adjacent data points,                */
00030                 /*      measured in the same units as the elevation data.     */
00031                 /*      Note - for standard NCIC terrain data,                */
00032                 /*      this value is 208.3 feet.                             */
00033 IMAGE  **out    /*  O   Address of a pointer to the output image.             */
00034 /*----------------------------------------------------------------------------*/
00035 ) { register short i, j, k;
00036     char msg[SLEN];
00037     double ps, qs, sn, p, q;
00038 
00039     if (TIMES) TIMING(T_RELIEF);
00040     if (NAMES) {
00041         MESSAGE('I',"");
00042         MESSAGE('I',"RELIEF");
00043         MESSAGE('I',"");
00044         sprintf(msg," Input image:                       %s",in->text);
00045         MESSAGE('I',msg);
00046         sprintf(msg," Horizontal illumination angle:   %12.4e",180.0*phi/PI);
00047         MESSAGE('I',msg);
00048         sprintf(msg," Vertical illumination angle:     %12.4e",180.0*theta/PI);
00049         MESSAGE('I',msg);
00050         sprintf(msg," Distance between pixels:         %12.4e",dist);
00051         MESSAGE('I',msg);
00052         MESSAGE('I'," ...............");
00053     }
00054 
00055     /* check input */
00056     if (!CHECKIMG(in)) {
00057         MESSAGE('E'," Can't identify image.");
00058         goto the_end;
00059     } else if (phi < -2.0*PI  ||  2.0*PI < phi) {
00060         MESSAGE('E'," Horizontal illumination angle must be between -360 and +360 degrees.");
00061         goto the_end;
00062     } else if (theta < -0.5*PI  ||  0.5*PI < theta) {
00063         MESSAGE('E'," Vertical illumination angle must be between -90 and +90 degrees.");
00064         goto the_end;
00065     }
00066 
00067     /* create image of appropriate size */
00068     if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00069     if (!*out) goto the_end;
00070 
00071     /* initialize irradiance parameters */
00072     ps = sin(phi) / tan(theta);
00073     qs = cos(phi) / tan(theta);
00074     sn = sqrt(1.0 + ps*ps + qs*qs);
00075 
00076     /* build relief image */
00077     for (i=0; i<in->nbnd; i++) {
00078         for (j=1; j<in->nlin-1; j++) {
00079             for (k=1; k<in->npix-1; k++) {
00080                 p = (double)(in->data[i][j][k+1] - in->data[i][j][k-1]);
00081                 q = (double)(in->data[i][j-1][k] - in->data[i][j+1][k]);
00082                 (*out)->data[i][j][k] = (PIXEL)((dist + ps*p + qs*q) / (sn * sqrt(dist*dist + p*p + q*q)));
00083             }
00084         }
00085     }
00086 
00087     /* zero borders */
00088     for (i=0; i<in->nbnd; i++) {
00089         for (j=0; j<in->nlin; j++) {
00090             (*out)->data[i][j][         0] = (PIXEL)0;
00091             (*out)->data[i][j][in->npix-1] = (PIXEL)0;
00092         }
00093         for (k=0; k<in->npix; k++) {
00094             (*out)->data[i][         0][k] = (PIXEL)0;
00095             (*out)->data[i][in->nlin-1][k] = (PIXEL)0;
00096         }
00097     }
00098         
00099     the_end:
00100     if (TIMES) TIMING(T_EXIT);
00101 }

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