00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 void CONTOUR (
00013 IMAGE *in,
00014 short nlev,
00015 double width,
00016 IMAGE **out
00017
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
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
00050 if (!CHECKIMG(*out)) GETMEM(in->nbnd,in->nlin,in->npix,out);
00051 if (!*out) goto the_end;
00052
00053
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 }