// file: $USFS/class/image_analysis/v6.0/imaga_diff_12.cc
//

// isip include files
//
#include "image_analysis.h"
#include "image_analysis_constants.h"

// method: dent_test_cc
//
// arguments:
//  float_8& sbe: (output) the image's sbe value
//  char_1* image_fname: (input) the image file name
//  char_1* seg_fname: (input) the segmentation file name
//
// return:
//  a logical_1 value indicating the status
//
// this method computes a histogram and compares it to the reference model.
//
logical_1 Image_analysis::dent_test_cc(float_8& sbe_a, char_1* image_fname_a, 
				       char_1* seg_fname_a) {
 
  // initialize
  //
  if (dent_init_cc() == ISIP_FALSE) {
    error_handler_cc((char_1*)"dent_test_cc",
		     (char_1*)"error while computing the diff in magnitude");
    return ISIP_FALSE;
  }
  
  // compute the differential entropy
  //
  if (dent_compute_cc(image_fname_a, seg_fname_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"dent_test_cc",
		     (char_1*)"error while computing the diff in magnitude");
    return ISIP_FALSE;
  }

  // normalize
  //
  if (dent_normalize_cc() == ISIP_FALSE) {
    error_handler_cc((char_1*)"dent_test_cc",
		     (char_1*)"error while normalizing the diff magnitude");
    return ISIP_FALSE;
  }
  
  // provide some debugging information
  //
  if (debug_level_d > ISIP_DEBUG_BRIEF) {
    fprintf(stdout, "<%s> %s = %ld\n", "Image_analysis::dent_compute_cc",
	    "diff_npxls", dent_r_npxls_d);
    fprintf(stdout, "<%s> %s = %ld\n", "Image_analysis::dent_compute_cc",
	    "dent_r_nimages_d", dent_r_nimages_d);
    
    // display the histogram
    //
    fprintf(stdout, "red diff:\n");
    for (int_4 i=0; i<dent_r_nbins_d; i++) {
      fprintf(stdout, "%ld: %f\n", i, dent_t_red_d[i]);
    }

    fprintf(stdout, "green diff:\n");
    for (int_4 i=0; i<dent_r_nbins_d; i++) {
      fprintf(stdout, "%ld: %f\n", i, dent_t_grn_d[i]);
    }

    fprintf(stdout, "blue diff:\n");
    for (int_4 i=0; i<dent_r_nbins_d; i++) {
      fprintf(stdout, "%ld: %f\n", i, dent_t_blu_d[i]);
    }
    
  }
  
  // compute the sbe
  //
  if (dent_compare_cc(sbe_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"hist_test_cc",
  	     (char_1*)"error while computing the sbe");
    return ISIP_FALSE;
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
