// file: $USFS/class/image_analysis/v3.0/imaga_sd_01.cc
//

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

// method: sd_test_cc
//
// arguments:
//  float_8& sbe_a: (output) the image's sbe value
//  char_1* image_fname_a: (input) the image's filename
//
// return: a logical_1 value indicating the status
//
// this method computes a histogram and compares it to the reference model.
//
logical_1 Image_analysis::sd_test_cc(float_8& sbe_a,
				       char_1* image_fname_a) {
 
  // initialize
  //
  if (sd_init_cc() == ISIP_FALSE) {
    error_handler_cc((char_1*)"sd_test_cc",
		     (char_1*)"error while initializing for the deviation");
    return ISIP_FALSE;
  }
  
  // compute the standard deviation
  //
  if (sd_compute_cc(image_fname_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"sd_test_cc",
		     (char_1*)"error while computing standard deviation");
    return ISIP_FALSE;
  }

  // normalize the values
  //
  if(sd_normalize_cc() == ISIP_FALSE) {
    error_handler_cc((char_1*)"sd_test_cc",
		     (char_1*)"error normalizing the values");
    return ISIP_FALSE;
  }
  
  // provide some debugging information
  //
  if (debug_level_d > ISIP_DEBUG_BRIEF) {
    fprintf(stdout, "<%s> %s = %ld\n", "Image_analysis::sd_compute_cc",
	    "sd_npxls", sd_r_npxls_d);
    fprintf(stdout, "<%s> %s = %ld\n", "Image_analysis::sd_compute_cc",
	    "sd_r_nimages_d", sd_r_nimages_d);


    fprintf(stdout, "%s\n", "the values of standard deviation are");
    fprintf(stdout, "red_std = %f\tgrn_std = %f\tblu_std = %f\t\n", 
	    sd_t_red_d, sd_t_grn_d, sd_t_blu_d);

  }
  
  // compute the sbe
  //
  if (sd_compare_cc(sbe_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"sd_test_cc",
  	     (char_1*)"error while computing the sbe");
    return ISIP_FALSE;
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
 }
