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