00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 void
00013 SUBSAMPL (IMAGE * in,
00014 short ibgn,
00015 short jbgn,
00016 short kbgn,
00017 short iinc,
00018 short jinc,
00019 short kinc,
00020 short isize,
00021 short jsize,
00022 short ksize,
00023 IMAGE ** out
00024
00025 )
00026 {
00027 register short i, j, k, l, m, n, nbnd, nlin, npix;
00028 char msg[SLEN];
00029
00030 if (TIMES)
00031 TIMING (T_SUBSAMPL);
00032 if (NAMES)
00033 {
00034 MESSAGE ('I', "");
00035 MESSAGE ('I', "SUBSAMPL");
00036 MESSAGE ('I', "");
00037 sprintf (msg, " Input image: %s",
00038 in->text);
00039 MESSAGE ('I', msg);
00040 sprintf (msg, " From: band, line, pixel: %d, %d, %d",
00041 ibgn + 1, jbgn + 1, kbgn + 1);
00042 MESSAGE ('I', msg);
00043 sprintf (msg, " To: band, line, pixel: %d, %d, %d",
00044 isize + ibgn, jsize + jbgn, ksize + kbgn);
00045 MESSAGE ('I', msg);
00046 sprintf (msg, " Subsample increment: bands, lines, pixels: %d, %d, %d",
00047 iinc, jinc, kinc);
00048 MESSAGE ('I', msg);
00049 MESSAGE ('I', " ...............");
00050 }
00051
00052
00053 if (!CHECKIMG (in))
00054 {
00055 MESSAGE ('E', " Can't identify image.");
00056 goto the_end;
00057 }
00058 else if (0 > ibgn || ibgn + isize > in->nbnd)
00059 {
00060 MESSAGE ('E',
00061 " Image to be sampled must be located completely inside input image in the band dimension.");
00062 goto the_end;
00063 }
00064 else if (0 > jbgn || jbgn + jsize > in->nlin)
00065 {
00066 MESSAGE ('E',
00067 " Image to be sampled must be located completely inside input image in the line dimension.");
00068 goto the_end;
00069 }
00070 else if (0 > kbgn || kbgn + ksize > in->npix)
00071 {
00072 MESSAGE ('E',
00073 " Image to be sampled must be located completely inside input image in the pixel dimension.");
00074 goto the_end;
00075 }
00076 else if (iinc <= 0)
00077 {
00078 MESSAGE ('E', " Band subsample increment must be greater than zero.");
00079 goto the_end;
00080 }
00081 else if (jinc <= 0)
00082 {
00083 MESSAGE ('E', " Line subsample increment must be greater than zero.");
00084 goto the_end;
00085 }
00086 else if (kinc <= 0)
00087 {
00088 MESSAGE ('E', " Pixel subsample increment must be greater than zero.");
00089 goto the_end;
00090 }
00091 else if (isize <= 0)
00092 {
00093 MESSAGE ('E',
00094 " Number of bands to be spanned must be greater than zero.");
00095 goto the_end;
00096 }
00097 else if (jsize <= 0)
00098 {
00099 MESSAGE ('E',
00100 " Number of lines to be spanned must be greater than zero.");
00101 goto the_end;
00102 }
00103 else if (ksize <= 0)
00104 {
00105 MESSAGE ('E',
00106 " Number of pixels/line to be spanned must be greater than zero.");
00107 goto the_end;
00108 }
00109
00110
00111 nbnd = (short) ceil ((double) isize / (double) iinc);
00112 nlin = (short) ceil ((double) jsize / (double) jinc);
00113 npix = (short) ceil ((double) ksize / (double) kinc);
00114 if (!CHECKIMG (*out))
00115 GETMEM (nbnd, nlin, npix, out);
00116 if (!*out)
00117 goto the_end;
00118
00119
00120 for (i = 0, l = ibgn; i < nbnd && l < in->nbnd; i += 1, l += iinc)
00121 {
00122 for (j = 0, m = jbgn; j < nlin && m < in->nlin; j += 1, m += jinc)
00123 {
00124 for (k = 0, n = kbgn; k < npix && n < in->npix; k += 1, n += kinc)
00125 {
00126 (*out)->data[i][j][k] = in->data[l][m][n];
00127 }
00128 }
00129 }
00130
00131 the_end:
00132 if (TIMES)
00133 TIMING (T_EXIT);
00134 }