// file: $USFS/class/image_analysis/v1.0/imaga_edge_03.cc
//

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

#include <integral_constants.h>

// method: edge_gradient_cc
//
// arguments:
//  float_4* edge_grad_a: (output) output after the gradient is computed
//  int_4 width_a: (intput) width of the image
//  int_4 height_a: (input) height of the image
//  float_4* xdimg_a: (input) the gaussian image convolved with the x_mask
//  float_4* ydimg_a: (input) the gaussian image convolved with the y_mask
//
// return: a logical_1 value indicating status
//
// this method computes the gradient of the image from the output of the
// convolution with the horizontal and vertical derivatives
//
logical_1 Image_analysis::edge_gradient_cc(float_4* edge_grad_a, int_4 width_a,
					   int_4 height_a, float_4* xdimg_a,
					   float_4* ydimg_a) {
  
  // loop through the entire image
  //
  for (int_4 i=0; i <height_a; i++) {
    for (int_4 j=0; j<width_a; j++) {
      
      // assigning the values from the derivatives
      //
      float_4 p = xdimg_a[i*width_a + j];
      float_4 q = ydimg_a[i*width_a + j];
      
      // computing the gradient
      //
      edge_grad_a[i*width_a + j] = sqrt(p*p + q*q);
    }
  }
  
  // exit gracefully
  //
  return ISIP_TRUE;
}

