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