Main Page   Data Structures   File List   Data Fields   Globals  

createtreesmosaic.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 #include        "sadie_byte.h"
00003 #include        "mosaic.h"
00004 #include        "trees.h"
00005 #include        "math.h"
00006 
00007 
00008 /*----------------------------------------------------------------------------*/
00009 /*-General Information--------------------------------------------------------*/
00010 /*                                                                            */
00011 /*   This function assembles multiple images into                             */
00012 /*   a single composite mosaic.                                               */
00013 /*                                                                            */
00014 /*----------------------------------------------------------------------------*/
00015 /*-Interface Information------------------------------------------------------*/
00016 void CREATETREESMOSAIC (
00017 char **imglist, /*  I   Pointer to an array[nimg] containing pointers
00018                         to the input image names.                             */
00019 int illum_adjust, /*  I   Indicates whether to adjust for illumination
00020                           distortion.                                         */
00021 char *illum_image,
00022 int nimg,       /*  I   Number of input images.                               */
00023 int nlin,       /*  I   Number of lines in the output mosaic.                 */
00024 int npix,       /*  I   Number of pixels/line in the output mosaic.           */
00025 int frame_nlin, /*  I   Number of lines in each frame.                        */
00026 int frame_npix, /*  I   Number of pixels/line in each frame.                  */
00027 int *xoff,      /*  I   Address of an array[nimg], containing the starting    */
00028                 /*      line coordinates of the input images in the output.   */
00029 int *yoff,      /*  I   Address of an array[nimg], containing the starting    */
00030                 /*      pixel coordinates of the input images in the output.  */
00031 PIXEL *bias,    /*  I   Address of an array[nimg], containing the bias        */
00032                 /*      offsets of the input images relative to the output.   */
00033 PIXEL *gain,    /*  I   Address of an array[nimg], containing the gain        */
00034                 /*      offsets of the input images relative to the output.   */
00035 PIXEL gmin,     /*  I   Minimum value for image pixels after gain/bias
00036                         adjustments.                                          */
00037 PIXEL factor,   /*  I   Factor to multiply times each pixels.                 */
00038 PIXEL glev,     /*  I   Graylevel to fill otherwise empty pixels.             */
00039 IMAGE_BYTE **out,/*  O   Address of a pointer to the output byte mosaic.      */
00040 MOSAIC_INDEX **index /*  O   Address of a pointer to the output mosaic index. */
00041 /*----------------------------------------------------------------------------*/
00042 ) { register int i, j, k, l, elin, epix, lin;
00043     int maxheight=0,top,bottom, height_actual;
00044     char msg[SLEN];
00045     IMAGE* inimg=NULL;
00046     IMAGE* illum=NULL;
00047     PIXEL pixval;
00048 
00049     int progmeter;
00050     double progress;
00051     double localpercent;
00052     double localprogress;
00053     int count, total, increment;
00054     int cancel=0;
00055 
00056     progmeter = ProgMeter_Create("Create TREES Mosaic");
00057     progress = 0.0;
00058 
00059 
00060     /* if (TIMES) TIMING(T_MOSAIC); */
00061 /*    if (NAMES) { */
00062         MESSAGE('I',"");
00063         MESSAGE('I',"----------");
00064         MESSAGE('I',"");
00065         MESSAGE('I',"CREATETREESMOSAIC");
00066         MESSAGE('I',"");
00067         sprintf(msg," Number of input images:  %d",nimg);
00068         MESSAGE('I',msg);
00069         sprintf(msg," Mosaic size: lines:      %d",nlin);
00070         MESSAGE('I',msg);
00071         sprintf(msg,"             pixels:      %d",npix);
00072         MESSAGE('I',msg);
00073         sprintf(msg," Frame size:  lines:      %d",frame_nlin);
00074         MESSAGE('I',msg);
00075         sprintf(msg,"             pixels:      %d",frame_npix);
00076         MESSAGE('I',msg);
00077         for (i=0; i<nimg; i++) {
00078             sprintf(msg," Image %d:   Offset: lines: %-4d pixels: %-4d",i,yoff[i],xoff[i]);
00079             MESSAGE('I',msg);
00080             sprintf(msg,"                   Contrast Adjustment: gain: %12.4e bias: %12.4e",gain[i],bias[i]);
00081             MESSAGE('I',msg);
00082         }
00083         sprintf(msg," Minimum input graylevel:       %12.4e",gmin);
00084         MESSAGE('I',msg);
00085         sprintf(msg," Factor:       %12.4e",factor);
00086         MESSAGE('I',msg);
00087         sprintf(msg," Fill graylevel:       %12.4e",glev);
00088         MESSAGE('I',msg);
00089         MESSAGE('I'," ...............");
00090         MESSAGE('I',"");
00091 /*    } */
00092 
00093     for (i=0; i<nimg; i++) {
00094         printf(" Image %d:   Offset: lines: %-4d pixels: %-4d \n",i,yoff[i],xoff[i]);
00095         printf("                   Contrast Adjustment: gain: %12.4e bias: %12.4e \n",gain[i],bias[i]);
00096     }
00097 
00098 
00099     /* create mosaic index of appropriate size */
00100     if (!CHECKIMG_MOSAIC_INDEX(*index)) GETMEM_MOSAIC_INDEX(nlin,npix,nimg,index);
00101     if (!*index) goto the_end;
00102     
00103     if (progmeter) {
00104         localpercent = 0.1;
00105         localprogress = 0.0;
00106         maxheight = 0;
00107         increment = rint((double)npix/5.0);
00108     }
00109     for (k=0; k<npix; k++) {
00110         if (progmeter) {
00111             if ((k%increment) == 0) {
00112                 localprogress = ((double)k/(double)npix)*100.0;
00113                 cancel = ProgMeter_Update(progmeter,(localprogress*localpercent)+progress);
00114                 if (cancel != 0) goto the_end;
00115             }
00116         }        
00117 
00118         top = nlin-1;
00119         bottom = 0;
00120         for (i=0; i<nimg; i++) {
00121             if ((xoff[i] <= k) && (xoff[i]+frame_npix > k)) {
00122                 if (yoff[i] < top) top = yoff[i];
00123                 if (yoff[i] + (frame_nlin-1) > bottom) bottom = yoff[i] + (frame_nlin-1);
00124             }
00125         }
00126         (*index)->voffset[k] = top;
00127         (*index)->vheight[k] = (bottom - top) + 1;
00128         (*index)->vstart[k] = (*index)->voffset[k];
00129         (*index)->vend[k] = (*index)->voffset[k] + (*index)->vheight[k] - 1;
00130         
00131         if ((*index)->vheight[k] > maxheight) maxheight = (*index)->vheight[k];
00132     }
00133     if (progmeter) {
00134         progress += localpercent * 100.0;
00135     }    
00136 
00137     (*index)->nframe = nimg;
00138     for (i=0; i<nimg; i++) {
00139         (*index)->frame[i].startx = xoff[i];
00140         (*index)->frame[i].endx = (xoff[i]+frame_npix)-1;
00141         (*index)->frame[i].starty = yoff[i];
00142         (*index)->frame[i].endy = (yoff[i]+frame_nlin)-1;
00143     }
00144 
00145 
00146     (*index)->roi->left[0] = 0;
00147     (*index)->roi->left[1] = 0;
00148     (*index)->roi->top[0] = 0;
00149     (*index)->roi->top[1] = (*index)->npix - 1;;
00150     height_actual = (abs((*index)->frame[nimg-1].starty - (*index)->frame[0].endy) >
00151                      abs((*index)->frame[nimg-1].endy - (*index)->frame[0].starty)     ?
00152                      abs((*index)->frame[nimg-1].starty - (*index)->frame[0].endy) :
00153                      abs((*index)->frame[nimg-1].endy - (*index)->frame[0].starty)    );
00154 
00155     (*index)->roi->right[0] = height_actual;
00156     (*index)->roi->right[1] = (*index)->npix - 1;;
00157     (*index)->roi->bottom[0] = height_actual;
00158     (*index)->roi->bottom[1] = 0;
00159     
00160     printf("index->nframe = %d\n",(*index)->nframe);
00161     for (i=0; i<(*index)->nframe; i++) {
00162         printf("Frame %d: (%d,%d) to (%d,%d)\n",i,(*index)->frame[i].startx,(*index)->frame[i].starty,(*index)->frame[i].endx,(*index)->frame[i].endy);
00163     }
00164 
00165     (*index)->height_max = maxheight;
00166     
00167     /* create mosaic image of appropriate size */
00168     if (!CHECKIMG_BYTE(*out)) GETMEM_BYTE((short)1,(short)maxheight,(short)npix,out);
00169     if (!*out) goto the_end;
00170 
00171     /* fill the background */
00172     if (progmeter) {
00173         localpercent = 0.2;
00174         localprogress = 0.0;
00175         count = 0;
00176         total = (*out)->npix * (*out)->nlin;
00177         increment = rint((double)total/10.0);
00178     }
00179     for (i=0; i<1; i++) {
00180         for (j=0; j<(*out)->nlin; j++) {
00181             for (k=0; k<(*out)->npix; k++) {
00182                 if (progmeter) {
00183                     count++;
00184                     if ((count%increment) == 0) {
00185                         localprogress = ((double)count/(double)total)*100.0;
00186                         cancel = ProgMeter_Update(progmeter,(localprogress*localpercent)+progress);
00187                         if (cancel != 0) goto the_end;
00188                     }
00189                 }
00190                 (*out)->data[i][j][k] = glev;
00191             }
00192         }
00193     }
00194     if (progmeter) {
00195         progress += localpercent * 100.0;
00196     }
00197 
00198     if (illum_adjust) {
00199         DISK2IMG (illum_image,-1,&illum);
00200     }
00201 
00202     /* assemble the mosaic */
00203     for (l=0; l<nimg; l++) {
00204         DISK2IMG (imglist[l],-1,&inimg);
00205         if (!CHECKIMG(inimg)) {        
00206             sprintf(msg," Cannot open image: %s",imglist[l]);
00207             MESSAGE('E',msg);
00208             goto the_end;
00209         } else if (inimg->nlin != frame_nlin || inimg->npix != frame_npix) {
00210             sprintf(msg," Input image %s dimensions do not match expected values.",imglist[l]);
00211             MESSAGE('E',msg);
00212             MESSAGE('E',"   Generated mosaic may be in error!");
00213         }
00214 
00215         elin = min(yoff[l]+inimg->nlin,nlin);
00216         epix = min(xoff[l]+inimg->npix,npix);
00217         if (progmeter) {
00218             localpercent = 0.7/(double)nimg;
00219             count = 0;
00220             total = (elin-yoff[l])*(epix-xoff[l]);
00221             increment = rint((double)total/3.0);
00222         }
00223         if (illum_adjust) {
00224             for (j=yoff[l]; j<elin; j++) {
00225                 for (k=xoff[l]; k<epix; k++) {
00226                     if (progmeter) {
00227                         count++;
00228                         if ((count%increment) == 0) {
00229                             localprogress = ((double)count/(double)total)*100.0;
00230                             ProgMeter_Update(progmeter,(localprogress*localpercent)+progress);
00231                         }
00232                     }
00233 
00234                     lin = j-(*index)->voffset[k];
00235                     if (lin>=0 && lin<(*out)->nlin) {
00236                         pixval = (PIXEL)((double)gain[l]*((double)inimg->data[0][j-yoff[l]][k-xoff[l]] / (double)illum->data[0][j-yoff[l]][k-xoff[l]])+(double)bias[l]);
00237                         (*out)->data[0][lin][k] = (PIXEL_BYTE)rnd((pixval-gmin)*factor) + (PIXEL_BYTE)1;
00238                     }
00239                 }
00240             }
00241         } else {
00242             for (j=yoff[l]; j<elin; j++) {
00243                 for (k=xoff[l]; k<epix; k++) {
00244                     if (progmeter) {
00245                         count++;
00246                         if ((count%increment) == 0) {
00247                             localprogress = ((double)count/(double)total)*100.0;
00248                             cancel = ProgMeter_Update(progmeter,(localprogress*localpercent)+progress);
00249                             if (cancel != 0) goto the_end;
00250                         }
00251                     }
00252 
00253                     lin = j-(*index)->voffset[k];
00254                     if (lin>=0 && lin<(*out)->nlin) {
00255                         (*out)->data[0][lin][k] = (PIXEL_BYTE)rnd((((double)gain[l]*(double)inimg->data[0][j-yoff[l]][k-xoff[l]]+(double)bias[l])-gmin)*(double)factor) + (PIXEL_BYTE)1;
00256                     }
00257                 }
00258             }
00259         }
00260         if (progmeter) {
00261             progress += localpercent * 100.0;
00262         }        
00263 
00264         RELMEM(inimg);
00265         inimg = NULL;
00266     }
00267 
00268     the_end:
00269     /* if (TIMES) TIMING(T_EXIT); */
00270     
00271     if (progmeter) {
00272         ProgMeter_Destroy(progmeter);
00273     }
00274 
00275     if (inimg) RELMEM(inimg);
00276     if (illum) RELMEM(illum);
00277     
00278     if (cancel != 0) {
00279         if (*out) RELMEM_BYTE(*out);
00280         *out = NULL;
00281         if (*index) RELMEM_MOSAIC_INDEX(*index);
00282         *index = NULL;
00283     }
00284     
00285     return;
00286 }

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