/*--------------------------- Commande MegaWave -----------------------------*/
/* mwcommand
   name = {filter};
   author = {"Trung Nguyen"};
   version = {"1.0"};
   function = {"Filter by self-dual operateurs"};
   usage = {   
     A->A               "Input positive image",
     B->B               "Input negative image",
     ref->ref           "Referencet image",
     out<-out           "Output Fimage"
   };
*/

#include "mw.h"

void filter(A, B, ref, out)
     Fimage A, B, ref, out;
{
  int i;

  if (A->ncol != B->ncol || A->nrow != B->nrow) 
    mwerror(FATAL, 1, "Image A and Image B have not the same size!\n");
 
  if  ((out = mw_change_fimage(out ,A->nrow, A->ncol)) == NULL)
  mwerror(FATAL, 1, "Not enough memory !\n");

  for (i = 0; i < A->ncol * A->nrow; i++)
    out->gray[i] = A->gray[i] - B->gray[i] + ref->gray[i];
}

