Main Page   Data Structures   File List   Data Fields   Globals  

sigmap.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1990 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This function creates a class signature map from the original image      */
00009 /*   and a class label map produced by a classification or segmentation       */
00010 /*   function.  The signature map consists of the average graylevel for       */
00011 /*   each labeled segment in the image.                                       */
00012 /*                                                                            */
00013 /*----------------------------------------------------------------------------*/
00014 /*-Interface Information------------------------------------------------------*/
00015 void
00016 SIGMAP (IMAGE * in1,            /*  I   Pointer to the classification label map.              */
00017         IMAGE * in2,            /*  I   Pointer to the original image.                        */
00018         IMAGE ** out            /*  O   Address of a pointer to the output signature map.     */
00019 /*----------------------------------------------------------------------------*/
00020   )
00021 {
00022   register short i, j, k;
00023   char msg[SLEN];
00024   long n, nlev, index, *count = 0;
00025   PIXEL *table = 0;
00026 
00027   if (TIMES)
00028     TIMING (T_SIGMAP);
00029   if (NAMES)
00030     {
00031       MESSAGE ('I', "");
00032       MESSAGE ('I', "SIGMAP");
00033       MESSAGE ('I', "");
00034       sprintf (msg, " Label map:        %s", in1->text);
00035       MESSAGE ('I', msg);
00036       sprintf (msg, " Original image:   %s", in2->text);
00037       MESSAGE ('I', msg);
00038       MESSAGE ('I', " ...............");
00039     }
00040 
00041   if (!CHECKIMG (in1))
00042     {
00043       MESSAGE ('E', " Can't identify image.");
00044       goto the_end;
00045     }
00046   else if (!CHECKIMG (in2))
00047     {
00048       MESSAGE ('E', " Can't identify image.");
00049       goto the_end;
00050     }
00051   else if (in1->nbnd != 1)
00052     {
00053       MESSAGE ('E', " Classification label map must be single-band.");
00054       goto the_end;
00055     }
00056   else if (in1->nlin != in2->nlin)
00057     {
00058       MESSAGE ('E', " Number of lines must be identical in all images.");
00059       goto the_end;
00060     }
00061   else if (in1->npix != in2->npix)
00062     {
00063       MESSAGE ('E',
00064                " Number of pixels/line must be identical in all images.");
00065       goto the_end;
00066     }
00067 
00068   /* create image of appropriate size */
00069   if (!CHECKIMG (*out))
00070     GETMEM (in2->nbnd, in2->nlin, in2->npix, out);
00071   if (!*out)
00072     goto the_end;
00073 
00074   /* allocate and initialize accumulator arrays */
00075   RANGE (in1);
00076   nlev = (long) in1->gmax - (long) in1->gmin + 1L;
00077   if (!(count = (long *) malloc (nlev * sizeof (long))))
00078     {
00079       MESSAGE ('E', " Memory request failed.");
00080       goto the_end;
00081     }
00082   if (!(table = (PIXEL *) malloc (nlev * (long) in2->nbnd * sizeof (PIXEL))))
00083     {
00084       MESSAGE ('E', " Memory request failed.");
00085       goto the_end;
00086     }
00087   for (n = 0L; n < nlev; count[n++] = 0L);
00088   for (n = 0L; n < nlev * (long) in2->nbnd; table[n++] = (PIXEL) 0);
00089 
00090   /* first pass: accumulate segment graylevels */
00091   for (j = 0; j < in2->nlin; j++)
00092     {
00093       for (k = 0; k < in2->npix; k++)
00094         {
00095           index = (long) in1->data[0][j][k] - (long) in1->gmin;
00096           count[index] += 1L;
00097           for (i = 0; i < in2->nbnd; i++)
00098             {
00099               table[(long) i * nlev + index] += in2->data[i][j][k];
00100             }
00101         }
00102     }
00103 
00104   /* calculate average segment graylevels */
00105   for (n = 0L; n < nlev; n++)
00106     {
00107       if (count[n] > 0L)
00108         {
00109           for (i = 0; i < in2->nbnd; i++)
00110             {
00111               table[(long) i * nlev + n] /= (PIXEL) count[n];
00112             }
00113         }
00114     }
00115 
00116   /* second pass: replace segment labels with average graylevels */
00117   for (j = 0; j < in2->nlin; j++)
00118     {
00119       for (k = 0; k < in2->npix; k++)
00120         {
00121           index = (long) in1->data[0][j][k] - (long) in1->gmin;
00122           for (i = 0; i < in2->nbnd; i++)
00123             {
00124               (*out)->data[i][j][k] = table[(long) i * nlev + index];
00125             }
00126         }
00127     }
00128 
00129 the_end:
00130   if (count)
00131     free (count);
00132   if (table)
00133     free (table);
00134   if (TIMES)
00135     TIMING (T_EXIT);
00136 }

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