Main Page   Data Structures   File List   Data Fields   Globals  

mosaic_byte_resample.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 #include        "sadie_byte.h"
00003 #include        "mosaic.h"
00004 #include        "math.h"
00005 
00006 
00007 
00008 /*-Copyright Information------------------------------------------------------*/
00009 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00010 /*----------------------------------------------------------------------------*/
00011 /*-General Information--------------------------------------------------------*/
00012 /*                                                                            */
00013 /*   This function performs a moving window average on a byte mosaic image, and          */
00014 /*   resamples the new image at specified intervals.                          */
00015 /*                                                                            */
00016 /*----------------------------------------------------------------------------*/
00017 /*-Interface Information------------------------------------------------------*/
00018 void MOSAIC_BYTE_RESAMPL (
00019 IMAGE_BYTE *in,      /*  I   Pointer to the input byte mosaic image.                           */
00020 MOSAIC_INDEX *index, /* I Pointer to the input mosaic index.  */
00021 short jsize,    /*  I   Number of lines in the window.                        */
00022 short ksize,    /*  I   Number of pixels/line in the window.                  */
00023 short jinc,     /*  I   Line resampling increment.                            */
00024 short kinc,     /*  I   Pixels/line resampling increment.                     */
00025 IMAGE **out     /*  O   Address of a pointer to the output image.             */
00026 /*----------------------------------------------------------------------------*/
00027 ) { register int i, j, k, l, m, nlin, npix, pix, lin;
00028     char   msg[SLEN];
00029     double subsum, area=(double)(jsize*ksize);
00030 
00031     int progmeter;
00032     double progress;
00033     int count, total, increment;
00034     int cancel=0;
00035 
00036     progmeter = ProgMeter_Create("Resample Byte Mosaic");
00037     progress = 0.0;
00038 
00039 
00040     /* if (TIMES) TIMING(T_RESAMPL); */
00041     if (NAMES) {
00042         MESSAGE('I',"");
00043         MESSAGE('I',"MOSAIC_BYTE_RESAMPL");
00044         MESSAGE('I',"");
00045         sprintf(msg," Input image:                  %s",in->text);
00046         MESSAGE('I',msg);
00047         sprintf(msg," Window size: lines:           %d",jsize);
00048         MESSAGE('I',msg);
00049         sprintf(msg,"              pixels:          %d",ksize);
00050         MESSAGE('I',msg);
00051         sprintf(msg," Subsample increment: lines:   %d",jinc);
00052         MESSAGE('I',msg);
00053         sprintf(msg,"                      pixels:  %d",kinc);
00054         MESSAGE('I',msg);
00055         MESSAGE('I'," ...............");
00056     }
00057 
00058     /* check input */
00059     if (!CHECKIMG_BYTE(in)) {
00060         MESSAGE('E'," Can't identify image.");
00061         goto the_end;
00062     } else if (jsize <= 0) {
00063         MESSAGE('E'," Number of lines in the averaging window must be greater than zero.");
00064         goto the_end;
00065     } else if (in->nlin < jsize) {
00066         MESSAGE('E'," Image size must be equal to or greater than window size in the line dimension.");
00067         goto the_end;
00068     } else if (ksize <= 0) {
00069         MESSAGE('E'," Number of pixels/line in the averaging window must be greater than zero.");
00070         goto the_end;
00071     } else if (in->npix < ksize) {
00072         MESSAGE('E'," Image size must be equal to or greater than window sizein the pixel dimension.");
00073         goto the_end;
00074     } else if (jinc <= 0) {
00075         MESSAGE('E'," Line subsample increment must be greater than zero.");
00076         goto the_end;
00077     } else if (kinc <= 0) {
00078         MESSAGE('E'," Pixel subsample increment must be greater than zero.");
00079         goto the_end;
00080     } else if (!CHECKIMG_MOSAIC_INDEX(index)) {
00081         MESSAGE('E'," Can't identify mosaic index.");
00082         goto the_end;
00083     } else if (index->npix != in->npix) {
00084         MESSAGE('E'," Mosaic image and index are not the same size.");
00085         goto the_end;
00086     }
00087 
00088     /* create image of appropriate size */
00089     nlin = (index->nlin-jsize)/jinc + 1;
00090     npix = (index->npix-ksize)/kinc + 1;
00091     printf("index nlin = %d, index npix = %d\n",index->nlin,index->npix);
00092     printf("nlin = %d, npix = %d\n",nlin,npix);
00093     if (!CHECKIMG(*out)) GETMEM(in->nbnd,nlin,npix,out);
00094     if (!*out) goto the_end;
00095 
00096     /* perform moving average and resample */
00097     if (progmeter) {
00098         count = 0;
00099         total = in->nbnd * (npix * nlin);
00100         increment = rint((double)total/20.0);
00101     }
00102     for (i=0; i<in->nbnd; i++) {
00103         for (j=0; j<nlin; j++) {
00104             for (k=0; k<npix; k++) {
00105                 if (progmeter) {
00106                     count++;
00107                     if ((count%increment) == 0) {
00108                         progress = ((double)count/(double)total)*100.0;
00109                         cancel = ProgMeter_Update(progmeter,progress);
00110                         if (cancel != 0) goto the_end;
00111                     }
00112                 }
00113 
00114                 for (subsum=0.0,m=0; m<ksize; m++) {
00115                     pix = k*kinc+m;
00116                     for (l=0; l<jsize; l++) {
00117                         lin = (j*jinc+l)-index->voffset[pix];
00118                         if (0<lin && lin<in->nlin) {
00119                             subsum += (double)in->data[i][lin][k*kinc+m];
00120                         }
00121                     }
00122                 }
00123                 (*out)->data[i][j][k] = (PIXEL)(subsum/area);
00124             }
00125         }
00126     }
00127 
00128     the_end:
00129     if (TIMES) TIMING(T_EXIT);
00130     
00131     if (progmeter) {
00132         ProgMeter_Destroy(progmeter);
00133     }
00134     if (cancel != 0) {
00135         if (*out) RELMEM(*out);
00136         *out = NULL;
00137     }
00138 
00139 }
00140 
00141 
00142 
00143 /*-Copyright Information---------------------------------------------------------*/
00144 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab    */
00145 /*-------------------------------------------------------------------------------*/
00146 /*-General Information-----------------------------------------------------------*/
00147 /*                                                                               */
00148 /*   This function performs a moving window average on a byte mosaic image, and  */
00149 /*   resamples the new image at specified intervals. Returns a byte mosaic.      */
00150 /*                                                                               */
00151 /*-------------------------------------------------------------------------------*/
00152 /*-Interface Information---------------------------------------------------------*/
00153 void MOSAIC2MOSAIC_RESAMPL (
00154 IMAGE_BYTE *in,      /*  I   Pointer to the input byte mosaic image.             */
00155 MOSAIC_INDEX *index, /*  I   Pointer to the input mosaic index.                  */
00156 short jsize,         /*  I   Number of lines in the window.                      */
00157 short ksize,         /*  I   Number of pixels/line in the window.                */
00158 short jinc,          /*  I   Line resampling increment.                          */
00159 short kinc,          /*  I   Pixels/line resampling increment.                   */
00160 IMAGE_BYTE **out     /*  O   Address of a pointer to the output mosaic image.    */
00161 /*-------------------------------------------------------------------------------*/
00162 ) { register int i, j, k, l, m, nlin, npix;
00163     char   msg[SLEN];
00164     double subsum, area=(double)(jsize*ksize);
00165 
00166     /* if (TIMES) TIMING(T_RESAMPL); */
00167     if (NAMES) {
00168         MESSAGE('I',"");
00169         MESSAGE('I',"MOSAIC2MOSAIC_RESAMPL");
00170         MESSAGE('I',"");
00171         sprintf(msg," Input image:                  %s",in->text);
00172         MESSAGE('I',msg);
00173         sprintf(msg," Window size: lines:           %d",jsize);
00174         MESSAGE('I',msg);
00175         sprintf(msg,"              pixels:          %d",ksize);
00176         MESSAGE('I',msg);
00177         sprintf(msg," Subsample increment: lines:   %d",jinc);
00178         MESSAGE('I',msg);
00179         sprintf(msg,"                      pixels:  %d",kinc);
00180         MESSAGE('I',msg);
00181         MESSAGE('I'," ...............");
00182     }
00183 
00184     /* check input */
00185     if (!CHECKIMG_BYTE(in)) {
00186         MESSAGE('E'," Can't identify image.");
00187         goto the_end;
00188     } else if (jsize <= 0) {
00189         MESSAGE('E'," Number of lines in the averaging window must be greater than zero.");
00190         goto the_end;
00191     } else if (in->nlin < jsize) {
00192         MESSAGE('E'," Image size must be equal to or greater than window size in the line dimension.");
00193         goto the_end;
00194     } else if (ksize <= 0) {
00195         MESSAGE('E'," Number of pixels/line in the averaging window must be greater than zero.");
00196         goto the_end;
00197     } else if (in->npix < ksize) {
00198         MESSAGE('E'," Image size must be equal to or greater than window sizein the pixel dimension.");
00199         goto the_end;
00200     } else if (jinc <= 0) {
00201         MESSAGE('E'," Line subsample increment must be greater than zero.");
00202         goto the_end;
00203     } else if (kinc <= 0) {
00204         MESSAGE('E'," Pixel subsample increment must be greater than zero.");
00205         goto the_end;
00206     } else if (!CHECKIMG_MOSAIC_INDEX(index)) {
00207         MESSAGE('E'," Can't identify mosaic index.");
00208         goto the_end;
00209     } else if (index->npix != in->npix) {
00210         MESSAGE('E'," Mosaic image and index are not the same size.");
00211         goto the_end;
00212     }
00213 
00214     /* create mosaic image of appropriate size */
00215     nlin = (index->height_max-jsize)/jinc + 1;
00216     npix = (index->npix-ksize)/kinc + 1;
00217     if (!CHECKIMG_BYTE(*out)) GETMEM_BYTE(in->nbnd,nlin,npix,out);
00218     if (!*out) goto the_end;
00219 
00220     /* perform moving average and resample */
00221     for (i=0; i<in->nbnd; i++) {
00222         for (j=0; j<nlin; j++) {
00223             for (k=0; k<npix; k++) {
00224                 for (subsum=0.0,m=0; m<ksize; m++) {
00225                     for (l=0; l<jsize; l++) {
00226                         subsum += (double)in->data[i][j*jinc+l][k*kinc+m];
00227                     }
00228                 }
00229                 (*out)->data[i][j][k] = (PIXEL)(subsum/area);
00230             }
00231         }
00232     }
00233 
00234     the_end:
00235 
00236 }

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