Main Page   Data Structures   File List   Data Fields   Globals  

gainadjmos.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 #include        "proto.h"
00003 
00004 /*----------------------------------------------------------------------------*/
00005 /*-General Information--------------------------------------------------------*/
00006 /*                                                                            */
00007 /*   This function adjusts the gain of, and assembles multiple images into    */
00008 /*   a single composite mosaic.  It is based on MOSAIC and TFLINEAR from      */
00009 /*   the SADIE library.                                                       */
00010 /*                                                                            */
00011 /*----------------------------------------------------------------------------*/
00012 /*-Interface Information------------------------------------------------------*/
00013 int GAINADJMOS (
00014 IMAGE **in,     /*  I   Pointer to an array[nimg] containing pointers         */
00015                 /*      to the input images.                                  */
00016 int nimg,       /*  I   Number of input images.                               */
00017 int nlin,       /*  I   Number of lines in the output image.                  */
00018 int npix,       /*  I   Number of pixels/line in the output image.            */
00019 int *jbgn,      /*  I   Address of an array[nimg], containing the starting    */
00020                 /*      line coordinates of the input images in the output.   */
00021 int *kbgn,      /*  I   Address of an array[nimg], containing the starting    */
00022                 /*      pixel coordinates of the input images in the output.  */
00023 PIXEL *bias,    /*  I   Address of an array[nimg], containing the bias        */
00024                 /*      offsets of the input images relative to the output.   */
00025 PIXEL *gain,    /*  I   Address of an array[nimg], containing the gain        */
00026                 /*      offsets of the input images relative to the output.   */
00027 PIXEL glev,     /*  I   Graylevel to fill otherwise empty pixels.             */
00028 IMAGE **out     /*  O   Address of a pointer to the output image.             */
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     /* check input */
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     /* create image of appropriate size */
00083     if (!CHECKIMG(*out)) GETMEM(nbnd,nlin,npix,out);
00084     if (!*out) goto the_end;
00085 
00086     /* fill the background */
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     /* assemble the mosaic */
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 }

Generated on Wed Apr 9 08:56:06 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002