Main Page   Data Structures   File List   Data Fields   Globals  

subsampl.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 extracts a subimage from an image.                         */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void
00013 SUBSAMPL (IMAGE * in,           /*  I   Pointer to the input image.                           */
00014           short ibgn,           /*  I   Number of the first band to be sampled.               */
00015           short jbgn,           /*  I   Number of the first line to be sampled.               */
00016           short kbgn,           /*  I   Number of the first pixel to be sampled.              */
00017           short iinc,           /*  I   Band increment during sampling.                       */
00018           short jinc,           /*  I   Line increment during sampling.                       */
00019           short kinc,           /*  I   Pixel increment during sampling.                      */
00020           short isize,          /*  I   Number of bands to be spanned.                        */
00021           short jsize,          /*  I   Number of lines to be spanned.                        */
00022           short ksize,          /*  I   Number of pixels/line to be spanned.                  */
00023           IMAGE ** out          /*  O   Address of a pointer to the output image.             */
00024 /*----------------------------------------------------------------------------*/
00025   )
00026 {
00027   register short i, j, k, l, m, n, nbnd, nlin, npix;
00028   char msg[SLEN];
00029 
00030   if (TIMES)
00031     TIMING (T_SUBSAMPL);
00032   if (NAMES)
00033     {
00034       MESSAGE ('I', "");
00035       MESSAGE ('I', "SUBSAMPL");
00036       MESSAGE ('I', "");
00037       sprintf (msg, " Input image:                                %s",
00038                in->text);
00039       MESSAGE ('I', msg);
00040       sprintf (msg, " From:                band, line, pixel:     %d, %d, %d",
00041                ibgn + 1, jbgn + 1, kbgn + 1);
00042       MESSAGE ('I', msg);
00043       sprintf (msg, " To:                  band, line, pixel:     %d, %d, %d",
00044                isize + ibgn, jsize + jbgn, ksize + kbgn);
00045       MESSAGE ('I', msg);
00046       sprintf (msg, " Subsample increment: bands, lines, pixels:  %d, %d, %d",
00047                iinc, jinc, kinc);
00048       MESSAGE ('I', msg);
00049       MESSAGE ('I', " ...............");
00050     }
00051 
00052   /* check input */
00053   if (!CHECKIMG (in))
00054     {
00055       MESSAGE ('E', " Can't identify image.");
00056       goto the_end;
00057     }
00058   else if (0 > ibgn || ibgn + isize > in->nbnd)
00059     {
00060       MESSAGE ('E',
00061                " Image to be sampled must be located completely inside input image in the band dimension.");
00062       goto the_end;
00063     }
00064   else if (0 > jbgn || jbgn + jsize > in->nlin)
00065     {
00066       MESSAGE ('E',
00067                " Image to be sampled must be located completely inside input image in the line dimension.");
00068       goto the_end;
00069     }
00070   else if (0 > kbgn || kbgn + ksize > in->npix)
00071     {
00072       MESSAGE ('E',
00073                " Image to be sampled must be located completely inside input image in the pixel dimension.");
00074       goto the_end;
00075     }
00076   else if (iinc <= 0)
00077     {
00078       MESSAGE ('E', " Band subsample increment must be greater than zero.");
00079       goto the_end;
00080     }
00081   else if (jinc <= 0)
00082     {
00083       MESSAGE ('E', " Line subsample increment must be greater than zero.");
00084       goto the_end;
00085     }
00086   else if (kinc <= 0)
00087     {
00088       MESSAGE ('E', " Pixel subsample increment must be greater than zero.");
00089       goto the_end;
00090     }
00091   else if (isize <= 0)
00092     {
00093       MESSAGE ('E',
00094                " Number of bands to be spanned must be greater than zero.");
00095       goto the_end;
00096     }
00097   else if (jsize <= 0)
00098     {
00099       MESSAGE ('E',
00100                " Number of lines to be spanned must be greater than zero.");
00101       goto the_end;
00102     }
00103   else if (ksize <= 0)
00104     {
00105       MESSAGE ('E',
00106                " Number of pixels/line to be spanned must be greater than zero.");
00107       goto the_end;
00108     }
00109 
00110   /* create image of appropriate size */
00111   nbnd = (short) ceil ((double) isize / (double) iinc);
00112   nlin = (short) ceil ((double) jsize / (double) jinc);
00113   npix = (short) ceil ((double) ksize / (double) kinc);
00114   if (!CHECKIMG (*out))
00115     GETMEM (nbnd, nlin, npix, out);
00116   if (!*out)
00117     goto the_end;
00118 
00119   /* extract subimage */
00120   for (i = 0, l = ibgn; i < nbnd && l < in->nbnd; i += 1, l += iinc)
00121     {
00122       for (j = 0, m = jbgn; j < nlin && m < in->nlin; j += 1, m += jinc)
00123         {
00124           for (k = 0, n = kbgn; k < npix && n < in->npix; k += 1, n += kinc)
00125             {
00126               (*out)->data[i][j][k] = in->data[l][m][n];
00127             }
00128         }
00129     }
00130 
00131 the_end:
00132   if (TIMES)
00133     TIMING (T_EXIT);
00134 }

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