Main Page   Data Structures   File List   Data Fields   Globals  

insert.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 inserts one image into another by replacing overlapping    */
00009 /*   pixels in the "background" image with those from the "foreground" image. */
00010 /*                                                                            */
00011 /*----------------------------------------------------------------------------*/
00012 /*-Interface Information------------------------------------------------------*/
00013 void INSERT (
00014 IMAGE *in1,     /*  I   Pointer to the background image.                      */
00015 IMAGE *in2,     /*  I   Pointer to the foreground image.                      */
00016 short jbgn,     /*  I   Line offset in the background image.                  */
00017 short kbgn,     /*  I   Pixel offset in the background image.                 */
00018 IMAGE **out     /*  O   Address of a pointer to the output image.             */
00019                 /*      The background image may be overwritten (out = &in1). */
00020 /*----------------------------------------------------------------------------*/
00021 ) { register short i, j, k, elin, epix;
00022     char msg[SLEN];
00023 
00024     if (TIMES) TIMING(T_INSERT);
00025     if (NAMES) {
00026         MESSAGE('I',"");
00027         MESSAGE('I',"INSERT");
00028         MESSAGE('I',"");
00029         sprintf(msg," Background input image:   %s",in1->text);
00030         MESSAGE('I',msg);
00031         sprintf(msg," Foreground input image:   %s",in2->text);
00032         MESSAGE('I',msg);
00033         sprintf(msg," Offset: lines:            %d",jbgn);
00034         MESSAGE('I',msg);
00035         sprintf(msg,"         pixels:           %d",kbgn);
00036         MESSAGE('I',msg);
00037         MESSAGE('I'," ...............");
00038     }
00039 
00040     /* check input */
00041     if (!CHECKIMG(in1)) {
00042         MESSAGE('E'," Can't identify background image.");
00043         goto the_end;
00044     } else if (!CHECKIMG(in2)) {
00045         MESSAGE('E'," Can't identify foreground image.");
00046         goto the_end;
00047     } else if (in1->nbnd != in2->nbnd) {
00048         MESSAGE('E'," Number of bands must be identical in both images.");
00049         goto the_end;
00050     } else if (0 > jbgn  ||  jbgn >= in1->nlin  ||  jbgn+in2->nlin > in1->nlin) {
00051         MESSAGE('E'," Foreground image must be located completely inside the background image in the line dimension.");
00052         goto the_end;
00053     } else if (0 > kbgn  ||  kbgn >= in1->npix  ||  kbgn+in2->npix > in1->npix) {
00054         MESSAGE('E'," Foreground image must be located completely inside the background image in the pixel dimension.");
00055         goto the_end;
00056     }
00057 
00058     /* create image of appropriate size */
00059     if (!CHECKIMG(*out)) GETMEM(in1->nbnd,in1->nlin,in1->npix,out);
00060     if (!*out) goto the_end;
00061 
00062     /* copy image */
00063     for (i=0; i<in1->nbnd; i++) {
00064         for (j=0; j<in1->nlin; j++) {
00065             for (k=0; k<in1->npix; k++) {
00066                 (*out)->data[i][j][k] = in1->data[i][j][k];
00067             }
00068         }
00069     }
00070 
00071     /* replace overlapping pixels */
00072     elin = min(in1->nlin,jbgn+in2->nlin);
00073     epix = min(in1->npix,kbgn+in2->npix);
00074     for (i=0; i<in1->nbnd; i++) {
00075         for (j=jbgn; j<elin; j++) {
00076             for (k=kbgn; k<epix; k++) {
00077                 (*out)->data[i][j][k] = in2->data[i][j-jbgn][k-kbgn];
00078             }
00079         }
00080     }
00081 
00082     the_end:
00083     if (TIMES) TIMING(T_EXIT);
00084 }

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