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