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

Generated on Sun May 18 15:36:19 2003 for tclSadie by doxygen1.3