Main Page   Data Structures   File List   Data Fields   Globals  

treeringmag.c

Go to the documentation of this file.
00001 #include "trees.h"
00002 
00003 static PIXEL firstdiff_x[3][3] = { { -1.0,  0.0,  1.0 }, 
00004                                    { -2.0,  0.0,  2.0 }, 
00005                                    { -1.0,  0.0,  1.0 } };
00006 
00007 static PIXEL firstdiff_y[3][3] = { {  1.0,  2.0,  1.0 }, 
00008                                    {  0.0,  0.0,  0.0 }, 
00009                                    { -1.0, -2.0, -1.0 } };
00010 
00011 
00012 /*----------------------------------------------------------------------------*/
00013 /*-General Information--------------------------------------------------------*/
00014 /*                                                                            */
00015 /* This function detects tree rings.                                          */
00016 /*                                                                            */
00017 /*----------------------------------------------------------------------------*/
00018 /*-Interface Information------------------------------------------------------*/
00019 void TREES_TREERINGMAG (
00020 IMAGE  *in,      /*  I   Pointer to the input image.                          */
00021 LOCAL_INDEX *localindex,                      
00022 double sigma,    /*  I   Std. deviation of gaussian smoothing filter.         */
00023 int    size,     /*  I   Size of gaussian smoothing filter.                   */
00024 IMAGE **mag,     /*  O   Address of a pointer to the output image             */
00025                  /*      containing the gradient magnitude.                   */
00026 IMAGE **dir      /*  O   Address of a pointer to the output image             */
00027                  /*      containing the gradient direction.                   */
00028 /*----------------------------------------------------------------------------*/
00029 ) { register int j, k, n;
00030     char msg[SLEN];
00031     IMAGE *gaussian, *smoothed;
00032     IMAGE *FoG_mag, *FoG_dir;
00033     PIXEL *psf=0, factor;
00034 
00035     /* if (TIMES) TIMING(T_TREERINGMAG); */
00036     if (NAMES) {
00037         MESSAGE('I',"");
00038         MESSAGE('I',"TREERINGMAG");
00039         MESSAGE('I',"");
00040         sprintf(msg," Input image:                       %s",in->text);
00041         MESSAGE('I',msg);
00042         sprintf(msg," Gaussian smoothing filter size:    %d",size);
00043         MESSAGE('I',msg);
00044         sprintf(msg,"             Standard Deviation:    %f",sigma);
00045         MESSAGE('I',msg);
00046         MESSAGE('I'," ...............");
00047     }
00048 
00049     /* check input */
00050     if (!CHECKIMG(in)) {
00051         MESSAGE('E'," Can't identify image.");
00052         goto the_end;
00053     } else if (in->nbnd > 1) {
00054         MESSAGE('E'," Image must be single-band.");
00055         goto the_end;
00056     }
00057 
00058     if (size > 0) {
00059         /* create gaussian smoothing filter */
00060         CREATEGAUSS(size, sigma, &gaussian);
00061         if (CHECKIMG(gaussian)) {
00062             sprintf(gaussian->text, "%dx%d Gaussian -- sigma=%f", size,size,sigma);
00063         } else {
00064             MESSAGE('E'," Can't identify gaussian filter.");
00065             goto the_end;
00066         }
00067 
00068         /* perform gaussian smoothing on input image */
00069         if (!(psf = (PIXEL *) malloc(size*size*sizeof(PIXEL)))) {
00070             MESSAGE('E'," Memory allocation failed.");
00071             goto the_end;
00072         }
00073         for (n=0, j=0, factor=0.0; j<size; j++) {
00074             for (k=0; k<size; k++) {
00075                 psf[n] = gaussian->data[0][j][k];
00076                 factor += psf[n++];
00077             }
00078         }
00079         for (n=0, j=0; j<size; j++) {
00080             for (k=0; k<size; k++) {
00081                 psf[n++] /= factor;
00082             }
00083         }
00084         TREES_SCONVL(in, localindex, psf, size, size, &smoothed);
00085     } else {
00086         IMGCOPY(in,&smoothed);
00087     }
00088 
00089     if (CHECKIMG(smoothed)) {
00090         sprintf(smoothed->text, "Smoothed image");
00091     } else {
00092         MESSAGE('E'," Can't identify smoothed image.");
00093         goto the_end;
00094     }
00095     
00096     /* create the First Order Gaussian filtered image */
00097     TREES_GRADIENT(smoothed, localindex, (PIXEL *)firstdiff_y, (PIXEL *)firstdiff_x, 3, &FoG_mag, &FoG_dir);
00098     
00099     *mag = FoG_mag;
00100     *dir = FoG_dir;
00101     
00102     the_end:
00103 
00104     if (psf) free(psf);
00105     if (CHECKIMG(gaussian))  RELIMG(&gaussian);
00106     if (CHECKIMG(smoothed))  RELIMG(&smoothed);
00107     /* if (TIMES) TIMING(T_EXIT); */
00108 
00109 }
00110 
00111 
00112 

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