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

Linux Cross Reference
Tina6/tina-libs/tina/image/imgEM_estep.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-libs/tina/image/imgEM_estep.c,v $
 27  * Date    :  $Date: 2005/07/03 23:46:54 $
 28  * Version :  $Revision: 1.11 $
 29  * CVS Id  :  $Id: imgEM_estep.c,v 1.11 2005/07/03 23:46:54 paul Exp $
 30  *
 31  * Notes :
 32  *
 33  *  List handling. (singly directed)
 34  *  List is { int type; List *next; void *to; }
 35  *
 36  *********
 37 */
 38 
 39 #include "imgEM_estep.h"
 40 /*#include "segment_grad/imgEM_estep.h"
 41 */
 42 
 43 #if HAVE_CONFIG_H
 44   #include <config.h>
 45 #endif
 46 
 47 #include <stdio.h>
 48 #include <math.h>
 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 <tina/image/imgDef.h>
 54 #include <tina/image/imgPro.h>
 55 
 56 
 57 static Imrect *im_tot=NULL;
 58 
 59 Imrect *em_get_im_tot(void)
 60 {
 61    return(im_tot);
 62 }
 63 
 64 void em_clear_im_tot(void)
 65 {
 66         im_free(im_tot);
 67         im_tot=NULL;
 68 }
 69 
 70 /*************************************************************************/
 71 /*           Estimation (E) step of EM algorithm                         */
 72 /*    Probability densities are calculated for pure and mixture models   */
 73 /*    For each model the density image is generated                      */
 74 /*    The sum of all density at each pixel location is calculated        */
 75 /*************************************************************************/
 76 void ***em_estep(void ***pim_array, Mixmodel *model, int grad_flag)
 77 {
 78    int MAX_ITER = 1,iter;
 79    int i,j;
 80    Imrect *im=NULL, *im_seq=NULL, *im_slope=NULL;
 81    Sequence *seq_get_current(void);
 82    Sequence *seq = seq_get_current();
 83    List *lptr = get_current_seq_current_el();
 84    void ***imptrs = NULL;
 85    int   imptrlx, imptrux, imptrly, imptruy, imptrlz, imptruz;
 86    Imregion *roi=NULL;
 87 
 88    if (grad_flag == 1)
 89    {
 90       im_slope = (Imrect *)mD_slope_image(seq);
 91    }
 92    if (model == NULL)
 93    {
 94        error("Input file is missing!", warning);
 95        return(NULL);
 96    }
 97 
 98    if ((im_seq = (Imrect *)(lptr->to))== NULL)
 99    {
100       error("Image sequence is missing!", warning);
101       return(NULL);
102    }
103    roi = im_seq->region;
104    if(roi == NULL) return(NULL);
105 
106    if(pim_array == NULL)
107       pim_array = parray_alloc(0,0,model->nmix,model->nmix);
108 
109    seq_slice_init(seq);
110    imptrs = seq_limits(&imptrlz, &imptruz, &imptrly, &imptruy, &imptrlx,
111                        &imptrux);
112 
113   /* Allocation of memory for each pure tissue and mixtures image based on 2D array             */
114   /* that corresponds to par_dens matrix. If par_dens==0 no memory is allocated for that image  */
115 
116    for (i=0; i < model->nmix; i++)
117    {
118       for (j=0; j< model->nmix; j++)
119       {
120           if (pim_array[i][j]!=NULL) im_free(pim_array[i][j]);
121 
122           if (model->par_dens[i][j] > 0.0)
123              pim_array[i][j] = (void *)im_alloc(imptruy-imptrly,imptrux-imptrlx, roi, float_v);
124           else
125              pim_array[i][j] = NULL;
126       }
127    }
128 
129    for (iter = 0;iter < MAX_ITER; ++iter)
130    {
131       for(i = 0; i < model->nmix; i++)
132       {
133          for(j = 0; j < model->nmix; j++)
134          {
135             if (pim_array[i][j] != NULL)
136             {
137                im = (Imrect *)pim_array[i][j];
138 /*get the memory address for the image (i,j)*/
139                if (grad_flag == 1)
140                   im = prob_im_grad(model,im,roi,i,j,im_slope);
141                else
142                   im = prob_im(model,im,roi,i,j);
143 /*density image for particular (i,j) tissue*/
144             }
145          }
146       }
147       format("\niter=%i ",iter);
148 
149     }/* end of iter loop */
150 
151     if (im_tot!=NULL) im_free(im_tot);
152     im_tot = prob_im_tot(model,pim_array,roi);
153     if (grad_flag==1) im_free(im_slope);
154     return(pim_array);
155 }
156 
157 

~ [ 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.