Added snark14m distribution examples
[snark14.git] / examples / b9 / src / user_fom1.c
1 #include <malloc.h>
2 #include "experimenter.h"
3 #include "read_eval_phantom1.h"
4 #include "read_eval_recon3.h"
5 #include "user_fom1.h"
6
7 /* ----------------------------- user_fom1.c --------------
8
9         This function illustrates the use of a user-defined figure 
10 of merit.
11
12 INPUTS:
13   itr1 - array of length niters containing the iteration numbers for the
14          first algorithm.
15   itr2 - array of length niters containing the iteration numbers for the
16          second algorithm.
17   niters - number of iterations to be compared
18   keywrd1 - string containing the keyword which defines the first algorithm.
19   keywrd2 - string containing the keyword which defines the second algorithm.
20
21 OUTPUTS:
22   user1 - array of length niters containing the user defined figure of 
23           merit for the first algorithm.
24   user2 - array of length niters containing the user defined figure of
25           merit for the second algorithm.
26
27 */
28
29 void user_fom1(int* itr1, int* itr2, int niters, char* keywrd1, char* keywrd2, double* user1, double* user2)
30      //int *itr1,*itr2,niters;
31      //char *keywrd1,*keywrd2;
32      //double *user1,*user2;
33 {
34   double *phantom,*recon1,*recon2;
35   int *regions,numstr,i,j,*strarea;
36   float totarea=0.0,avgarea;
37   
38   /* Read in abnormality index and area for phantom structures.
39      The program which does this is read_eval_phantom1.c. 
40      NOTE: the only information to be used is the value
41      'numstr' (which is the number of structures in the phantom) */
42   read_eval_phantom1(&regions,&numstr,&phantom,&strarea);
43   
44   /* allocate memory to store abnormality indexes and area
45      (i.e number of pixels) for structures in the 
46      reconstructions */  
47   recon1 = (double *) malloc(numstr*sizeof(double));
48   recon2 = (double *) malloc(numstr*sizeof(double));
49     
50   for(i=0;i < niters;i++) {
51     /* read in variance for structures in 
52        the reconstructions. Initialize the arrays
53        which will store the user FOM */
54     
55     //printf("*** about to read variance\n"); /* TEST (JD) */
56     read_eval_recon3(itr1[i],keywrd1,numstr,recon1);
57     read_eval_recon3(itr2[i],keywrd2,numstr,recon2);
58     /* the varaince of the 'SINGLE' structure to be 
59        used is the first in the array.  The FOM value
60        is 1-variance */
61     user1[i]=1-recon1[0];
62     user2[i]=1-recon2[0];
63   }
64   
65   free(phantom);        /* free memory for next function call */
66   free(recon1);
67   free(recon2);
68   free(strarea);
69 }