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
00014 INSERT (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   )
00022 {
00023   register short i, j, k, elin, epix;
00024   char msg[SLEN];
00025 
00026   if (TIMES)
00027     TIMING (T_INSERT);
00028   if (NAMES)
00029     {
00030       MESSAGE ('I', "");
00031       MESSAGE ('I', "INSERT");
00032       MESSAGE ('I', "");
00033       sprintf (msg, " Background input image:   %s", in1->text);
00034       MESSAGE ('I', msg);
00035       sprintf (msg, " Foreground input image:   %s", in2->text);
00036       MESSAGE ('I', msg);
00037       sprintf (msg, " Offset: lines:            %d", jbgn);
00038       MESSAGE ('I', msg);
00039       sprintf (msg, "         pixels:           %d", kbgn);
00040       MESSAGE ('I', msg);
00041       MESSAGE ('I', " ...............");
00042     }
00043 
00044   /* check input */
00045   if (!CHECKIMG (in1))
00046     {
00047       MESSAGE ('E', " Can't identify background image.");
00048       goto the_end;
00049     }
00050   else if (!CHECKIMG (in2))
00051     {
00052       MESSAGE ('E', " Can't identify foreground image.");
00053       goto the_end;
00054     }
00055   else if (in1->nbnd != in2->nbnd)
00056     {
00057       MESSAGE ('E', " Number of bands must be identical in both images.");
00058       goto the_end;
00059     }
00060   else if (0 > jbgn || jbgn >= in1->nlin || jbgn + in2->nlin > in1->nlin)
00061     {
00062       MESSAGE ('E',
00063                " Foreground image must be located completely inside the background image in the line dimension.");
00064       goto the_end;
00065     }
00066   else if (0 > kbgn || kbgn >= in1->npix || kbgn + in2->npix > in1->npix)
00067     {
00068       MESSAGE ('E',
00069                " Foreground image must be located completely inside the background image in the pixel dimension.");
00070       goto the_end;
00071     }
00072 
00073   /* create image of appropriate size */
00074   if (!CHECKIMG (*out))
00075     GETMEM (in1->nbnd, in1->nlin, in1->npix, out);
00076   if (!*out)
00077     goto the_end;
00078 
00079   /* copy image */
00080   for (i = 0; i < in1->nbnd; i++)
00081     {
00082       for (j = 0; j < in1->nlin; j++)
00083         {
00084           for (k = 0; k < in1->npix; k++)
00085             {
00086               (*out)->data[i][j][k] = in1->data[i][j][k];
00087             }
00088         }
00089     }
00090 
00091   /* replace overlapping pixels */
00092   elin = min (in1->nlin, jbgn + in2->nlin);
00093   epix = min (in1->npix, kbgn + in2->npix);
00094   for (i = 0; i < in1->nbnd; i++)
00095     {
00096       for (j = jbgn; j < elin; j++)
00097         {
00098           for (k = kbgn; k < epix; k++)
00099             {
00100               (*out)->data[i][j][k] = in2->data[i][j - jbgn][k - kbgn];
00101             }
00102         }
00103     }
00104 
00105 the_end:
00106   if (TIMES)
00107     TIMING (T_EXIT);
00108 }

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