00001 #include "sadie.h"
00002 #include "sadie_byte.h"
00003 #include "mosaic.h"
00004 #include "math.h"
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 void MOSAIC_BYTE_RESAMPL (
00019 IMAGE_BYTE *in,
00020 MOSAIC_INDEX *index,
00021 short jsize,
00022 short ksize,
00023 short jinc,
00024 short kinc,
00025 IMAGE **out
00026
00027 ) { register int i, j, k, l, m, nlin, npix, pix, lin;
00028 char msg[SLEN];
00029 double subsum, area=(double)(jsize*ksize);
00030
00031 int progmeter;
00032 double progress;
00033 int count, total, increment;
00034 int cancel=0;
00035
00036 progmeter = ProgMeter_Create("Resample Byte Mosaic");
00037 progress = 0.0;
00038
00039
00040
00041 if (NAMES) {
00042 MESSAGE('I',"");
00043 MESSAGE('I',"MOSAIC_BYTE_RESAMPL");
00044 MESSAGE('I',"");
00045 sprintf(msg," Input image: %s",in->text);
00046 MESSAGE('I',msg);
00047 sprintf(msg," Window size: lines: %d",jsize);
00048 MESSAGE('I',msg);
00049 sprintf(msg," pixels: %d",ksize);
00050 MESSAGE('I',msg);
00051 sprintf(msg," Subsample increment: lines: %d",jinc);
00052 MESSAGE('I',msg);
00053 sprintf(msg," pixels: %d",kinc);
00054 MESSAGE('I',msg);
00055 MESSAGE('I'," ...............");
00056 }
00057
00058
00059 if (!CHECKIMG_BYTE(in)) {
00060 MESSAGE('E'," Can't identify image.");
00061 goto the_end;
00062 } else if (jsize <= 0) {
00063 MESSAGE('E'," Number of lines in the averaging window must be greater than zero.");
00064 goto the_end;
00065 } else if (in->nlin < jsize) {
00066 MESSAGE('E'," Image size must be equal to or greater than window size in the line dimension.");
00067 goto the_end;
00068 } else if (ksize <= 0) {
00069 MESSAGE('E'," Number of pixels/line in the averaging window must be greater than zero.");
00070 goto the_end;
00071 } else if (in->npix < ksize) {
00072 MESSAGE('E'," Image size must be equal to or greater than window sizein the pixel dimension.");
00073 goto the_end;
00074 } else if (jinc <= 0) {
00075 MESSAGE('E'," Line subsample increment must be greater than zero.");
00076 goto the_end;
00077 } else if (kinc <= 0) {
00078 MESSAGE('E'," Pixel subsample increment must be greater than zero.");
00079 goto the_end;
00080 } else if (!CHECKIMG_MOSAIC_INDEX(index)) {
00081 MESSAGE('E'," Can't identify mosaic index.");
00082 goto the_end;
00083 } else if (index->npix != in->npix) {
00084 MESSAGE('E'," Mosaic image and index are not the same size.");
00085 goto the_end;
00086 }
00087
00088
00089 nlin = (index->nlin-jsize)/jinc + 1;
00090 npix = (index->npix-ksize)/kinc + 1;
00091 printf("index nlin = %d, index npix = %d\n",index->nlin,index->npix);
00092 printf("nlin = %d, npix = %d\n",nlin,npix);
00093 if (!CHECKIMG(*out)) GETMEM(in->nbnd,nlin,npix,out);
00094 if (!*out) goto the_end;
00095
00096
00097 if (progmeter) {
00098 count = 0;
00099 total = in->nbnd * (npix * nlin);
00100 increment = rint((double)total/20.0);
00101 }
00102 for (i=0; i<in->nbnd; i++) {
00103 for (j=0; j<nlin; j++) {
00104 for (k=0; k<npix; k++) {
00105 if (progmeter) {
00106 count++;
00107 if ((count%increment) == 0) {
00108 progress = ((double)count/(double)total)*100.0;
00109 cancel = ProgMeter_Update(progmeter,progress);
00110 if (cancel != 0) goto the_end;
00111 }
00112 }
00113
00114 for (subsum=0.0,m=0; m<ksize; m++) {
00115 pix = k*kinc+m;
00116 for (l=0; l<jsize; l++) {
00117 lin = (j*jinc+l)-index->voffset[pix];
00118 if (0<lin && lin<in->nlin) {
00119 subsum += (double)in->data[i][lin][k*kinc+m];
00120 }
00121 }
00122 }
00123 (*out)->data[i][j][k] = (PIXEL)(subsum/area);
00124 }
00125 }
00126 }
00127
00128 the_end:
00129 if (TIMES) TIMING(T_EXIT);
00130
00131 if (progmeter) {
00132 ProgMeter_Destroy(progmeter);
00133 }
00134 if (cancel != 0) {
00135 if (*out) RELMEM(*out);
00136 *out = NULL;
00137 }
00138
00139 }
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153 void MOSAIC2MOSAIC_RESAMPL (
00154 IMAGE_BYTE *in,
00155 MOSAIC_INDEX *index,
00156 short jsize,
00157 short ksize,
00158 short jinc,
00159 short kinc,
00160 IMAGE_BYTE **out
00161
00162 ) { register int i, j, k, l, m, nlin, npix;
00163 char msg[SLEN];
00164 double subsum, area=(double)(jsize*ksize);
00165
00166
00167 if (NAMES) {
00168 MESSAGE('I',"");
00169 MESSAGE('I',"MOSAIC2MOSAIC_RESAMPL");
00170 MESSAGE('I',"");
00171 sprintf(msg," Input image: %s",in->text);
00172 MESSAGE('I',msg);
00173 sprintf(msg," Window size: lines: %d",jsize);
00174 MESSAGE('I',msg);
00175 sprintf(msg," pixels: %d",ksize);
00176 MESSAGE('I',msg);
00177 sprintf(msg," Subsample increment: lines: %d",jinc);
00178 MESSAGE('I',msg);
00179 sprintf(msg," pixels: %d",kinc);
00180 MESSAGE('I',msg);
00181 MESSAGE('I'," ...............");
00182 }
00183
00184
00185 if (!CHECKIMG_BYTE(in)) {
00186 MESSAGE('E'," Can't identify image.");
00187 goto the_end;
00188 } else if (jsize <= 0) {
00189 MESSAGE('E'," Number of lines in the averaging window must be greater than zero.");
00190 goto the_end;
00191 } else if (in->nlin < jsize) {
00192 MESSAGE('E'," Image size must be equal to or greater than window size in the line dimension.");
00193 goto the_end;
00194 } else if (ksize <= 0) {
00195 MESSAGE('E'," Number of pixels/line in the averaging window must be greater than zero.");
00196 goto the_end;
00197 } else if (in->npix < ksize) {
00198 MESSAGE('E'," Image size must be equal to or greater than window sizein the pixel dimension.");
00199 goto the_end;
00200 } else if (jinc <= 0) {
00201 MESSAGE('E'," Line subsample increment must be greater than zero.");
00202 goto the_end;
00203 } else if (kinc <= 0) {
00204 MESSAGE('E'," Pixel subsample increment must be greater than zero.");
00205 goto the_end;
00206 } else if (!CHECKIMG_MOSAIC_INDEX(index)) {
00207 MESSAGE('E'," Can't identify mosaic index.");
00208 goto the_end;
00209 } else if (index->npix != in->npix) {
00210 MESSAGE('E'," Mosaic image and index are not the same size.");
00211 goto the_end;
00212 }
00213
00214
00215 nlin = (index->height_max-jsize)/jinc + 1;
00216 npix = (index->npix-ksize)/kinc + 1;
00217 if (!CHECKIMG_BYTE(*out)) GETMEM_BYTE(in->nbnd,nlin,npix,out);
00218 if (!*out) goto the_end;
00219
00220
00221 for (i=0; i<in->nbnd; i++) {
00222 for (j=0; j<nlin; j++) {
00223 for (k=0; k<npix; k++) {
00224 for (subsum=0.0,m=0; m<ksize; m++) {
00225 for (l=0; l<jsize; l++) {
00226 subsum += (double)in->data[i][j*jinc+l][k*kinc+m];
00227 }
00228 }
00229 (*out)->data[i][j][k] = (PIXEL)(subsum/area);
00230 }
00231 }
00232 }
00233
00234 the_end:
00235
00236 }