bdccf75b0196fe7e27c5bab5a238e5eec601dc26
[snark14.git] / src / snark / stru_acc.c
1 /*
2  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3  *                                                               *
4  *                         S N A R K   1 4                       *
5  *                                                               *
6  *                A PICTURE RECONSTRUCTION PROGRAM               *
7  *                                                               *
8  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9
10   stru_acc.c,v 1.4 2009/06/01 03:33:26 jklukowska Exp
11
12  Previously part of SuperSNARK
13  */
14
15 #include "malloc.h"
16 #include "experimenter.h"
17 #include "stru_acc.h"
18 #include "read_eval_recon1.h"
19 #include "read_eval_phantom1.h"
20
21 /* ----------------------------- stru_acc.c -------------------------------
22
23         This function computes the structural accuracy.
24
25 INPUTS:
26   itr1 - array of length niters containing the iteration numbers for the
27          first algorithm.
28   itr2 - array of length niters containing the iteration numbers for the
29          second algorithm.
30   niters - number of iterations to be compared
31   keywrd1 - string containing the keyword which defines the first algorithm.
32   keywrd2 - string containing the keyword which defines the second algorithm.
33
34 OUTPUTS:
35   str_acc1 - array of length niters containing the structural accuracy for 
36              the first algorithm.
37   str_acc2 - array of length niters containing the structural accuracy for
38              the second algorithm.
39
40  */
41
42 void stru_acc(int* itr1, int* itr2, int niters, char* keywrd1, char* keywrd2, double* str_acc1, double* str_acc2)
43 //int *itr1,*itr2,niters;
44 //char *keywrd1,*keywrd2;
45 //double *str_acc1,*str_acc2;
46 {
47     double *phantom, *recon1, *recon2;
48     int *regions, numstr, i, j, *strarea;
49
50     /* read in abnormality index for phantom structures */
51
52     read_eval_phantom1(&regions, &numstr, &phantom, &strarea);
53
54     /* allocate memory to store abnormality indexes for
55        structures in the reconstructions*/
56
57     recon1 = (double *) malloc(numstr * sizeof (double));
58     recon2 = (double *) malloc(numstr * sizeof (double));
59
60     for (i = 0; i < niters; i++) { /* read in abnormality indexes for structures in
61                    the reconstructions. Initialize the arrays
62                    which will store the structural accuracy */
63
64         read_eval_recon1(&itr1[i], keywrd1, numstr, recon1);
65         read_eval_recon1(&itr2[i], keywrd2, numstr, recon2);
66         str_acc1[i] = 0.0;
67         str_acc2[i] = 0.0;
68         for (j = 0; j < numstr; j++) { /* compute structural accuracy for both algorithms */
69
70             str_acc1[i] = str_acc1[i] + fabs(recon1[j] - phantom[j]);
71             str_acc2[i] = str_acc2[i] + fabs(recon2[j] - phantom[j]);
72         }
73         str_acc1[i] = -str_acc1[i] / numstr; /* structural */
74         str_acc2[i] = -str_acc2[i] / numstr; /* accuracy */
75     }
76
77     free(phantom); /* free memory for next function call */
78     free(recon1);
79     free(recon2);
80     free(strarea);
81
82 }