Main Page   Data Structures   File List   Data Fields   Globals  

treering_detect.c

Go to the documentation of this file.
00001 #include        "sadie.h"
00002 #include        "proto.h"
00003 
00004 extern  PIXEL   thresh;
00005 
00006 
00007 /*-General Information--------------------------------------------------------*/
00008 /*                                                                            */
00009 /*  Description:  This procedure detects tree ring boundaries and             */
00010 /*      links fragments.                                                      */
00011 /*                                                                            */
00012 /*----------------------------------------------------------------------------*/
00013 /*-Interface Information------------------------------------------------------*/
00014 void TREERING_DETECT (
00015 IMAGE  *in,     /*  I   Pointer to the input image.                           */
00016 IMAGE  **out    /*  O   Address of a pointer to the output image.             */
00017 /*----------------------------------------------------------------------------*/
00018 ) { register short i, j, k;
00019     char   msg[SLEN];
00020     IMAGE *ringmag=NULL;         /* Tree ring magnitudes prior to thresholding */
00021     IMAGE *thresh1img=NULL;      /* High threshold, to remove most noise */
00022     IMAGE *thresh2img=NULL;      /* Low threshold, including noise and tree rings */
00023     IMAGE *sizethresh1img=NULL;  /* High threshold, also with a size threshold */
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     /* if (TIMES) TIMING(T_TREERING_DETECT); */
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     /* check input */
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     /* Detect rings and return gradient magnitudes of possible ring boundaries */
00051     /* Use a gaussian of size 11 and std. deviation 3.0 */
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     /* For some reason this is necessary to make the following threshold work */
00061     /* Without it, the following threshold returns a all-zero image always
00062         under linux, and after the third run under Solaris ???                */
00063     RANGE(ringmag);
00064 
00065 
00066     /* Create high threshold image */
00067     //thresh = (PIXEL)9.0;   /* Need to set this automatically */
00068     thresh = (PIXEL)25.0;   /* Need to set this automatically */
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     /* Perform size threshold */
00079     /* Don't pass any fragment smaller than 25 pixels */
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     /* Create low threshold image */
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     /* Perform double threshold linking */
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     /* Combine the output into a single edge map */
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     /* Perform tree ring fragment linking */
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     /* Combine the output into a single edge map */
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     /* if (TIMES)   TIMING(T_EXIT); */
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 }

Generated on Wed Apr 9 08:56:15 2003 for TREES by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002