Main Page   Data Structures   File List   Data Fields   Globals  

tclSadie_ROI.c

Go to the documentation of this file.
00001 #include "sadie.h"
00002 
00003 
00004 
00005 void CREATE_ROI (
00006 IMAGE *in,      /*  I   Pointer to the image                                  */
00007 char  *name,    /*  I   Name of the region to create                          */
00008 int   xbgn,     /*  I   Starting x coord of region of interest                */
00009 int   ybgn,     /*  I   Starting y coord of region of interest                */
00010 int   xend,     /*  I   Ending x coord of region of interest                  */
00011 int   yend,     /*  I   Ending y coord of region of interest                  */
00012 short matrix,   /*  I   Indicates whether to compute cov/cor matrix           */
00013 short inc,      /*  I   Pixel subsample increment                             */
00014 short nlev      /*  I   > 0:    Number of bins in the histogram               */
00015                 /*      = 0:    Histogram is suppressed                       */
00016 /*----------------------------------------------------------------------------*/
00017 ) {   char msg[SLEN];
00018     short i, j, k;
00019     long  nval,n;
00020     PIXEL *gval=NULL;
00021     ROIPtr r=NULL, s=NULL;
00022     
00023 
00024 
00025     if (NAMES) {
00026         MESSAGE('I',"");
00027         MESSAGE('I',"CREATE_ROI");
00028         MESSAGE('I',"");
00029         sprintf(msg," Region Name:                %s",name);
00030         MESSAGE('I',msg);
00031         sprintf(msg," Region Start Point:         ( %d , %d )",xbgn+1,ybgn+1);
00032         MESSAGE('I',msg);
00033         sprintf(msg," Region End Point:           ( %d , %d )",xend+1,yend+1);
00034         MESSAGE('I',msg);
00035         sprintf(msg," Region Height:              %d pixels",(yend-ybgn)+1);
00036         MESSAGE('I',msg);
00037         sprintf(msg," Region Width:               %d pixels",(xend-xbgn)+1);
00038         MESSAGE('I',msg);
00039         MESSAGE('I'," ...............");
00040     }
00041     
00042     /* check input */
00043     if (!CHECKIMG(in)) {
00044         MESSAGE('E'," Can't identify input image.");
00045         goto the_end;
00046     }
00047     
00048     /* Determine the number of pixels in the region */
00049     nval = (long)((xend-xbgn)+1) * (long)((yend-ybgn)+1);
00050     
00051     /* Find the end of the ROI list */
00052     for (i = 1, s = in->regions; s != NULL; s = s->next, i++);
00053 
00054     /* Allocate space for the array of pixel values */
00055     if ((gval    = (PIXEL  *)malloc(in->nbnd*nval*sizeof(PIXEL))) != NULL  &&
00056         (r       = (ROIPtr  )malloc(sizeof(ROI))) != NULL  &&
00057         (r->name = (char   *)malloc((strlen((char *)name)+1)*sizeof(char))) != NULL  &&
00058         (r->zero = (long   *)malloc(in->nbnd*sizeof(long))) != NULL  &&
00059         (r->gmin = (PIXEL  *)malloc(in->nbnd*sizeof(PIXEL))) != NULL  &&
00060         (r->gmax = (PIXEL  *)malloc(in->nbnd*sizeof(PIXEL))) != NULL  &&
00061         (r->mean = (double *)malloc(in->nbnd*sizeof(double))) != NULL  &&
00062         (r->dev  = (double *)malloc(in->nbnd*sizeof(double))) != NULL  &&
00063         (!matrix  ||  (r->cov  = (double *)malloc(in->nbnd*in->nbnd*sizeof(double))) != NULL)  &&
00064         (!matrix  ||  (r->cor  = (double *)malloc(in->nbnd*in->nbnd*sizeof(double))) != NULL)) {
00065 
00066       strcpy(r->name,name);
00067       r->nval = nval;
00068 
00069       for (n = i = 0; i< in->nbnd; i++) {
00070         for (j=ybgn; j<= yend; j++) {
00071           for (k=xbgn; k<= xend; k++,n++) {
00072             gval[n] = in->data[i][j][k];
00073           }
00074         }
00075       }
00076       
00077       if (!matrix) {
00078         r->cov = NULL;
00079         r->cor = NULL;
00080       }
00081       ROISTATS(r->name,in->nbnd,nval,gval,inc,nlev,r->gmin,r->gmax,r->mean,r->dev,r->zero,r->cov,r->cor);
00082       r->next   = NULL;
00083       if (in->regions == NULL) {
00084         in->regions = r;
00085       } else {
00086         for (s = in->regions; s->next != NULL; s = s->next);
00087         s->next = r;
00088       }
00089       
00090       
00091 
00092     } else {
00093       MESSAGE('E',"Memory request failed.");                            
00094       goto the_end;                                                             
00095     }                                                                          
00096     
00097 
00098 
00099     the_end:
00100     if (gval) free(gval);
00101 }
00102 
00103 
00104 
00105 
00106 

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