00001 #include "sadie.h"
00002 #include "proto.h"
00003
00004 extern PIXEL thresh;
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 void TREERING_DETECT (
00015 IMAGE *in,
00016 IMAGE **out
00017
00018 ) { register short i, j, k;
00019 char msg[SLEN];
00020 IMAGE *ringmag=NULL;
00021 IMAGE *thresh1img=NULL;
00022 IMAGE *thresh2img=NULL;
00023 IMAGE *sizethresh1img=NULL;
00024 IMAGE *double_thresh_rings=NULL;
00025 IMAGE *double_thresh_links=NULL;
00026 IMAGE *linkrings_rings=NULL;
00027 IMAGE *linkrings_links=NULL;
00028 IMAGE *combineoutput=NULL;
00029 short (*tf)(IMAGE*, IMAGE **);
00030 tf = TFTHRESH;
00031
00032
00033 if (NAMES) {
00034 MESSAGE('I',"");
00035 MESSAGE('I',"TREERING_DETECT");
00036 MESSAGE('I',"");
00037 sprintf(msg," Input image: %s",in->text);
00038 MESSAGE('I',msg);
00039 MESSAGE('I'," ...............");
00040 }
00041
00042
00043 if (!CHECKIMG(in)) {
00044 MESSAGE('E'," Can't identify image.");
00045 goto the_end;
00046 } else if (in->nbnd > 1) {
00047 MESSAGE('E'," Only first band of input image will be used.");
00048 }
00049
00050
00051
00052 TREERINGMAG(in,3.0,11,&ringmag);
00053 if (!CHECKIMG(ringmag)) {
00054 MESSAGE('E'," Problem determining tree ring boundary magnitudes.");
00055 goto the_end;
00056 } else {
00057 sprintf(ringmag->text, "%s - Ring Magnitude", in->text);
00058 }
00059
00060
00061
00062
00063 RANGE(ringmag);
00064
00065
00066
00067
00068 thresh = (PIXEL)25.0;
00069 STRETCH(ringmag, tf, &thresh1img);
00070 if (!CHECKIMG(thresh1img)) {
00071 MESSAGE('E'," Problem creating threshold 1.");
00072 goto the_end;
00073 } else {
00074 sprintf(thresh1img->text, "%s - Threshold 1", in->text);
00075 }
00076
00077
00078
00079
00080 SIZEFILTER(thresh1img, 25, &sizethresh1img);
00081 if (!CHECKIMG(sizethresh1img)) {
00082 MESSAGE('E'," Problem creating threshold 1.");
00083 goto the_end;
00084 } else {
00085 sprintf(sizethresh1img->text, "%s - Size Filtered Threshold 1", in->text);
00086 }
00087
00088
00089
00090 thresh = (PIXEL)0.001;
00091 STRETCH(ringmag, tf, &thresh2img);
00092 if (!CHECKIMG(thresh2img)) {
00093 MESSAGE('E'," Problem creating threshold 2.");
00094 goto the_end;
00095 } else {
00096 sprintf(thresh2img->text, "%s - Threshold 2", in->text);
00097 }
00098
00099
00100
00101 LINK_DOUBLETHRESH(sizethresh1img,thresh2img,5,&double_thresh_links,&double_thresh_rings);
00102 if (!CHECKIMG(double_thresh_links) || !CHECKIMG(double_thresh_rings) || !CHECKIMG(in)) {
00103 MESSAGE('E'," Problem with double threshold linking.");
00104 goto the_end;
00105 } else {
00106 sprintf(double_thresh_links->text, "%s - Double Threshold Links", in->text);
00107 sprintf(double_thresh_rings->text, "%s - Double Threshold Rings", in->text);
00108 }
00109
00110
00111
00112 COMPARE (double_thresh_links, double_thresh_rings, OR, out);
00113
00114 goto the_end;
00115 COMPARE (double_thresh_links, double_thresh_rings, OR, &combineoutput);
00116 if (!CHECKIMG(combineoutput)) {
00117 MESSAGE('E'," Problem with combining double threshold linking output.");
00118 goto the_end;
00119 } else {
00120 sprintf(combineoutput->text, "%s - Double Threshold Links + Rings", in->text);
00121 }
00122
00123
00124
00125
00126 LINK_TREERINGS(combineoutput,1,&linkrings_links, &linkrings_rings);
00127 if (!CHECKIMG(linkrings_links) || !CHECKIMG(linkrings_rings)) {
00128 MESSAGE('E'," Problem with treering linking.");
00129 goto the_end;
00130 } else {
00131 sprintf(linkrings_links->text, "%s - TreeRing Links", in->text);
00132 sprintf(linkrings_rings->text, "%s - TreeRing Rings", in->text);
00133 }
00134
00135
00136 COMPARE (linkrings_links, linkrings_rings, OR, out);
00137 if (!CHECKIMG(*out)) {
00138 MESSAGE('E'," Problem with combining treering linking output.");
00139 goto the_end;
00140 }
00141
00142
00143
00144
00145 the_end:
00146
00147
00148 if (CHECKIMG(ringmag)) RELIMG(&ringmag);
00149 if (CHECKIMG(thresh1img)) RELIMG(&thresh1img);
00150 if (CHECKIMG(thresh2img)) RELIMG(&thresh2img);
00151 if (CHECKIMG(sizethresh1img)) RELIMG(&sizethresh1img);
00152 if (CHECKIMG(double_thresh_rings)) RELIMG(&double_thresh_rings);
00153 if (CHECKIMG(double_thresh_links)) RELIMG(&double_thresh_links);
00154 if (CHECKIMG(linkrings_rings)) RELIMG(&linkrings_rings);
00155 if (CHECKIMG(linkrings_links)) RELIMG(&linkrings_links);
00156 if (CHECKIMG(combineoutput)) RELIMG(&combineoutput);
00157 }