Main Page   Data Structures   File List   Data Fields   Globals  

radialavg.c

Go to the documentation of this file.
00001 #include "sadie.h"
00002 #include "proto.h"
00003 
00004 
00005 PIXEL globarray_original[50][100];
00006 PIXEL globarray_percent[50][100];
00007 PIXEL globarray_normalized[50][100];
00008 int globframecount;
00009 int globfreqcount;
00010 
00011 
00012 /*----------------------------------------------------------------------------*/
00013 /*-General Information--------------------------------------------------------*/
00014 /*                                                                            */
00015 /*   This function computes the radial average intensities around the center  */
00016 /*   of the input image.  It is useful for representing a 2-D power spectrum  */
00017 /*   in 1-D.                                                                  */
00018 /*----------------------------------------------------------------------------*/
00019 /*-Interface Information------------------------------------------------------*/
00020 void RADIALAVG (
00021 IMAGE  *in     /*  I   Pointer to the input image.                           */
00022 /*----------------------------------------------------------------------------*/
00023 ) { register short i, j, k;
00024     char msg[SLEN];
00025     int length, sublength;
00026     PIXEL *value_array=NULL, *value_subarray=NULL;
00027     int *count_array=NULL;
00028     int radius;
00029     double delta_y, delta_x;
00030     PIXEL maxval, tempval;
00031 
00032     /* if (TIMES) TIMING(T_RADIALAVG); */
00033     if (NAMES) {
00034         MESSAGE('I',"");
00035         MESSAGE('I',"RADIALAVG");
00036         MESSAGE('I',"");
00037         sprintf(msg," Input image:                       %s",in->text);
00038         MESSAGE('I',msg);
00039         MESSAGE('I'," ...............");
00040     }
00041 
00042     /* check input */
00043     if (!CHECKIMG(in)) {
00044         MESSAGE('E'," Can't identify image.");
00045         goto the_end;
00046     } else if (in->npix != in->nlin) {
00047         MESSAGE('E'," Input image must have the same width and height.");
00048         goto the_end;
00049     } else if (in->nbnd > 1) {
00050         MESSAGE('E'," Input image must be single band!");
00051         goto the_end;
00052     }
00053     
00054     length = (int) rnd((double)in->nlin / 2.0);
00055     
00056     value_array = malloc((length+1) * sizeof(PIXEL));
00057     count_array = malloc((length+1) * sizeof(int));
00058     
00059     /* Initialize arrays */
00060     for (i=0; i<=length; i++) {
00061         value_array[i] = (PIXEL)0.0;
00062         count_array[i] = 0;
00063     }
00064 
00065 
00066     for (j=0; j<in->nlin; j++) {
00067         delta_y = (double)(j-length);
00068         for (k=0; k<in->npix; k++) {
00069 
00070             delta_x = (double)(k-length);
00071 
00072             radius = (int) rnd(sqrt((delta_x)*(delta_x) + (delta_y)*(delta_y)));
00073             
00074             if (radius <= length) {
00075                 value_array[radius] += in->data[0][j][k];
00076                 count_array[radius] += 1;
00077             }
00078         }
00079     }
00080 
00081         
00082 
00083     for (i=0; i<=length; i++) {
00084         if (count_array[i] > 0) {
00085             value_array[i] /= (PIXEL) count_array[i];
00086         }
00087         globarray_original[globframecount][i] = value_array[i];
00088     }
00089 
00090 
00091 
00092     maxval = value_array[0];
00093     for (i=0; (i<=length)&&(i<100); i++) {
00094         globarray_normalized[globframecount][i] = value_array[i]/maxval;
00095         globarray_percent[globframecount][i] = value_array[i]/maxval;
00096         //printf("%2.8f ",globarray_normalized[globframecount][i]);
00097     }
00098     //printf("\n");
00099 
00100     
00101     //sublength = (int) rnd((double)length / 10.0);
00102     //value_subarray = malloc((sublength) * sizeof(PIXEL));
00103     //for (i=0; i<sublength; i++) {
00104     //    value_subarray[i] = (PIXEL)0.0;
00105     //    
00106     //    for (j=0; j<10; j++) {
00107     //        value_subarray[i] += value_array[j+(i*10)]/maxval;
00108     //    }
00109     //    
00110     //    printf("%2.8f ",value_subarray[i]/10.0);
00111     //}
00112     //printf("\n");
00113 
00114 //
00115 //Divide each value by the DC value to normalize --> convert to percent ??
00116 //
00117 //Print out array with each row containing the results for an image and each column containing a radius?
00118 //
00119 
00120 
00121 //    PLOT(value_array,length,LOG);
00122 
00123 
00124     globframecount++;
00125     if (globfreqcount > length) {
00126         globfreqcount = (int)min(length,100);
00127     }
00128 
00129     the_end:
00130     /* if (TIMES) TIMING(T_EXIT); */
00131     if (count_array) free(count_array);
00132     if (value_array) free(value_array);
00133     if (value_subarray) free(value_subarray);
00134 }

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