Main Page   Data Structures   File List   Data Fields   Globals  

contour.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 
00003 /*-Copyright Information------------------------------------------------------*/
00004 /* Copyright (c) 1988 by the University of Arizona Digital Image Analysis Lab */
00005 /*----------------------------------------------------------------------------*/
00006 /*-General Information--------------------------------------------------------*/
00007 /*                                                                            */
00008 /*   This function produces a contour map of an image.                        */
00009 /*                                                                            */
00010 /*----------------------------------------------------------------------------*/
00011 /*-Interface Information------------------------------------------------------*/
00012 void
00013 CONTOUR (IMAGE * in,            /*  I   Pointer to the input image.                           */
00014          short nlev,            /*  I   Number of contour lines.                              */
00015          double width,          /*  I   Width of contour lines, fraction less than one.       */
00016          IMAGE ** out           /*  O   Address of a pointer to the output image.             */
00017          /*      The input image may be overwritten (out = &in).       */
00018 /*----------------------------------------------------------------------------*/
00019   )
00020 {
00021   register short i, j, k;
00022   char msg[SLEN];
00023   double delta, class;
00024 
00025   if (TIMES)
00026     TIMING (T_CONTOUR);
00027   if (NAMES)
00028     {
00029       MESSAGE ('I', "");
00030       MESSAGE ('I', "CONTOUR");
00031       MESSAGE ('I', "");
00032       sprintf (msg, " Input image:               %s", in->text);
00033       MESSAGE ('I', msg);
00034       sprintf (msg, " Number of contour lines:   %d", nlev);
00035       MESSAGE ('I', msg);
00036       sprintf (msg, " Width of contour lines: %7.2f", width);
00037       MESSAGE ('I', msg);
00038       MESSAGE ('I', " ...............");
00039     }
00040 
00041   /* check input */
00042   if (!CHECKIMG (in))
00043     {
00044       MESSAGE ('E', " Can't identify image.");
00045       goto the_end;
00046     }
00047   else if (nlev <= 0)
00048     {
00049       MESSAGE ('E', " Number of contours must be greater than zero.");
00050       goto the_end;
00051     }
00052   else if (0.0 >= width || width >= 1.0)
00053     {
00054       MESSAGE ('E',
00055                " Width of contour lines must be greater than zero and less than one.");
00056       goto the_end;
00057     }
00058 
00059   /* create image of appropriate size */
00060   if (!CHECKIMG (*out))
00061     GETMEM (in->nbnd, in->nlin, in->npix, out);
00062   if (!*out)
00063     goto the_end;
00064 
00065   /* compute contours */
00066   RANGE (in);
00067   width = (1.0 - width) / 2.0;
00068   delta = (double) (in->gmax - in->gmin) / (double) nlev;
00069   for (i = 0; i < in->nbnd; i++)
00070     {
00071       for (j = 0; j < in->nlin; j++)
00072         {
00073           for (k = 0; k < in->npix; k++)
00074             {
00075               class = (double) (in->data[i][j][k] - in->gmin) / delta;
00076               (*out)->data[i][j][k] =
00077                 (PIXEL) (fabs (class - (double) rnd (class)) >
00078                          width ? SMAX : SMIN);
00079             }
00080         }
00081     }
00082   (*out)->gmin = (PIXEL) SMIN;
00083   (*out)->gmax = (PIXEL) SMAX;
00084 
00085 the_end:
00086   if (TIMES)
00087     TIMING (T_EXIT);
00088 }

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