Main Page   Data Structures   File List   Data Fields   Globals  

periodogram.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 #include        "proto.h"
00003 
00004 /*-Copyright Information------------------------------------------------------*/
00005 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00006 /*----------------------------------------------------------------------------*/
00007 /*-General Information--------------------------------------------------------*/
00008 /*                                                                            */
00009 /*   This function computes the periodogram of an image, using the            */
00010 /*   Fast Fourier transform.                                                  */
00011 /*                                                                            */
00012 /*----------------------------------------------------------------------------*/
00013 /*-Interface Information------------------------------------------------------*/
00014 void PERIODOGRAM (
00015 IMAGE *in,      /*  I   Pointer to the input image.                           */
00016 IMAGE **out     /*  O   Address of a pointer to the output image.             */
00017                 /*      The input image may be overwritten (out = &in).       */
00018 /*----------------------------------------------------------------------------*/
00019 ) { register short i, j, k;
00020     IMAGE *window=NULL;
00021     IMAGE *periodogram=NULL;
00022     IMAGE *section=NULL;
00023     IMAGE *scratch=NULL;
00024     int pheight, pwidth;
00025     PIXEL hwin, vwin;
00026     int vcount, hcount, voffset, hoffset;
00027     char msg[SLEN];
00028 
00029     if (NAMES) {
00030         MESSAGE('I',"");
00031         MESSAGE('I',"PERIODOGRAM");
00032         MESSAGE('I',"");
00033         sprintf(msg," Input image:   %s",in->text);
00034         MESSAGE('I',msg);
00035         MESSAGE('I'," ...............");
00036     }
00037 
00038 
00039 NAMES = 0;
00040 
00041 
00042     /* check input */
00043     if (!CHECKIMG(in)) {
00044         MESSAGE('E'," Can't identify image.");
00045         goto the_end;
00046     } else if (in->nlin < 4) {
00047         MESSAGE('E'," Number of lines must be at least four.");
00048         goto the_end;
00049     } else if (in->npix < 4) {
00050         MESSAGE('E'," Number of pixels/line must be at least four.");
00051         goto the_end;
00052     }
00053     
00054     pwidth = (int) pow(2.0,floor(log10((double)in->npix)/log10(2.0)) - 1.0);
00055     pheight = (int) pow(2.0,floor(log10((double)in->nlin)/log10(2.0)) - 1.0);
00056     
00057     if (in->nlin > (pheight*2)) {
00058         sprintf(msg, "Only the first %d lines will be used to compute the periodogram.", pheight*2);
00059         MESSAGE('I', msg);
00060     } else if (in->npix > (pwidth*2)) {
00061         sprintf(msg, "Only the first %d pixels in each line will be used to compute the periodogram.", pwidth*2);
00062         MESSAGE('I', msg);
00063     }
00064     
00065 
00066 
00067     /* Compute a 2-D window function assuming that lines and columns are independent */
00068     /* The 1-D equivalent of the window function is:
00069 
00070                       /             \  2
00071                      |       L-1     | 
00072                      |   j - ---     |
00073                      |        2      |
00074           W(j) = 1 - |  ----------   |      , j = 0,1,...,L-1
00075                      |     L+1       |
00076                      |     ---       |
00077                      |      2        |
00078                       \             /
00079      */
00080      
00081     /* create window image of appropriate size */
00082     if (!CHECKIMG(window)) GETMEM(1,pheight,pwidth,&window);
00083     if (!window) goto the_end;
00084 
00085     for (j=0; j<pheight; j++) {
00086         vwin = (PIXEL) (1.0 - ((((PIXEL)j - ((PIXEL)pheight-1.0)/2.0)/(((PIXEL)pheight+1.0)/2.0)) * (((PIXEL)j - ((PIXEL)pheight-1.0)/2.0)/(((PIXEL)pheight+1.0)/2.0))));
00087         for (k=0; k<pwidth; k++) {
00088             hwin = (PIXEL) (1.0 - ((((PIXEL)k - ((PIXEL)pwidth-1.0)/2.0)/(((PIXEL)pwidth+1.0)/2.0)) * (((PIXEL)k - ((PIXEL)pwidth-1.0)/2.0)/(((PIXEL)pwidth+1.0)/2.0))));
00089             window->data[0][j][k] = hwin * vwin;
00090         }
00091     }     
00092      
00093      
00094      
00095      
00096     /* create image of appropriate size */
00097     if (!CHECKIMG(*out)) GETMEM(in->nbnd,pheight,pwidth,out);
00098     if (!*out) goto the_end;
00099 
00100     /* initialize the output */
00101     for (i=0; i<(*out)->nbnd; i++) {
00102         for (j=0; j<(*out)->nlin; j++) {
00103             for (k=0; k<(*out)->npix; k++) {
00104                 (*out)->data[i][j][k] = (PIXEL)0.0;
00105             }
00106         }
00107     }
00108 
00109 
00110 
00111 
00112     /* create temporary image of appropriate size to hold windowed subsections of input */
00113     if (!CHECKIMG(section)) GETMEM(in->nbnd,pheight,pwidth,&section);
00114     if (!section) goto the_end;
00115     
00116     /* create temporary image of appropriate size to hold individual periodograms */
00117     if (!CHECKIMG(scratch)) GETMEM(in->nbnd,pheight,pwidth,&scratch);
00118     if (!scratch) goto the_end;
00119     
00120     
00121     voffset=(int)rnd((double)pheight/2.0);
00122     hoffset=(int)rnd((double)pwidth/2.0);
00123     for (vcount=0; vcount<3; vcount++) {
00124         for (hcount=0; hcount<3; hcount++) {
00125             for (i=0; i<in->nbnd; i++) {
00126                 for (j=0; j<pheight; j++) {
00127                     for (k=0; k<pwidth; k++) {
00128                         section->data[i][j][k] = in->data[i][j+(voffset*vcount)][k+(hoffset*hcount)] * window->data[0][j][k];;
00129                     }
00130                 }
00131             }
00132 
00133             PSPECT(section,&scratch);
00134 
00135             for (i=0; i<(*out)->nbnd; i++) {
00136                 for (j=0; j<(*out)->nlin; j++) {
00137                     for (k=0; k<(*out)->npix; k++) {
00138                         (*out)->data[i][j][k] += scratch->data[i][j][k];
00139                     }
00140                 }
00141             }
00142 
00143         }
00144     }
00145     
00146     
00147     for (i=0; i<(*out)->nbnd; i++) {
00148         for (j=0; j<(*out)->nlin; j++) {
00149             for (k=0; k<(*out)->npix; k++) {
00150                 (*out)->data[i][j][k] /= (PIXEL)9.0;
00151             }
00152         }
00153     }
00154     
00155     
00156     
00157     //RADIALAVG(*out);
00158     
00159     
00160 
00161 
00162     the_end:
00163     if (window) RELMEM(window);
00164     if (periodogram) RELMEM(periodogram);
00165     if (scratch) RELMEM(scratch);
00166     /* if (*out) RELMEM(*out); */
00167     if (TIMES)   TIMING(T_EXIT);
00168     
00169 NAMES = 1;
00170 }

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