00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 void
00021 RELIEF (IMAGE * in,
00022 double phi,
00023
00024
00025
00026
00027 double theta,
00028
00029 double dist,
00030
00031
00032
00033 IMAGE ** out
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
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
00081 if (!CHECKIMG (*out))
00082 GETMEM (in->nbnd, in->nlin, in->npix, out);
00083 if (!*out)
00084 goto the_end;
00085
00086
00087 ps = sin (phi) / tan (theta);
00088 qs = cos (phi) / tan (theta);
00089 sn = sqrt (1.0 + ps * ps + qs * qs);
00090
00091
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
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 }