00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 void
00013 MOSAIC (IMAGE ** in,
00014
00015 short nimg,
00016 short nlin,
00017 short npix,
00018 short *jbgn,
00019
00020 short *kbgn,
00021
00022 PIXEL glev,
00023 IMAGE ** out
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
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
00088 if (!CHECKIMG (*out))
00089 GETMEM (nbnd, nlin, npix, out);
00090 if (!*out)
00091 goto the_end;
00092
00093
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
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 }