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 CONTOUR (
00013 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 ) { register short i, j, k;
00020     char   msg[SLEN];
00021     double delta, class;
00022 
00023     if (TIMES) TIMING(T_CONTOUR);
00024     if (NAMES) {
00025         MESSAGE('I',"");
00026         MESSAGE('I',"CONTOUR");
00027         MESSAGE('I',"");
00028         sprintf(msg," Input image:               %s",in->text);
00029         MESSAGE('I',msg);
00030         sprintf(msg," Number of contour lines:   %d",nlev);
00031         MESSAGE('I',msg);
00032         sprintf(msg," Width of contour lines: %7.2f",width);
00033         MESSAGE('I',msg);
00034         MESSAGE('I'," ...............");
00035     }
00036 
00037     /* check input */
00038     if (!CHECKIMG(in)) {
00039         MESSAGE('E'," Can't identify image.");
00040         goto the_end;
00041     } else if (nlev <= 0) {
00042         MESSAGE('E'," Number of contours must be greater than zero.");
00043         goto the_end;
00044     } else if (0.0 >= width  ||  width >= 1.0) {
00045         MESSAGE('E'," Width of contour lines must be greater than zero and less than one.");
00046         goto the_end;
00047     }
00048 
00049     /* create image of appropriate size */
00050     if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00051     if (!*out) goto the_end;
00052 
00053     /* compute contours */
00054     RANGE(in);
00055     width = (1.0-width)/2.0;
00056     delta = (double)(in->gmax-in->gmin)/(double)nlev;
00057     for (i=0; i<in->nbnd; i++) {
00058         for (j=0; j<in->nlin; j++) {
00059             for (k=0; k<in->npix; k++) {
00060                 class = (double)(in->data[i][j][k]-in->gmin)/delta;
00061                 (*out)->data[i][j][k] = (PIXEL)(fabs(class-(double)rnd(class)) > width  ?  SMAX : SMIN);
00062             }
00063         }
00064     }
00065     (*out)->gmin = (PIXEL)SMIN;
00066     (*out)->gmax = (PIXEL)SMAX;
00067 
00068     the_end:
00069     if (TIMES) TIMING(T_EXIT);
00070 }

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