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