00001 #include "sadie.h"
00002 #include "proto.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 void PERIODOGRAM (
00015 IMAGE *in,
00016 IMAGE **out
00017
00018
00019 ) { register short i, j, k;
00020 IMAGE *window=NULL;
00021 IMAGE *periodogram=NULL;
00022 IMAGE *section=NULL;
00023 IMAGE *scratch=NULL;
00024 int pheight, pwidth;
00025 PIXEL hwin, vwin;
00026 int vcount, hcount, voffset, hoffset;
00027 char msg[SLEN];
00028
00029 if (NAMES) {
00030 MESSAGE('I',"");
00031 MESSAGE('I',"PERIODOGRAM");
00032 MESSAGE('I',"");
00033 sprintf(msg," Input image: %s",in->text);
00034 MESSAGE('I',msg);
00035 MESSAGE('I'," ...............");
00036 }
00037
00038
00039 NAMES = 0;
00040
00041
00042
00043 if (!CHECKIMG(in)) {
00044 MESSAGE('E'," Can't identify image.");
00045 goto the_end;
00046 } else if (in->nlin < 4) {
00047 MESSAGE('E'," Number of lines must be at least four.");
00048 goto the_end;
00049 } else if (in->npix < 4) {
00050 MESSAGE('E'," Number of pixels/line must be at least four.");
00051 goto the_end;
00052 }
00053
00054 pwidth = (int) pow(2.0,floor(log10((double)in->npix)/log10(2.0)) - 1.0);
00055 pheight = (int) pow(2.0,floor(log10((double)in->nlin)/log10(2.0)) - 1.0);
00056
00057 if (in->nlin > (pheight*2)) {
00058 sprintf(msg, "Only the first %d lines will be used to compute the periodogram.", pheight*2);
00059 MESSAGE('I', msg);
00060 } else if (in->npix > (pwidth*2)) {
00061 sprintf(msg, "Only the first %d pixels in each line will be used to compute the periodogram.", pwidth*2);
00062 MESSAGE('I', msg);
00063 }
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 if (!CHECKIMG(window)) GETMEM(1,pheight,pwidth,&window);
00083 if (!window) goto the_end;
00084
00085 for (j=0; j<pheight; j++) {
00086 vwin = (PIXEL) (1.0 - ((((PIXEL)j - ((PIXEL)pheight-1.0)/2.0)/(((PIXEL)pheight+1.0)/2.0)) * (((PIXEL)j - ((PIXEL)pheight-1.0)/2.0)/(((PIXEL)pheight+1.0)/2.0))));
00087 for (k=0; k<pwidth; k++) {
00088 hwin = (PIXEL) (1.0 - ((((PIXEL)k - ((PIXEL)pwidth-1.0)/2.0)/(((PIXEL)pwidth+1.0)/2.0)) * (((PIXEL)k - ((PIXEL)pwidth-1.0)/2.0)/(((PIXEL)pwidth+1.0)/2.0))));
00089 window->data[0][j][k] = hwin * vwin;
00090 }
00091 }
00092
00093
00094
00095
00096
00097 if (!CHECKIMG(*out)) GETMEM(in->nbnd,pheight,pwidth,out);
00098 if (!*out) goto the_end;
00099
00100
00101 for (i=0; i<(*out)->nbnd; i++) {
00102 for (j=0; j<(*out)->nlin; j++) {
00103 for (k=0; k<(*out)->npix; k++) {
00104 (*out)->data[i][j][k] = (PIXEL)0.0;
00105 }
00106 }
00107 }
00108
00109
00110
00111
00112
00113 if (!CHECKIMG(section)) GETMEM(in->nbnd,pheight,pwidth,§ion);
00114 if (!section) goto the_end;
00115
00116
00117 if (!CHECKIMG(scratch)) GETMEM(in->nbnd,pheight,pwidth,&scratch);
00118 if (!scratch) goto the_end;
00119
00120
00121 voffset=(int)rnd((double)pheight/2.0);
00122 hoffset=(int)rnd((double)pwidth/2.0);
00123 for (vcount=0; vcount<3; vcount++) {
00124 for (hcount=0; hcount<3; hcount++) {
00125 for (i=0; i<in->nbnd; i++) {
00126 for (j=0; j<pheight; j++) {
00127 for (k=0; k<pwidth; k++) {
00128 section->data[i][j][k] = in->data[i][j+(voffset*vcount)][k+(hoffset*hcount)] * window->data[0][j][k];;
00129 }
00130 }
00131 }
00132
00133 PSPECT(section,&scratch);
00134
00135 for (i=0; i<(*out)->nbnd; i++) {
00136 for (j=0; j<(*out)->nlin; j++) {
00137 for (k=0; k<(*out)->npix; k++) {
00138 (*out)->data[i][j][k] += scratch->data[i][j][k];
00139 }
00140 }
00141 }
00142
00143 }
00144 }
00145
00146
00147 for (i=0; i<(*out)->nbnd; i++) {
00148 for (j=0; j<(*out)->nlin; j++) {
00149 for (k=0; k<(*out)->npix; k++) {
00150 (*out)->data[i][j][k] /= (PIXEL)9.0;
00151 }
00152 }
00153 }
00154
00155
00156
00157
00158
00159
00160
00161
00162 the_end:
00163 if (window) RELMEM(window);
00164 if (periodogram) RELMEM(periodogram);
00165 if (scratch) RELMEM(scratch);
00166
00167 if (TIMES) TIMING(T_EXIT);
00168
00169 NAMES = 1;
00170 }