Main Page   Data Structures   File List   Data Fields   Globals  

resampl.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 moving window average on an image, and          */
00009 /*   resamples the new image at specified intervals.                          */
00010 /*                                                                            */
00011 /*----------------------------------------------------------------------------*/
00012 /*-Interface Information------------------------------------------------------*/
00013 void RESAMPL (
00014 IMAGE *in,      /*  I   Pointer to the input image.                           */
00015 short jsize,    /*  I   Number of lines in the window.                        */
00016 short ksize,    /*  I   Number of pixels/line in the window.                  */
00017 short jinc,     /*  I   Line resampling increment.                            */
00018 short kinc,     /*  I   Pixels/line resampling increment.                     */
00019 IMAGE **out     /*  O   Address of a pointer to the output image.             */
00020 /*----------------------------------------------------------------------------*/
00021 ) { register short i, j, k, l, m, nlin, npix;
00022     char   msg[SLEN];
00023     double subsum, area=(double)(jsize*ksize);
00024 
00025     if (TIMES) TIMING(T_RESAMPL);
00026     if (NAMES) {
00027         MESSAGE('I',"");
00028         MESSAGE('I',"RESAMPL");
00029         MESSAGE('I',"");
00030         sprintf(msg," Input image:                  %s",in->text);
00031         MESSAGE('I',msg);
00032         sprintf(msg," Window size: lines:           %d",jsize);
00033         MESSAGE('I',msg);
00034         sprintf(msg,"              pixels:          %d",ksize);
00035         MESSAGE('I',msg);
00036         sprintf(msg," Subsample increment: lines:   %d",jinc);
00037         MESSAGE('I',msg);
00038         sprintf(msg,"                      pixels:  %d",kinc);
00039         MESSAGE('I',msg);
00040         MESSAGE('I'," ...............");
00041     }
00042 
00043     /* check input */
00044     if (!CHECKIMG(in)) {
00045         MESSAGE('E'," Can't identify image.");
00046         goto the_end;
00047     } else if (jsize <= 0) {
00048         MESSAGE('E'," Number of lines in the averaging window must be greater than zero.");
00049         goto the_end;
00050     } else if (in->nlin < jsize) {
00051         MESSAGE('E'," Image size must be equal to or greater than window size in the line dimension.");
00052         goto the_end;
00053     } else if (ksize <= 0) {
00054         MESSAGE('E'," Number of pixels/line in the averaging window must be greater than zero.");
00055         goto the_end;
00056     } else if (in->npix < ksize) {
00057         MESSAGE('E'," Image size must be equal to or greater than window sizein the pixel dimension.");
00058         goto the_end;
00059     } else if (jinc <= 0) {
00060         MESSAGE('E'," Line subsample increment must be greater than zero.");
00061         goto the_end;
00062     } else if (kinc <= 0) {
00063         MESSAGE('E'," Pixel subsample increment must be greater than zero.");
00064         goto the_end;
00065     }
00066 
00067     /* create image of appropriate size */
00068     nlin = (in->nlin-jsize)/jinc + 1;
00069     npix = (in->npix-ksize)/kinc + 1;
00070     if (!CHECKIMG(*out)) GETMEM(in->nbnd,nlin,npix,out);
00071     if (!*out) goto the_end;
00072 
00073     /* perform moving average and resample */
00074     for (i=0; i<in->nbnd; i++) {
00075         for (j=0; j<nlin; j++) {
00076             for (k=0; k<npix; k++) {
00077                 for (subsum=0.0,l=0; l<jsize; l++) {
00078                     for (m=0; m<ksize; m++) {
00079                         subsum += (double)in->data[i][j*jinc+l][k*kinc+m];
00080                     }
00081                 }
00082                 (*out)->data[i][j][k] = (PIXEL)(subsum/area);
00083             }
00084         }
00085     }
00086 
00087     the_end:
00088     if (TIMES) TIMING(T_EXIT);
00089 }

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