00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 void PCT (
00014 IMAGE *in,
00015 short inc,
00016
00017 IMAGE **out
00018
00019
00020 ) { register short i, j, k, l;
00021 char msg[SLEN];
00022 double *cov=0, *cor=0, *eig=0, sum, pinc, psum;
00023
00024 if (TIMES) TIMING(T_PCT);
00025 if (NAMES) {
00026 MESSAGE('I',"");
00027 MESSAGE('I',"PCT");
00028 MESSAGE('I',"");
00029 sprintf(msg," Input image: %s",in->text);
00030 MESSAGE('I',msg);
00031 sprintf(msg," Line and pixel subsample increment: %d",inc);
00032 MESSAGE('I',msg);
00033 MESSAGE('I'," ...............");
00034 }
00035
00036
00037 if (!CHECKIMG(in)) {
00038 MESSAGE('E'," Can't identify image.");
00039 goto the_end;
00040 } else if (in->nbnd == 1) {
00041 MESSAGE('E'," Image must be multi-band.");
00042 goto the_end;
00043 } else if (inc <= 0) {
00044 MESSAGE('E'," Subsample increment must be greater than zero.");
00045 goto the_end;
00046 }
00047
00048
00049 if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00050 if (!*out) goto the_end;
00051
00052
00053 if (!(cov=(double *)malloc(in->nbnd*in->nbnd*sizeof(double)))) {
00054 MESSAGE('E'," Memory request failed.");
00055 goto the_end;
00056 }
00057 if (!(cor=(double *)malloc(in->nbnd*in->nbnd*sizeof(double)))) {
00058 MESSAGE('E'," Memory request failed.");
00059 goto the_end;
00060 }
00061 if (!(eig=(double *)malloc(in->nbnd*in->nbnd*sizeof(double)))) {
00062 MESSAGE('E'," Memory request failed.");
00063 goto the_end;
00064 }
00065
00066
00067 if (LINES && !PROGRESS(psum=0.0)) goto the_end;
00068 pinc = 1.0/(double)in->nbnd/(double)in->nlin;
00069
00070
00071 COVAR(in,inc,cov,cor);
00072 if (ABORT) goto the_end;
00073 EIGEN(cov,in->nbnd,eig);
00074 if (ABORT) goto the_end;
00075
00076
00077 for (i=0; i<in->nbnd; i++) {
00078 for (j=0; j<in->nlin; j++) {
00079 for (k=0; k<in->npix; k++) {
00080 for (sum=0.0,l=0; l<in->nbnd; l++) {
00081 sum += (double)in->data[l][j][k]*eig[l*in->nbnd+i];
00082 }
00083 (*out)->data[i][j][k] = (PIXEL)sum;
00084 }
00085 if (LINES && !PROGRESS(psum+=pinc)) goto the_end;
00086 }
00087 }
00088
00089 the_end:
00090 if (cov) free(cov);
00091 if (cor) free(cor);
00092 if (eig) free(eig);
00093 if (TIMES) TIMING(T_EXIT);
00094 }