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 SUBSAMPL (
00013 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 ) { register short i, j, k, l, m, n, nbnd, nlin, npix;
00026     char msg[SLEN];
00027 
00028     if (TIMES) TIMING(T_SUBSAMPL);
00029     if (NAMES) {
00030         MESSAGE('I',"");
00031         MESSAGE('I',"SUBSAMPL");
00032         MESSAGE('I',"");
00033         sprintf(msg," Input image:                                %s",in->text);
00034         MESSAGE('I',msg);
00035         sprintf(msg," From:                band, line, pixel:     %d, %d, %d",ibgn+1,jbgn+1,kbgn+1);
00036         MESSAGE('I',msg);
00037         sprintf(msg," To:                  band, line, pixel:     %d, %d, %d",isize+ibgn,jsize+jbgn,ksize+kbgn);
00038         MESSAGE('I',msg);
00039         sprintf(msg," Subsample increment: bands, lines, pixels:  %d, %d, %d",iinc,jinc,kinc);
00040         MESSAGE('I',msg);
00041         MESSAGE('I'," ...............");
00042     }
00043 
00044     /* check input */
00045     if (!CHECKIMG(in)) {
00046         MESSAGE('E'," Can't identify image.");
00047         goto the_end;
00048     } else if (0 > ibgn  ||  ibgn+isize > in->nbnd) {
00049         MESSAGE('E'," Image to be sampled must be located completely inside input image in the band dimension.");
00050         goto the_end;
00051     } else if (0 > jbgn  ||  jbgn+jsize > in->nlin) {
00052         MESSAGE('E'," Image to be sampled must be located completely inside input image in the line dimension.");
00053         goto the_end;
00054     } else if (0 > kbgn  ||  kbgn+ksize > in->npix) {
00055         MESSAGE('E'," Image to be sampled must be located completely inside input image in the pixel dimension.");
00056         goto the_end;
00057     } else if (iinc <= 0) {
00058         MESSAGE('E'," Band subsample increment must be greater than zero.");
00059         goto the_end;
00060     } else if (jinc <= 0) {
00061         MESSAGE('E'," Line subsample increment must be greater than zero.");
00062         goto the_end;
00063     } else if (kinc <= 0) {
00064         MESSAGE('E'," Pixel subsample increment must be greater than zero.");
00065         goto the_end;
00066     } else if (isize <= 0) {
00067         MESSAGE('E'," Number of bands to be spanned must be greater than zero.");
00068         goto the_end;
00069     } else if (jsize <= 0) {
00070         MESSAGE('E'," Number of lines to be spanned must be greater than zero.");
00071         goto the_end;
00072     } else if (ksize <= 0) {
00073         MESSAGE('E'," Number of pixels/line to be spanned must be greater than zero.");
00074         goto the_end;
00075     }
00076 
00077     /* create image of appropriate size */
00078     nbnd = (short)ceil((double)isize/(double)iinc);
00079     nlin = (short)ceil((double)jsize/(double)jinc);
00080     npix = (short)ceil((double)ksize/(double)kinc);
00081     if (!CHECKIMG(*out)) GETMEM(nbnd,nlin,npix,out);
00082     if (!*out) goto the_end;
00083 
00084     /* extract subimage */
00085     for (i=0,l=ibgn; i<nbnd && l<in->nbnd; i+=1,l+=iinc) {
00086         for (j=0,m=jbgn; j<nlin && m<in->nlin; j+=1,m+=jinc) {
00087             for (k=0,n=kbgn; k<npix && n<in->npix; k+=1,n+=kinc) {
00088                 (*out)->data[i][j][k] = in->data[l][m][n];
00089             }
00090         }
00091     }
00092 
00093     the_end:
00094     if (TIMES) TIMING(T_EXIT);
00095 }

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