Main Page   Data Structures   File List   Data Fields   Globals  

segment.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 optionally resamples an image, creates a label map of      */
00009 /*   the image by segmenting it into regions of similar graylevels, and,      */
00010 /*   if the input image was resampled, refines the label map back to the      */
00011 /*   original resolution of the input image.                                  */
00012 /*                                                                            */
00013 /*----------------------------------------------------------------------------*/
00014 /*-Background Information-----------------------------------------------------*/
00015 /*                                                                            */
00016 /*   Mehldau, G.:                                                             */
00017 /*   "An Image Segmentation Algorithm."                                       */
00018 /*   University of Arizona, DIAL, Technical Report No. 90-3                   */
00019 /*                                                                            */
00020 /*----------------------------------------------------------------------------*/
00021 /*-Interface Information------------------------------------------------------*/
00022 void SEGMENT (
00023 IMAGE  *in,     /*  I   Pointer to the input image.                           */
00024 short  steps,   /*  I   Number of reduction steps.                            */
00025 double sigma,   /*  I   Greylevel variance threshold.                         */
00026 PIXEL  thresh,  /*  I   Greylevel difference threshold.                       */
00027 IMAGE  **out    /*  O   Address of a pointer to the output image.             */
00028 /*----------------------------------------------------------------------------*/
00029 ) { register short i;
00030     char  msg[SLEN];
00031     IMAGE **scratch=0, *img[3];
00032 
00033     if (TIMES) TIMING(T_SEGMENT);
00034     if (NAMES) {
00035         MESSAGE('I',"");
00036         MESSAGE('I',"SEGMENT");
00037         MESSAGE('I',"");
00038         sprintf(msg," Input image:                      %s",in->text);
00039         MESSAGE('I',msg);
00040         sprintf(msg," Graylevel difference threshold: %12.4e",thresh);
00041         MESSAGE('I',msg);
00042         sprintf(msg," Graylevel variance threshold:   %12.4e",sigma);
00043         MESSAGE('I',msg);
00044         sprintf(msg," Number of reduction steps:        %d",steps);
00045         MESSAGE('I',msg);
00046         MESSAGE('I'," ...............");
00047     }
00048 
00049     /* check input */
00050     if (!CHECKIMG(in)) {
00051         MESSAGE('E'," Can't identify image.");
00052         goto the_end;
00053     } else if (steps < 0) {
00054         MESSAGE('E'," Number of reduction steps must be equal to or greater than zero.");
00055         goto the_end;
00056     }
00057 
00058     /* allocate and initialize image vector */
00059     if (!(scratch=(IMAGE **)malloc((2*steps+2)*sizeof(IMAGE *)))) {
00060         MESSAGE('E'," Memory request failed.");
00061         goto the_end;
00062     }
00063     for (i=0; i<2*steps+2; scratch[i++]=0);
00064 
00065     /* reduce image */
00066     scratch[0] = in;
00067     for (i=0; i<steps; i++) {
00068         RESAMPL(scratch[i],2,2,2,2,scratch+i+1);
00069         if (ABORT  ||  !scratch[i+1]) goto the_end;
00070         sprintf(scratch[i+1]->text,"Scratch");
00071     }
00072 
00073     /* label image */
00074     LABEL(scratch[steps],sigma,thresh,scratch+steps+1);
00075     if (ABORT  ||  !scratch[steps+1]) goto the_end;
00076     sprintf(scratch[steps+1]->text,"Scratch");
00077 
00078     /* refine image */
00079     for (i=0; i<steps; i++) {
00080         img[0] = scratch[steps+i+1];
00081         img[1] = scratch[steps-i];
00082         img[2] = scratch[steps-i-1];
00083         REFINE(img,scratch+steps+i+2);
00084         if (ABORT  ||  !scratch[steps+i+2]) goto the_end;
00085         sprintf(scratch[steps+i+2]->text,"Scratch");
00086         RELMEM(scratch[steps-i]);
00087         scratch[steps-i] = 0;
00088     }
00089     *out = scratch[2*steps+1];
00090     
00091     the_end:
00092     if (scratch) {
00093         for (i=1; i<2*steps+1; i++) {
00094             if (scratch[i]) RELMEM(scratch[i]);
00095         }
00096         free(scratch);
00097     }
00098     if (TIMES) TIMING(T_EXIT);
00099 }

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