~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-tools/tinatool/tlmedical/tlmedCort_funcs.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU General Public License as 
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc., 
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  * ANY users of TINA who require exemption from the existing licence must
 20  * negotiate a new licence with Dr. Neil.A.Thacker, the sole agent for
 21  * the University of Manchester.
 22  *
 23  **********
 24  * 
 25  * Program :    TINA
 26  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/tlmedical/tlmedCort_funcs.c,v $
 27  * Date    :  $Date: 2007/02/15 01:55:50 $
 28  * Version :  $Revision: 1.2 $
 29  * CVS Id  :  $Id: tlmedCort_funcs.c,v 1.2 2007/02/15 01:55:50 paul Exp $
 30  *
 31  * Author  : Legacy TINA
 32  *
 33  * Notes :
 34  *
 35  *********
 36 */
 37 
 38 #include "tlmedCort_funcs.h"
 39 
 40 #if HAVE_CONFIG_H
 41   #include <config.h>
 42 #endif
 43 
 44 #include <stdio.h>
 45 #include <sys/param.h>
 46 #include <string.h>
 47 #include <math.h>
 48 
 49 #include <tina/sys/sysDef.h>
 50 #include <tina/sys/sysPro.h>
 51 #include <tina/math/mathDef.h>
 52 #include <tina/math/mathPro.h>
 53 #include <tinatool/draw/drawDef.h>
 54 #include <tinatool/draw/drawPro.h>
 55 #include <tina/image/imgDef.h>
 56 #include <tina/image/imgPro.h>
 57 #include <tina/geometry/geomDef.h>
 58 #include <tina/geometry/geomPro.h>
 59 #include <tinatool/tlbase/tlbaseDef.h>
 60 #include <tinatool/tlbase/tlbasePro.h>
 61 #include <tinatool/tlmedical/tlmedCort_tool.h>
 62 
 63 
 64 /* Performs a 3D Gaussian smoothing operation on a volume of data, given a 
 65    range and sigma.*/
 66 Sequence *seq_gauss_3d(Sequence *seq, double range, double sigma)
 67 {
 68   List *lptr = NULL;
 69   Prof1 *prof;
 70   Imrect *im_temp = NULL;
 71   int lx, ly, ux, uy, uz;
 72   int i, j, k;
 73   float *line = NULL;
 74   double acc = 0.0;
 75 
 76   if (seq == NULL)
 77     return(NULL);
 78 
 79 
 80   acc = exp(-range*range/(2.0*sigma*sigma));
 81   prof = prof_gauss(sigma, acc);
 82 
 83   for (lptr = seq->start; lptr != NULL; lptr=lptr->next)
 84     {
 85       Imrect *image = NULL, *row_im = NULL, *col_im = NULL;
 86       
 87       image = lptr->to;
 88       
 89       row_im = im_filter_rows(image, smooth_1d_sym, (void *) prof);
 90       col_im = im_filter_cols(row_im, smooth_1d_sym, (void *) prof);
 91       lptr->to = col_im;
 92       
 93       im_free(image);
 94       im_free(row_im);
 95      
 96     }
 97 
 98   im_temp = seq->start->to;
 99   lx = im_temp->region->lx;
100   ly = im_temp->region->ly;
101   ux = im_temp->region->ux;
102   uy = im_temp->region->uy;
103   uz = list_length(seq->start);
104   line = fvector_alloc(0, uz);
105 
106   for (i = ly; i<uy; i++)
107     {
108       for (j = lx; j<ux; j++)
109         {
110           for (lptr = seq->start, k=0; lptr!=NULL, k<uz; lptr=lptr->next, k++)
111             {
112               line[k] = (float) im_get_pixf(lptr->to, i, j);
113             }
114           smooth_1d_sym(line, 0, uz, prof);
115           
116           for (lptr = seq->start, k=0; lptr!=NULL, k<uz; lptr=lptr->next, k++)
117             {
118               im_put_pixf((double)line[k], lptr->to, i, j);
119             }
120         }
121     } 
122   
123   fvector_free(line, 0);
124   prof1_free(prof);
125   return(seq);
126 
127 }
128 
129 /* Function to return an mask of the given start_im which excludes the skull 
130  and background.*/
131 Imrect *get_boundary_im(Imrect *start_im)
132 {
133   Imrect *bound_im = NULL, *im1= NULL, *im2 = NULL, *im3 = NULL, *im4 = NULL, *im5 = NULL, *im6 = NULL;
134   Imrect *im7 = NULL, *im8 = NULL, *im9 = NULL, *im6b = NULL, *im2b = NULL, *im9b = NULL;
135   Imrect *im10 = NULL, *im11 = NULL, *im12 = NULL;
136   Imrect *el_val = NULL;
137   int type;
138   Tv *imc_tv = NULL;
139   double skull_seg = 0.0;
140  
141 
142   imc_tv = imcalc_tv_get();
143   skull_seg = get_skull_seg_param();
144 
145   if ((skull_seg < 3.0) || (skull_seg > 4.0))
146     {
147       format("\n Please choose a skull seg parameter between 3.0 and 4.0");
148       format("\n Using default value of 3.05 now\n");
149       skull_seg = 3.05;
150     }
151 
152   morph_spere(3.0, &el_val);
153   im1 = imf_dilate(start_im, el_val);
154   im_free(el_val); 
155   im2 = im_bthresh(skull_seg, im1);
156   im2b = im_cast(im2, uchar_v);
157   im3 = im_minus(im2b);
158   im4 = im_add(1.0, im3);
159 
160   stack_push((void *)im4, IMRECT, im_free);
161   /* fixme: conn_roi, conn_add_regions, conn_seg_regions undeclared */
162   conn_roi(imc_tv, ipos(1,1));
163   conn_add_regions(imc_tv, ipos(1,1));
164   conn_seg_regions(imc_tv, ipos(1,1));
165   im5 = stack_pop(&type);
166   im6 = im_bthresh(0, im5);
167   im6b = im_cast(im6, uchar_v);
168   im7 = imf_sqrgrad(im6b);
169   im8 = im_sqrt(im7);
170   morph_spere(3.0, &el_val);
171   im9 = imf_dilate(im8, el_val);
172   im_free(el_val); 
173   im9b = im_bthresh(3.0, im9);
174   im10 = im_cast(im9b, uchar_v);
175   morph_spere(2.0, &el_val);
176   im11 = imf_dilate(im10, el_val);
177   im_free(el_val); 
178   im12 = im_bthresh(2.0, im11);
179   bound_im = im_cast(im12, uchar_v);
180 
181   im_free(im1);
182   im_free(im2);
183   im_free(im2b);
184   im_free(im3);
185   /*im_free(im4); */
186   im_free(im5);
187   im_free(im6);
188   im_free(im6b);
189   im_free(im7);
190   im_free(im8);
191   im_free(im9);
192   im_free(im9b);
193   im_free(im10);
194   im_free(im11);
195   im_free(im12);
196 
197   return(bound_im);
198 }
199 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.