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 PCT (
00014 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 ) { 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     /* check input */
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     /* create image of appropriate size */
00049     if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00050     if (!*out) goto the_end;
00051 
00052     /* allocate space for cov, cor, and eig */
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     /* initialize progress indicator */
00067     if (LINES  &&  !PROGRESS(psum=0.0)) goto the_end;
00068     pinc = 1.0/(double)in->nbnd/(double)in->nlin;
00069 
00070     /* compute covariance matrix of the input image and its eigenvectors */
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     /* perform principal component transform */
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 }

Generated on Wed Apr 9 08:56:09 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002