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
00028
00029 void SECTOR8 (
00030 IMAGE *in,
00031 IMAGE **out
00032
00033 ) { register short i, j, k;
00034 char msg[SLEN];
00035 double theta;
00036 int sectornum;
00037
00038
00039 if (NAMES) {
00040 MESSAGE('I',"");
00041 MESSAGE('I',"SECTOR8");
00042 MESSAGE('I',"");
00043 sprintf(msg," Input image: %s",in->text);
00044 MESSAGE('I',msg);
00045 MESSAGE('I'," ...............");
00046 }
00047
00048
00049 if (!CHECKIMG(in)) {
00050 MESSAGE('E'," Can't identify image.");
00051 goto the_end;
00052 }
00053
00054
00055 RANGE(in);
00056
00057
00058 if (in->gmin < -2.0*PI || 2.0*PI < in->gmax) {
00059 MESSAGE('E'," This is not a gradient direction image!");
00060 MESSAGE('E'," Direction must be between -360 and +360 degrees.");
00061 goto the_end;
00062 }
00063
00064
00065 if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00066 if (!*out) goto the_end;
00067
00068
00069
00070
00071 for (i=0; i<in->nbnd; i++) {
00072 for (j=0; j<in->nlin; j++) {
00073 for (k=0; k<in->npix; k++) {
00074 theta = (double)(in->data[i][j][k]);
00075
00076
00077 if (theta < 0.0) {
00078 theta = (2.0*PI) + theta;
00079 }
00080
00081 if (theta < (PI / 8.0) && 0 <= theta) {
00082 sectornum = 0;
00083 } else if (theta < ((2.0*PI) / 8.0) && (PI / 8.0) <= theta) {
00084 sectornum = 1;
00085 } else if (theta < ((3.0*PI)/8.0) && ((2.0*PI)/8.0) <= theta) {
00086 sectornum = 2;
00087 } else if (theta < ((4.0*PI)/8.0) && ((3.0*PI)/8.0) <= theta) {
00088 sectornum = 3;
00089 } else if (theta < ((5.0*PI)/8.0) && ((4.0*PI)/8.0) <= theta) {
00090 sectornum = 4;
00091 } else if (theta < ((6.0*PI)/8.0) && ((5.0*PI)/8.0) <= theta) {
00092 sectornum = 5;
00093 } else if (theta < ((7.0*PI)/8.0) && ((6.0*PI)/8.0) <= theta) {
00094 sectornum = 6;
00095 } else if (theta < ((8.0*PI)/8.0) && ((7.0*PI)/8.0) <= theta) {
00096 sectornum = 7;
00097 } else if (theta < ((9.0*PI)/8.0) && ((8.0*PI)/8.0) <= theta) {
00098 sectornum = 0;
00099 } else if (theta < ((10.0*PI)/8.0) && ((9.0*PI)/8.0) <= theta) {
00100 sectornum = 1;
00101 } else if (theta < ((11.0*PI)/8.0) && ((10.0*PI)/8.0) <= theta) {
00102 sectornum = 2;
00103 } else if (theta < ((12.0*PI)/8.0) && ((11.0*PI)/8.0) <= theta) {
00104 sectornum = 3;
00105 } else if (theta < ((13.0*PI)/8.0) && ((12.0*PI)/8.0) <= theta) {
00106 sectornum = 4;
00107 } else if (theta < ((14.0*PI)/8.0) && ((13.0*PI)/8.0) <= theta) {
00108 sectornum = 5;
00109 } else if (theta < ((15.0*PI)/8.0) && ((14.0*PI)/8.0) <= theta) {
00110 sectornum = 6;
00111 } else {
00112 sectornum = 7;
00113 }
00114
00115 (*out)->data[i][j][k] = (PIXEL)(sectornum);
00116 }
00117 }
00118 }
00119
00120
00121
00122 the_end:
00123
00124 }
00125