Commit 94839c9b authored by Ian Humphrey's avatar Ian Humphrey
Browse files

gradient provides ability to calculate gradients approximately or exactly...

gradient provides ability to calculate gradients approximately or exactly (default approximate). Fixes #1741.

git-svn-id: http://subversion.wr.usgs.gov/repos/prog/isis3/trunk@6273 41f8697f-d340-4b68-9986-7bafba869bb8
parent 778a019c
Loading
Loading
Loading
Loading
−26.8 KiB (65.2 KiB)
Loading image diff...
−27.8 KiB (64.5 KiB)
Loading image diff...
−25.8 KiB (4.39 KiB)
Loading image diff...
−26.3 KiB (4.35 KiB)
Loading image diff...
+63 −3
Original line number Diff line number Diff line
#include <cmath>

#include "Isis.h"
#include "ProcessByBoxcar.h"
#include "SpecialPixel.h"
@@ -6,7 +8,9 @@ using namespace std;
using namespace Isis;

void robertGradient(Buffer &in, double &v);
void robertGradientApprox(Buffer &in, double &v);
void sobelGradient(Buffer &in, double &v);
void sobelGradientApprox(Buffer &in, double &v);

void IsisMain() {

@@ -20,22 +24,38 @@ void IsisMain() {
  //  Allocate the output cube
  p.SetOutputCube("TO");

  //  Which computation?
  QString method = ui.GetString("METHOD");

  //  Which gradient?
  QString gradType = ui.GetString("GRADTYPE");

  //  Set boxcar size depending on the gradient type
  if (gradType == "SOBEL") {
    p.SetBoxcarSize(3, 3);
    if (method == "EXACT") {
      p.StartProcess(sobelGradient);
    }
  else if(gradType == "ROBERTS") {
    else { // APPROXIMATE
      p.StartProcess(sobelGradientApprox);
    }
  }

  else { // ROBERTS
    p.SetBoxcarSize(2, 2);
    if (method == "EXACT") {
      p.StartProcess(robertGradient);
    }
    else { // APPROXIMATE
      p.StartProcess(robertGradientApprox);
    }
  }

  p.EndProcess();

}


//  Sobel gradient filter
void sobelGradient(Buffer &in, double &v) {

@@ -49,14 +69,54 @@ void sobelGradient(Buffer &in, double &v) {
    v = Isis::Null;
    return;
  }
  v = abs((in[0] + 2 * in[1] + in[2]) - (in[6] + 2 * in[7] + in[8])) +
      abs((in[2] + 2 * in[5] + in[8]) - (in[0] + 2 * in[3] + in[6]));
  v = sqrt(
        pow( (in[2] + 2 * in[5] + in[8]) - (in[0] + 2 * in[3] + in[6]), 2 ) +
        pow( (in[0] + 2 * in[1] + in[2]) - (in[6] + 2 * in[7] + in[8]), 2 )
      );

}


//  Sobel approximate gradient filter
void sobelGradientApprox(Buffer &in, double &v) {

  bool specials = false;
  for(int i = 0; i < in.size(); ++i) {
    if(IsSpecial(in[i])) {
      specials = true;
    }
  }
  if(specials) {
    v = Isis::Null;
    return;
  }
  v = abs((in[2] + 2 * in[5] + in[8]) - (in[0] + 2 * in[3] + in[6])) +
      abs((in[0] + 2 * in[1] + in[2]) - (in[6] + 2 * in[7] + in[8])); 
 
}


//   Roberts gradient filter
void robertGradient(Buffer &in, double &v) {

  bool specials = false;
  for(int i = 0; i < in.size(); ++i) {
    if(IsSpecial(in[i])) {
      specials = true;
    }
  }
  if(specials) {
    v = Isis::Null;
    return;
  }
  v = sqrt( pow((in[0] - in[3]), 2) + pow((in[1] - in[2]), 2) );

}


//  Roberts approximate gradient filter
void robertGradientApprox(Buffer &in, double &v) {

  bool specials = false;
  for(int i = 0; i < in.size(); ++i) {
    if(IsSpecial(in[i])) {
Loading