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