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

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

// method: edge_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 performs the edge detection on a prescribed region
//
logical_1 Image_analysis::edge_test_cc(float_8& sbe_a, char_1* image_fname_a,
				       char_1* seg_fname_a) {

  // initialize the private data
  //
  if (edge_init_cc() == ISIP_FALSE) {
    error_handler_cc((char_1*)"edge_test_cc",
		     (char_1*)"error while initializing the edge detection");
    return ISIP_FALSE;
  }
  
  // perform the edge detection
  //
  if (edge_compute_cc(image_fname_a, seg_fname_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"edge_test_cc",
		     (char_1*)"error while computing the edges");
    return ISIP_FALSE;
  }
  
  // perform the normalization
  //
  if (edge_normalize_cc() == ISIP_FALSE) {
    error_handler_cc((char_1*)"edge_test_cc",
		     (char_1*)"error while normalizing the data");
    return ISIP_FALSE;
  }

  for (int_4 i=0; i < edge_r_nbins_d; i++) {
    fprintf(stdout, " %f\t", edge_t_lpdf_d[i]);
  }
  
  // provide some debugging information
  //
  if (debug_level_d > ISIP_DEBUG_BRIEF) {
    fprintf(stdout, "<%s> %s = %ld\n", "Image_analysis::edge_test_cc",
	    "edge_t_nlines", edge_t_tlines_d);
    fprintf(stdout, "<%s> %s = %ld\n", "Image_analysis::edge_test_cc",
	    "edge_t_nimages_d", edge_t_nimages_d);

    // display the distribution of lines
    //
    fprintf(stdout, "lines pdf:\n");
    for (int_4 i=0; i<edge_r_nbins_d; i++) {
      fprintf(stdout, "%ld: %f\n", i, edge_t_lpdf_d[i]);
    }
  }
  
  // compute the sbe
  //
  if (edge_compare_cc(sbe_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"edge_test_cc",
		     (char_1*)"error while computing the sbe");
    return ISIP_FALSE;
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}
