Main Page   Data Structures   File List   Data Fields   Globals  

pct.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This function performs a principal component transform on a multi-band   */
00009 /*   image.                                                                   */
00010 /*                                                                            */
00011 /*----------------------------------------------------------------------------*/
00012 /*-Interface Information------------------------------------------------------*/
00013 void
00014 PCT (IMAGE * in,                /*  I   Pointer to the input image                            */
00015      short inc,                 /*  I   Line and pixel subsample increment to be used for     */
00016      /*      calculating the covariance matrix.                    */
00017      IMAGE ** out               /*  O   Address of a pointer to the output image.             */
00018      /*      The input image may be overwritten (out = &in).       */
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   /* check input */
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   /* create image of appropriate size */
00058   if (!CHECKIMG (*out))
00059     GETMEM (in->nbnd, in->nlin, in->npix, out);
00060   if (!*out)
00061     goto the_end;
00062 
00063   /* allocate space for cov, cor, and eig */
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   /* initialize progress indicator */
00081   if (LINES && !PROGRESS (psum = 0.0))
00082     goto the_end;
00083   pinc = 1.0 / (double) in->nbnd / (double) in->nlin;
00084 
00085   /* compute covariance matrix of the input image and its eigenvectors */
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   /* perform principal component transform */
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 }

Generated on Sun May 18 15:36:12 2003 for tclSadie by doxygen1.3