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 SEGMENT (
00023 IMAGE *in,
00024 short steps,
00025 double sigma,
00026 PIXEL thresh,
00027 IMAGE **out
00028
00029 ) { register short i;
00030 char msg[SLEN];
00031 IMAGE **scratch=0, *img[3];
00032
00033 if (TIMES) TIMING(T_SEGMENT);
00034 if (NAMES) {
00035 MESSAGE('I',"");
00036 MESSAGE('I',"SEGMENT");
00037 MESSAGE('I',"");
00038 sprintf(msg," Input image: %s",in->text);
00039 MESSAGE('I',msg);
00040 sprintf(msg," Graylevel difference threshold: %12.4e",thresh);
00041 MESSAGE('I',msg);
00042 sprintf(msg," Graylevel variance threshold: %12.4e",sigma);
00043 MESSAGE('I',msg);
00044 sprintf(msg," Number of reduction steps: %d",steps);
00045 MESSAGE('I',msg);
00046 MESSAGE('I'," ...............");
00047 }
00048
00049
00050 if (!CHECKIMG(in)) {
00051 MESSAGE('E'," Can't identify image.");
00052 goto the_end;
00053 } else if (steps < 0) {
00054 MESSAGE('E'," Number of reduction steps must be equal to or greater than zero.");
00055 goto the_end;
00056 }
00057
00058
00059 if (!(scratch=(IMAGE **)malloc((2*steps+2)*sizeof(IMAGE *)))) {
00060 MESSAGE('E'," Memory request failed.");
00061 goto the_end;
00062 }
00063 for (i=0; i<2*steps+2; scratch[i++]=0);
00064
00065
00066 scratch[0] = in;
00067 for (i=0; i<steps; i++) {
00068 RESAMPL(scratch[i],2,2,2,2,scratch+i+1);
00069 if (ABORT || !scratch[i+1]) goto the_end;
00070 sprintf(scratch[i+1]->text,"Scratch");
00071 }
00072
00073
00074 LABEL(scratch[steps],sigma,thresh,scratch+steps+1);
00075 if (ABORT || !scratch[steps+1]) goto the_end;
00076 sprintf(scratch[steps+1]->text,"Scratch");
00077
00078
00079 for (i=0; i<steps; i++) {
00080 img[0] = scratch[steps+i+1];
00081 img[1] = scratch[steps-i];
00082 img[2] = scratch[steps-i-1];
00083 REFINE(img,scratch+steps+i+2);
00084 if (ABORT || !scratch[steps+i+2]) goto the_end;
00085 sprintf(scratch[steps+i+2]->text,"Scratch");
00086 RELMEM(scratch[steps-i]);
00087 scratch[steps-i] = 0;
00088 }
00089 *out = scratch[2*steps+1];
00090
00091 the_end:
00092 if (scratch) {
00093 for (i=1; i<2*steps+1; i++) {
00094 if (scratch[i]) RELMEM(scratch[i]);
00095 }
00096 free(scratch);
00097 }
00098 if (TIMES) TIMING(T_EXIT);
00099 }