Main Page   Data Structures   File List   Data Fields   Globals  

mosaic.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 assembles multiple images into a single composite mosaic.  */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void
00013 MOSAIC (IMAGE ** in,            /*  I   Pointer to an array[nimg] containing pointers         */
00014         /*      to the input images.                                  */
00015         short nimg,             /*  I   Number of input images.                               */
00016         short nlin,             /*  I   Number of lines in the output image.                  */
00017         short npix,             /*  I   Number of pixels/line in the output image.            */
00018         short *jbgn,            /*  I   Address of an array[nimg], containing the starting    */
00019         /*      line coordinates of the input images in the output.   */
00020         short *kbgn,            /*  I   Address of an array[nimg], containing the starting    */
00021         /*      pixel coordinates of the input images in the output.  */
00022         PIXEL glev,             /*  I   Graylevel to fill otherwise empty pixels.             */
00023         IMAGE ** out            /*  O   Address of a pointer to the output image.             */
00024 /*----------------------------------------------------------------------------*/
00025   )
00026 {
00027   register short i, j, k, l, nbnd, elin, epix;
00028   char msg[SLEN];
00029 
00030   if (TIMES)
00031     TIMING (T_MOSAIC);
00032   if (NAMES)
00033     {
00034       MESSAGE ('I', "");
00035       MESSAGE ('I', "MOSAIC");
00036       MESSAGE ('I', "");
00037       sprintf (msg, " Number of input images: %d", nimg);
00038       MESSAGE ('I', msg);
00039       sprintf (msg, " Image size: lines:      %d", nlin);
00040       MESSAGE ('I', msg);
00041       sprintf (msg, "             pixels:     %d", npix);
00042       MESSAGE ('I', msg);
00043       for (i = 0; i < nimg; i++)
00044         {
00045           sprintf (msg, " Image: %s   Offset: lines: %-4d pixels: %-4d",
00046                    in[i]->text, jbgn[i], kbgn[i]);
00047           MESSAGE ('I', msg);
00048         }
00049       sprintf (msg, " Fill graylevel:       %12.4e", glev);
00050       MESSAGE ('I', msg);
00051       MESSAGE ('I', " ...............");
00052     }
00053 
00054   /* check input */
00055   for (i = 0; i < nimg; i++)
00056     {
00057       if (!CHECKIMG (in[i]))
00058         {
00059           MESSAGE ('E', " Can't identify input image(s).");
00060           goto the_end;
00061         }
00062     }
00063   for (nbnd = in[0]->nbnd, i = 1; i < nimg; i++)
00064     {
00065       if (nbnd != in[i]->nbnd)
00066         {
00067           MESSAGE ('E', " Number of bands must be identical in all images.");
00068           goto the_end;
00069         }
00070     }
00071   for (i = 0; i < nimg; i++)
00072     {
00073       if (0 > jbgn[i] || jbgn[i] + in[i]->nlin > nlin)
00074         {
00075           MESSAGE ('E',
00076                    " Input image(s) must be located completely inside output image in the line dimension.");
00077           goto the_end;
00078         }
00079       else if (0 > kbgn[i] || kbgn[i] + in[i]->npix > npix)
00080         {
00081           MESSAGE ('E',
00082                    " Input image(s) must be located completely inside output image in the pixel dimension.");
00083           goto the_end;
00084         }
00085     }
00086 
00087   /* create image of appropriate size */
00088   if (!CHECKIMG (*out))
00089     GETMEM (nbnd, nlin, npix, out);
00090   if (!*out)
00091     goto the_end;
00092 
00093   /* fill the background */
00094   for (i = 0; i < nbnd; i++)
00095     {
00096       for (j = 0; j < nlin; j++)
00097         {
00098           for (k = 0; k < npix; k++)
00099             {
00100               (*out)->data[i][j][k] = glev;
00101             }
00102         }
00103     }
00104 
00105   /* assemble the mosaic */
00106   for (i = 0; i < nbnd; i++)
00107     {
00108       for (l = 0; l < nimg; l++)
00109         {
00110           elin = min (jbgn[l] + in[l]->nlin, nlin);
00111           epix = min (kbgn[l] + in[l]->npix, npix);
00112           for (j = jbgn[l]; j < elin; j++)
00113             {
00114               for (k = kbgn[l]; k < epix; k++)
00115                 {
00116                   (*out)->data[i][j][k] =
00117                     in[l]->data[i][j - jbgn[l]][k - kbgn[l]];
00118                 }
00119             }
00120         }
00121     }
00122 
00123 the_end:
00124   if (TIMES)
00125     TIMING (T_EXIT);
00126 }

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