00001 #include "sadie.h"
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 void
00023 SEGMENT (IMAGE * in,
00024 short steps,
00025 double sigma,
00026 PIXEL thresh,
00027 IMAGE ** out
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
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
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
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
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
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 }