Added snark14m distribution examples
[snark14.git] / examples / b9 / src / user_fom1.c
diff --git a/examples/b9/src/user_fom1.c b/examples/b9/src/user_fom1.c
new file mode 100644 (file)
index 0000000..22cc22a
--- /dev/null
@@ -0,0 +1,69 @@
+#include <malloc.h>
+#include "experimenter.h"
+#include "read_eval_phantom1.h"
+#include "read_eval_recon3.h"
+#include "user_fom1.h"
+
+/* ----------------------------- user_fom1.c --------------
+
+       This function illustrates the use of a user-defined figure 
+of merit.
+
+INPUTS:
+  itr1 - array of length niters containing the iteration numbers for the
+        first algorithm.
+  itr2 - array of length niters containing the iteration numbers for the
+        second algorithm.
+  niters - number of iterations to be compared
+  keywrd1 - string containing the keyword which defines the first algorithm.
+  keywrd2 - string containing the keyword which defines the second algorithm.
+
+OUTPUTS:
+  user1 - array of length niters containing the user defined figure of 
+         merit for the first algorithm.
+  user2 - array of length niters containing the user defined figure of
+         merit for the second algorithm.
+
+*/
+
+void user_fom1(int* itr1, int* itr2, int niters, char* keywrd1, char* keywrd2, double* user1, double* user2)
+     //int *itr1,*itr2,niters;
+     //char *keywrd1,*keywrd2;
+     //double *user1,*user2;
+{
+  double *phantom,*recon1,*recon2;
+  int *regions,numstr,i,j,*strarea;
+  float totarea=0.0,avgarea;
+  
+  /* Read in abnormality index and area for phantom structures.
+     The program which does this is read_eval_phantom1.c. 
+     NOTE: the only information to be used is the value
+     'numstr' (which is the number of structures in the phantom) */
+  read_eval_phantom1(&regions,&numstr,&phantom,&strarea);
+  
+  /* allocate memory to store abnormality indexes and area
+     (i.e number of pixels) for structures in the 
+     reconstructions */  
+  recon1 = (double *) malloc(numstr*sizeof(double));
+  recon2 = (double *) malloc(numstr*sizeof(double));
+    
+  for(i=0;i < niters;i++) {
+    /* read in variance for structures in 
+       the reconstructions. Initialize the arrays
+       which will store the user FOM */
+    
+    //printf("*** about to read variance\n"); /* TEST (JD) */
+    read_eval_recon3(itr1[i],keywrd1,numstr,recon1);
+    read_eval_recon3(itr2[i],keywrd2,numstr,recon2);
+    /* the varaince of the 'SINGLE' structure to be 
+       used is the first in the array.  The FOM value
+       is 1-variance */
+    user1[i]=1-recon1[0];
+    user2[i]=1-recon2[0];
+  }
+  
+  free(phantom);       /* free memory for next function call */
+  free(recon1);
+  free(recon2);
+  free(strarea);
+}