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
00014 RESAMPL (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   )
00022 {
00023   register short i, j, k, l, m, nlin, npix;
00024   char msg[SLEN];
00025   double subsum, area = (double) (jsize * ksize);
00026 
00027   if (TIMES)
00028     TIMING (T_RESAMPL);
00029   if (NAMES)
00030     {
00031       MESSAGE ('I', "");
00032       MESSAGE ('I', "RESAMPL");
00033       MESSAGE ('I', "");
00034       sprintf (msg, " Input image:                  %s", in->text);
00035       MESSAGE ('I', msg);
00036       sprintf (msg, " Window size: lines:           %d", jsize);
00037       MESSAGE ('I', msg);
00038       sprintf (msg, "              pixels:          %d", ksize);
00039       MESSAGE ('I', msg);
00040       sprintf (msg, " Subsample increment: lines:   %d", jinc);
00041       MESSAGE ('I', msg);
00042       sprintf (msg, "                      pixels:  %d", kinc);
00043       MESSAGE ('I', msg);
00044       MESSAGE ('I', " ...............");
00045     }
00046 
00047   /* check input */
00048   if (!CHECKIMG (in))
00049     {
00050       MESSAGE ('E', " Can't identify image.");
00051       goto the_end;
00052     }
00053   else if (jsize <= 0)
00054     {
00055       MESSAGE ('E',
00056                " Number of lines in the averaging window must be greater than zero.");
00057       goto the_end;
00058     }
00059   else if (in->nlin < jsize)
00060     {
00061       MESSAGE ('E',
00062                " Image size must be equal to or greater than window size in the line dimension.");
00063       goto the_end;
00064     }
00065   else if (ksize <= 0)
00066     {
00067       MESSAGE ('E',
00068                " Number of pixels/line in the averaging window must be greater than zero.");
00069       goto the_end;
00070     }
00071   else if (in->npix < ksize)
00072     {
00073       MESSAGE ('E',
00074                " Image size must be equal to or greater than window sizein the pixel dimension.");
00075       goto the_end;
00076     }
00077   else if (jinc <= 0)
00078     {
00079       MESSAGE ('E', " Line subsample increment must be greater than zero.");
00080       goto the_end;
00081     }
00082   else if (kinc <= 0)
00083     {
00084       MESSAGE ('E', " Pixel subsample increment must be greater than zero.");
00085       goto the_end;
00086     }
00087 
00088   /* create image of appropriate size */
00089   nlin = (in->nlin - jsize) / jinc + 1;
00090   npix = (in->npix - ksize) / kinc + 1;
00091   if (!CHECKIMG (*out))
00092     GETMEM (in->nbnd, nlin, npix, out);
00093   if (!*out)
00094     goto the_end;
00095 
00096   /* perform moving average and resample */
00097   for (i = 0; i < in->nbnd; i++)
00098     {
00099       for (j = 0; j < nlin; j++)
00100         {
00101           for (k = 0; k < npix; k++)
00102             {
00103               for (subsum = 0.0, l = 0; l < jsize; l++)
00104                 {
00105                   for (m = 0; m < ksize; m++)
00106                     {
00107                       subsum +=
00108                         (double) in->data[i][j * jinc + l][k * kinc + m];
00109                     }
00110                 }
00111               (*out)->data[i][j][k] = (PIXEL) (subsum / area);
00112             }
00113         }
00114     }
00115 
00116 the_end:
00117   if (TIMES)
00118     TIMING (T_EXIT);
00119 }

Generated on Sun May 18 15:36:13 2003 for tclSadie by doxygen1.3