// file: $USFS/class/image_analysis/v6.1/imaga_sd_15.cc
//

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

// method: sd_test_cc
//
// arguments:
//  float_8& distance: (output) the distance from the test feature vector to
//                     the feature vector in the model
//  uint_1* blk_r: (input) buffer for red color
//  uint_1* blk_g: (input) buffer for green color
//  uint_1* blk_b: (input) buffer for blue color
//  int_4 offset_w: (input) offset in width for the image block
//  int_4 offset_h: (input) offset in height for the image block
//  int_4 width: (input) width of the image block
//  int_4 height: (input) height of the image block
//
// return:
//  a logical_1 value indicating the status
//
// this method computes a histogram on an image block and compares it
// to the reference model.
//
logical_1 Image_analysis::sd_test_cc(float_8& distance_a, uint_1* blk_r_a,
				     uint_1* blk_g_a, uint_1* blk_b_a,
				     int_4 offset_w_a, int_4 offset_h_a,
				     int_4 width_a, int_4 height_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(blk_r_a, blk_g_a, blk_b_a, offset_w_a, offset_h_a,
		    width_a, height_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_nblks_d", sd_r_nblks_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 distance
  //
  if (sd_compare_cc(distance_a) == ISIP_FALSE) {
    error_handler_cc((char_1*)"sd_test_cc",
  	     (char_1*)"error while computing the distance");
    return ISIP_FALSE;
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
 }
