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
00023 SEGMENT (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   )
00030 {
00031   register short i;
00032   char msg[SLEN];
00033   IMAGE **scratch = 0, *img[3];
00034 
00035   if (TIMES)
00036     TIMING (T_SEGMENT);
00037   if (NAMES)
00038     {
00039       MESSAGE ('I', "");
00040       MESSAGE ('I', "SEGMENT");
00041       MESSAGE ('I', "");
00042       sprintf (msg, " Input image:                      %s", in->text);
00043       MESSAGE ('I', msg);
00044       sprintf (msg, " Graylevel difference threshold: %12.4e", thresh);
00045       MESSAGE ('I', msg);
00046       sprintf (msg, " Graylevel variance threshold:   %12.4e", sigma);
00047       MESSAGE ('I', msg);
00048       sprintf (msg, " Number of reduction steps:        %d", steps);
00049       MESSAGE ('I', msg);
00050       MESSAGE ('I', " ...............");
00051     }
00052 
00053   /* check input */
00054   if (!CHECKIMG (in))
00055     {
00056       MESSAGE ('E', " Can't identify image.");
00057       goto the_end;
00058     }
00059   else if (steps < 0)
00060     {
00061       MESSAGE ('E',
00062                " Number of reduction steps must be equal to or greater than zero.");
00063       goto the_end;
00064     }
00065 
00066   /* allocate and initialize image vector */
00067   if (!(scratch = (IMAGE **) malloc ((2 * steps + 2) * sizeof (IMAGE *))))
00068     {
00069       MESSAGE ('E', " Memory request failed.");
00070       goto the_end;
00071     }
00072   for (i = 0; i < 2 * steps + 2; scratch[i++] = 0);
00073 
00074   /* reduce image */
00075   scratch[0] = in;
00076   for (i = 0; i < steps; i++)
00077     {
00078       RESAMPL (scratch[i], 2, 2, 2, 2, scratch + i + 1);
00079       if (ABORT || !scratch[i + 1])
00080         goto the_end;
00081       sprintf (scratch[i + 1]->text, "Scratch");
00082     }
00083 
00084   /* label image */
00085   LABEL (scratch[steps], sigma, thresh, scratch + steps + 1);
00086   if (ABORT || !scratch[steps + 1])
00087     goto the_end;
00088   sprintf (scratch[steps + 1]->text, "Scratch");
00089 
00090   /* refine image */
00091   for (i = 0; i < steps; i++)
00092     {
00093       img[0] = scratch[steps + i + 1];
00094       img[1] = scratch[steps - i];
00095       img[2] = scratch[steps - i - 1];
00096       REFINE (img, scratch + steps + i + 2);
00097       if (ABORT || !scratch[steps + i + 2])
00098         goto the_end;
00099       sprintf (scratch[steps + i + 2]->text, "Scratch");
00100       RELMEM (scratch[steps - i]);
00101       scratch[steps - i] = 0;
00102     }
00103   *out = scratch[2 * steps + 1];
00104 
00105 the_end:
00106   if (scratch)
00107     {
00108       for (i = 1; i < 2 * steps + 1; i++)
00109         {
00110           if (scratch[i])
00111             RELMEM (scratch[i]);
00112         }
00113       free (scratch);
00114     }
00115   if (TIMES)
00116     TIMING (T_EXIT);
00117 }

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