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