00001 #include "sadie.h"
00002 #include "proto.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 void MAXGRADDIR (
00028 IMAGE *mag,
00029 IMAGE *dir
00030
00031 ) { register short i, j, k;
00032 char msg[SLEN];
00033 double theta;
00034 int sectornum;
00035 int count[8];
00036 PIXEL value[8];
00037
00038
00039 if (NAMES) {
00040 MESSAGE('I',"");
00041 MESSAGE('I',"MAXGRADDIR");
00042 MESSAGE('I',"");
00043 sprintf(msg," Input mag: %s",mag->text);
00044 MESSAGE('I',msg);
00045 sprintf(msg," Input dir: %s",dir->text);
00046 MESSAGE('I',msg);
00047 MESSAGE('I'," ...............");
00048 }
00049
00050
00051 if (!CHECKIMG(mag)) {
00052 MESSAGE('E'," Can't identify image.");
00053 goto the_end;
00054 }
00055 if (!CHECKIMG(dir)) {
00056 MESSAGE('E'," Can't identify image.");
00057 goto the_end;
00058 }
00059 if (dir->nbnd != mag->nbnd || dir->nlin != mag->nlin || dir->npix != mag->npix) {
00060 MESSAGE('E'," Input images must be the same size.");
00061 goto the_end;
00062 }
00063
00064
00065 RANGE(dir);
00066
00067
00068 if (dir->gmin < -2.0*PI || 2.0*PI < dir->gmax) {
00069 MESSAGE('E'," This is not a gradient direction image!");
00070 MESSAGE('E'," Direction must be between -360 and +360 degrees.");
00071 goto the_end;
00072 }
00073
00074 for (i=0; i<8; i++) {
00075 count[i] = 0;
00076 value[i] = (PIXEL)0.0;
00077 }
00078
00079 for (i=0; i<dir->nbnd; i++) {
00080 for (j=0; j<dir->nlin; j++) {
00081 for (k=0; k<dir->npix; k++) {
00082 theta = (double)(dir->data[i][j][k]);
00083
00084
00085 if (theta < 0.0) {
00086 theta = (2.0*PI) + theta;
00087 }
00088
00089 if ((theta < (PI / 8.0)) && (0 <= theta)) {
00090 sectornum = 0;
00091 } else if ((theta <= (2*PI)) && (((15.0*PI)/8.0) <= theta)) {
00092 sectornum = 0;
00093 } else if ((theta < ((3.0*PI)/8.0)) && ((PI/8.0) <= theta)) {
00094 sectornum = 1;
00095 } else if ((theta < ((5.0*PI)/8.0)) && (((3.0*PI)/8.0) <= theta)) {
00096 sectornum = 2;
00097 } else if ((theta < ((7.0*PI)/8.0)) && (((5.0*PI)/8.0) <= theta)) {
00098 sectornum = 3;
00099 } else if ((theta < ((9.0*PI)/8.0)) && (((7.0*PI)/8.0) <= theta)) {
00100 sectornum = 4;
00101 } else if ((theta < ((11.0*PI)/8.0)) && (((9.0*PI)/8.0) <= theta)) {
00102 sectornum = 5;
00103 } else if ((theta < ((13.0*PI)/8.0)) && (((11.0*PI)/8.0) <= theta)) {
00104 sectornum = 6;
00105 } else {
00106 sectornum = 7;
00107 }
00108
00109 count[sectornum] += 1;
00110 value[sectornum] += mag->data[i][j][k];
00111 }
00112 }
00113 }
00114
00115 for (i=0; i<8; i++) {
00116 if (count[i] <= 0) {
00117 printf("Direction %d %5.4f\n",i+1,0.0);
00118 } else {
00119 printf("Direction %d %5.4f\n",i+1,value[i]/(PIXEL)count[i]);
00120 }
00121 }
00122
00123
00124 the_end:
00125
00126 }