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 SIGMAP (
00016 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 ) { register short i, j, k;
00021     char  msg[SLEN];
00022     long  n, nlev, index, *count=0;
00023     PIXEL *table=0;
00024 
00025     if (TIMES) TIMING(T_SIGMAP);
00026     if (NAMES) {
00027         MESSAGE('I',"");
00028         MESSAGE('I',"SIGMAP");
00029         MESSAGE('I',"");
00030         sprintf(msg," Label map:        %s",in1->text);
00031         MESSAGE('I',msg);
00032         sprintf(msg," Original image:   %s",in2->text);
00033         MESSAGE('I',msg);
00034         MESSAGE('I'," ...............");
00035     }
00036 
00037     if (!CHECKIMG(in1)) {
00038         MESSAGE('E'," Can't identify image.");
00039         goto the_end;
00040     } else if (!CHECKIMG(in2)) {
00041         MESSAGE('E'," Can't identify image.");
00042         goto the_end;
00043     } else if (in1->nbnd != 1) {
00044         MESSAGE('E'," Classification label map must be single-band.");
00045         goto the_end;
00046     } else if (in1->nlin != in2->nlin) {
00047         MESSAGE('E'," Number of lines must be identical in all images.");
00048         goto the_end;
00049     } else if (in1->npix != in2->npix) {
00050         MESSAGE('E'," Number of pixels/line must be identical in all images.");
00051         goto the_end;
00052     }
00053 
00054     /* create image of appropriate size */
00055     if (!CHECKIMG(*out)) GETMEM(in2->nbnd,in2->nlin,in2->npix,out);
00056     if (!*out) goto the_end;
00057 
00058     /* allocate and initialize accumulator arrays */
00059     RANGE(in1);
00060     nlev = (long)in1->gmax - (long)in1->gmin + 1L;
00061     if (!(count=(long *)malloc(nlev*sizeof(long)))) {
00062         MESSAGE('E'," Memory request failed.");
00063         goto the_end;
00064     }
00065     if (!(table=(PIXEL *)malloc(nlev*(long)in2->nbnd*sizeof(PIXEL)))) {
00066         MESSAGE('E'," Memory request failed.");
00067         goto the_end;
00068     }
00069     for (n=0L; n<nlev; count[n++]=0L);
00070     for (n=0L; n<nlev*(long)in2->nbnd; table[n++]=(PIXEL)0);
00071 
00072     /* first pass: accumulate segment graylevels */
00073     for (j=0; j<in2->nlin; j++) {
00074         for (k=0; k<in2->npix; k++) {
00075             index = (long)in1->data[0][j][k] - (long)in1->gmin;
00076             count[index] += 1L;
00077             for (i=0; i<in2->nbnd; i++) {
00078                 table[(long)i*nlev+index] += in2->data[i][j][k];
00079             }
00080         }
00081     }
00082 
00083     /* calculate average segment graylevels */
00084     for (n=0L; n<nlev; n++) {
00085         if (count[n] > 0L) {
00086             for (i=0; i<in2->nbnd; i++) {
00087                 table[(long)i*nlev+n] /= (PIXEL)count[n];
00088             }
00089         }
00090     }
00091 
00092     /* second pass: replace segment labels with average graylevels */
00093     for (j=0; j<in2->nlin; j++) {
00094         for (k=0; k<in2->npix; k++) {
00095             index = (long)in1->data[0][j][k] - (long)in1->gmin;
00096             for (i=0; i<in2->nbnd; i++) {
00097                 (*out)->data[i][j][k] = table[(long)i*nlev+index];
00098             }
00099         }
00100     }
00101 
00102     the_end:
00103     if (count) free(count);
00104     if (table) free(table);
00105     if (TIMES) TIMING(T_EXIT);
00106 }

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