00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 void DECORSTR (
00016 IMAGE *in,
00017 short inc,
00018
00019 IMAGE **out
00020
00021
00022 ) { register short i, j, k, l;
00023 double *mean=0, *dev=0, *cov=0, *cor=0, *eig=0, *pct=0, avgdev, sum, pinc, psum;
00024 PIXEL *gmin=0, *gmax=0, *grng=0;
00025 long *zero=0;
00026
00027 if (TIMES) TIMING(T_DECORSTR);
00028
00029 if (NAMES) {
00030 MESSAGE('I',"");
00031 MESSAGE('I',"DECORSTR");
00032 }
00033
00034
00035 if (!CHECKIMG(in)) {
00036 MESSAGE('E'," Can't identify image.");
00037 goto the_end;
00038 } else if (in->nbnd == 1) {
00039 MESSAGE('E'," Image must be multi-band.");
00040 goto the_end;
00041 } else if (inc <= 0) {
00042 MESSAGE('E'," Subsample increment must be greater than zero.");
00043 goto the_end;
00044 }
00045
00046
00047 if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00048 if (!*out) goto the_end;
00049
00050
00051 if (!(mean=(double *)malloc(in->nbnd*sizeof(double)))) {
00052 MESSAGE ('E', " Memory request failed.");
00053 goto the_end;
00054 }
00055 if (!(dev=(double *)malloc(in->nbnd*sizeof(double)))) {
00056 MESSAGE ('E', " Memory request failed.");
00057 goto the_end;
00058 }
00059 if (!(gmin=(PIXEL *)malloc(in->nbnd*sizeof(PIXEL)))) {
00060 MESSAGE ('E', " Memory request failed.");
00061 goto the_end;
00062 }
00063 if (!(gmax=(PIXEL *)malloc(in->nbnd*sizeof(PIXEL)))) {
00064 MESSAGE ('E', " Memory request failed.");
00065 goto the_end;
00066 }
00067 if (!(grng=(PIXEL *)malloc(in->nbnd*sizeof(PIXEL)))) {
00068 MESSAGE ('E', " Memory request failed.");
00069 goto the_end;
00070 }
00071 if (!(zero=(long *)malloc(in->nbnd*sizeof(long)))) {
00072 MESSAGE ('E', " Memory request failed.");
00073 goto the_end;
00074 }
00075 if (!(cov=(double *)malloc(in->nbnd*in->nbnd*sizeof(double)))) {
00076 MESSAGE('E'," Memory request failed.");
00077 goto the_end;
00078 }
00079 if (!(cor=(double *)malloc(in->nbnd*in->nbnd*sizeof(double)))) {
00080 MESSAGE('E'," Memory request failed.");
00081 goto the_end;
00082 }
00083 if (!(eig=(double *)malloc(in->nbnd*in->nbnd*sizeof(double)))) {
00084 MESSAGE('E'," Memory request failed.");
00085 goto the_end;
00086 }
00087 if (!(pct=(double *)malloc(in->nbnd*sizeof(double)))) {
00088 MESSAGE ('E', " Memory request failed.");
00089 goto the_end;
00090 }
00091
00092
00093 if (LINES && !PROGRESS(psum=0.0)) goto the_end;
00094 pinc = 1.0/(double)in->nlin;
00095
00096
00097 STATS(in,inc,(short)0,IGNORE,0.0,0.0,mean,dev,gmin,gmax,grng,zero);
00098 if (ABORT) goto the_end;
00099 avgdev = 0.0;
00100 for (i=0; i<in->nbnd; i++) {
00101 avgdev += dev[i];
00102 }
00103 avgdev /= in->nbnd;
00104 COVAR(in,inc,cov,cor);
00105 if (ABORT) goto the_end;
00106 EIGEN(cov,in->nbnd,eig);
00107 if (ABORT) goto the_end;
00108
00109 for (j=0; j<in->nlin; j++) {
00110 for (k=0; k<in->npix; k++) {
00111
00112
00113 for (i=0; i<in->nbnd; i++) {
00114 for (pct[i]=0.0,l=0; l<in->nbnd; l++) {
00115 pct[i] += (double)((in->data[l][j][k] - mean[l])*eig[l*in->nbnd+i]);
00116 }
00117 }
00118
00119
00120 for (i=0; i<in->nbnd; i++) {
00121 for (sum=0.0,l=0; l<in->nbnd; l++) {
00122 sum += eig[i*in->nbnd+l] * ((pct[l]*avgdev)/sqrt(cov[l*in->nbnd+l]));
00123 }
00124 (*out)->data[i][j][k] = (PIXEL)(sum + mean[i]);
00125 }
00126
00127 }
00128 if (LINES && !PROGRESS(psum+=pinc)) goto the_end;
00129 }
00130
00131 the_end:
00132 if (cov) free(cov);
00133 if (cor) free(cor);
00134 if (eig) free(eig);
00135 if (pct) free(pct);
00136 if (mean) free(mean);
00137 if (dev) free(dev);
00138 if (gmin) free(gmin);
00139 if (gmax) free(gmax);
00140 if (grng) free(grng);
00141 if (zero) free(zero);
00142 if (TIMES) TIMING(T_EXIT);
00143 }