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