00001 #include "sadie.h"
00002 #include "proto.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 int GAINADJMOS (
00014 IMAGE **in,
00015
00016 int nimg,
00017 int nlin,
00018 int npix,
00019 int *jbgn,
00020
00021 int *kbgn,
00022
00023 PIXEL *bias,
00024
00025 PIXEL *gain,
00026
00027 PIXEL glev,
00028 IMAGE **out
00029
00030 ) { register int i, j, k, l, nbnd, elin, epix;
00031 char msg[SLEN];
00032
00033 if (TIMES) TIMING(T_MOSAIC);
00034 if (NAMES) {
00035 MESSAGE('I',"");
00036 MESSAGE('I',"----------");
00037 MESSAGE('I',"");
00038 MESSAGE('I',"GAINADJMOS");
00039 MESSAGE('I',"");
00040 sprintf(msg," Number of input images: %d",nimg);
00041 MESSAGE('I',msg);
00042 sprintf(msg," Image size: lines: %d",nlin);
00043 MESSAGE('I',msg);
00044 sprintf(msg," pixels: %d",npix);
00045 MESSAGE('I',msg);
00046 for (i=0; i<nimg; i++) {
00047 sprintf(msg," Image: %s Offset: lines: %-4d pixels: %-4d",in[i]->text,jbgn[i],kbgn[i]);
00048 MESSAGE('I',msg);
00049 sprintf(msg," Contrast Adjustment: gain: %12.4e bias: %12.4e",gain[i],bias[i]);
00050 MESSAGE('I',msg);
00051 }
00052 sprintf(msg," Fill graylevel: %12.4e",glev);
00053 MESSAGE('I',msg);
00054 MESSAGE('I'," ...............");
00055 MESSAGE('I',"");
00056 }
00057
00058
00059 for (i=0; i<nimg; i++) {
00060 if (!CHECKIMG(in[i])) {
00061 MESSAGE('E'," Can't identify input image(s).");
00062 goto the_end;
00063 }
00064 }
00065 for (nbnd=in[0]->nbnd,i=1; i<nimg; i++) {
00066 if (nbnd != in[i]->nbnd) {
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 if (0 > jbgn[i] || jbgn[i]+in[i]->nlin > nlin) {
00073 MESSAGE('E'," Input image(s) must be located completely inside output image in the line dimension.");
00074 goto the_end;
00075 } else if (0 > kbgn[i] || kbgn[i]+in[i]->npix > npix) {
00076 MESSAGE('E'," Input image(s) must be located completely inside output image in the pixel dimension.");
00077 goto the_end;
00078 }
00079 }
00080
00081
00082
00083 if (!CHECKIMG(*out)) GETMEM(nbnd,nlin,npix,out);
00084 if (!*out) goto the_end;
00085
00086
00087 for (i=0; i<nbnd; i++) {
00088 for (j=0; j<nlin; j++) {
00089 for (k=0; k<npix; k++) {
00090 (*out)->data[i][j][k] = glev;
00091 }
00092 }
00093 }
00094
00095
00096 for (i=0; i<nbnd; i++) {
00097 for (l=0; l<nimg; l++) {
00098 elin = min(jbgn[l]+in[l]->nlin,nlin);
00099 epix = min(kbgn[l]+in[l]->npix,npix);
00100 for (j=jbgn[l]; j<elin; j++) {
00101 for (k=kbgn[l]; k<epix; k++) {
00102 (*out)->data[i][j][k] = (PIXEL)((double)gain[l]*(double)in[l]->data[i][j-jbgn[l]][k-kbgn[l]]+(double)bias[l]);
00103 }
00104 }
00105 }
00106 }
00107
00108 the_end:
00109 if (TIMES) TIMING(T_EXIT);
00110 }