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
00021 RELIEF (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   )
00036 {
00037   register short i, j, k;
00038   char msg[SLEN];
00039   double ps, qs, sn, p, q;
00040 
00041   if (TIMES)
00042     TIMING (T_RELIEF);
00043   if (NAMES)
00044     {
00045       MESSAGE ('I', "");
00046       MESSAGE ('I', "RELIEF");
00047       MESSAGE ('I', "");
00048       sprintf (msg, " Input image:                       %s", in->text);
00049       MESSAGE ('I', msg);
00050       sprintf (msg, " Horizontal illumination angle:   %12.4e",
00051                180.0 * phi / PI);
00052       MESSAGE ('I', msg);
00053       sprintf (msg, " Vertical illumination angle:     %12.4e",
00054                180.0 * theta / PI);
00055       MESSAGE ('I', msg);
00056       sprintf (msg, " Distance between pixels:         %12.4e", dist);
00057       MESSAGE ('I', msg);
00058       MESSAGE ('I', " ...............");
00059     }
00060 
00061   /* check input */
00062   if (!CHECKIMG (in))
00063     {
00064       MESSAGE ('E', " Can't identify image.");
00065       goto the_end;
00066     }
00067   else if (phi < -2.0 * PI || 2.0 * PI < phi)
00068     {
00069       MESSAGE ('E',
00070                " Horizontal illumination angle must be between -360 and +360 degrees.");
00071       goto the_end;
00072     }
00073   else if (theta < -0.5 * PI || 0.5 * PI < theta)
00074     {
00075       MESSAGE ('E',
00076                " Vertical illumination angle must be between -90 and +90 degrees.");
00077       goto the_end;
00078     }
00079 
00080   /* create image of appropriate size */
00081   if (!CHECKIMG (*out))
00082     GETMEM (in->nbnd, in->nlin, in->npix, out);
00083   if (!*out)
00084     goto the_end;
00085 
00086   /* initialize irradiance parameters */
00087   ps = sin (phi) / tan (theta);
00088   qs = cos (phi) / tan (theta);
00089   sn = sqrt (1.0 + ps * ps + qs * qs);
00090 
00091   /* build relief image */
00092   for (i = 0; i < in->nbnd; i++)
00093     {
00094       for (j = 1; j < in->nlin - 1; j++)
00095         {
00096           for (k = 1; k < in->npix - 1; k++)
00097             {
00098               p = (double) (in->data[i][j][k + 1] - in->data[i][j][k - 1]);
00099               q = (double) (in->data[i][j - 1][k] - in->data[i][j + 1][k]);
00100               (*out)->data[i][j][k] =
00101                 (PIXEL) ((dist + ps * p +
00102                           qs * q) / (sn * sqrt (dist * dist + p * p +
00103                                                 q * q)));
00104             }
00105         }
00106     }
00107 
00108   /* zero borders */
00109   for (i = 0; i < in->nbnd; i++)
00110     {
00111       for (j = 0; j < in->nlin; j++)
00112         {
00113           (*out)->data[i][j][0] = (PIXEL) 0;
00114           (*out)->data[i][j][in->npix - 1] = (PIXEL) 0;
00115         }
00116       for (k = 0; k < in->npix; k++)
00117         {
00118           (*out)->data[i][0][k] = (PIXEL) 0;
00119           (*out)->data[i][in->nlin - 1][k] = (PIXEL) 0;
00120         }
00121     }
00122 
00123 the_end:
00124   if (TIMES)
00125     TIMING (T_EXIT);
00126 }

Generated on Sun May 18 15:36:13 2003 for tclSadie by doxygen1.3