/*----------------------------MegaWave2 module----------------------------*/
/* mwcommand
name = {select_miss};
version = {"1.0"};
author = {"Lionel Moisan"};
function = {"Select misclassified images"};
usage = {
 'w'->w             "write estimated / true labels (integer)",
 test->test         "test set (Ccmovie)",
 classif->classif   "estimated labels (Fsignal)",
 true->true         "true labels (Fsignal)",
 out<-select_miss   "misclassified images (Ccmovie)"
        };
*/
 
#include <stdio.h>
#include <math.h>
#include "mw.h"

Ccmovie select_miss(test,classif,true,w)
     Ccmovie test;
     Fsignal classif,true;
     int *w;
{
  Ccmovie out;
  Ccimage *next,prev,cur,u;
  int k,fg,bg;
  float r;
  char str[101];

  out = mw_new_ccmovie();
  next = &(out->first);
  prev = NULL;

  for (u=test->first,k=0;u;u=u->next,k++) 
    if (classif->values[k]!=true->values[k]) {
      cur = mw_change_ccimage(NULL,u->nrow,u->ncol);
      mw_copy_ccimage(u,cur);
      cur->previous = prev;
      *next = prev = cur;
      next = &(cur->next);
      if (w) {
	fg = 900;
	bg = 0;
	r = 0.;
	snprintf(str,100,"%d/%d",
		 (int)classif->values[k],(int)true->values[k]);
	ccputstring(cur,0,0,&fg,&bg,&r,str);
      }
    }
  *next = NULL;

  return(out);
}
