/**
   * Runs a canny edge detector on the input image given the provided thresholds. If configured to
   * save a list of trace points then the output image is optional.
   *
   * <p>NOTE: Input and output can be the same instance, if the image type allows it.
   *
   * @param input Input image. Not modified.
   * @param threshLow Lower threshold. >= 0.
   * @param threshHigh Upper threshold. >= 0.
   * @param output (Might be option) Output binary image. Edge pixels are marked with 1 and
   *     everything else 0.
   */
  public void process(T input, float threshLow, float threshHigh, ImageUInt8 output) {

    if (threshLow < 0 || threshHigh < 0)
      throw new IllegalArgumentException("Threshold must be >= zero!");

    if (hysteresisMark != null) {
      if (output == null)
        throw new IllegalArgumentException(
            "An output image must be specified when configured to mark edge points");
    }

    // setup internal data structures
    blurred.reshape(input.width, input.height);
    derivX.reshape(input.width, input.height);
    derivY.reshape(input.width, input.height);
    intensity.reshape(input.width, input.height);
    suppressed.reshape(input.width, input.height);
    angle.reshape(input.width, input.height);
    direction.reshape(input.width, input.height);
    work.reshape(input.width, input.height);

    // run canny edge detector
    blur.process(input, blurred);
    gradient.process(blurred, derivX, derivY);
    GGradientToEdgeFeatures.intensityAbs(derivX, derivY, intensity);
    GGradientToEdgeFeatures.direction(derivX, derivY, angle);
    GradientToEdgeFeatures.discretizeDirection4(angle, direction);
    GradientToEdgeFeatures.nonMaxSuppression4(intensity, direction, suppressed);

    performThresholding(threshLow, threshHigh, output);
  }
  /**
   * Specify internal algorithms and behavior.
   *
   * @param blur Initial blur applied to image.
   * @param gradient Computes the image gradient.
   * @param saveTrace Should it save a list of points that compose the objects contour/trace?
   */
  public CannyEdge(BlurFilter<T> blur, ImageGradient<T, D> gradient, boolean saveTrace) {
    this.blur = blur;
    this.gradient = gradient;

    Class<T> imageType = blur.getInputType().getImageClass();

    blurred = GeneralizedImageOps.createSingleBand(imageType, 1, 1);
    derivX = gradient.getDerivativeType().createImage(1, 1);
    derivY = gradient.getDerivativeType().createImage(1, 1);

    if (saveTrace) {
      hysteresisPts = new HysteresisEdgeTracePoints();
    } else {
      hysteresisMark = new HysteresisEdgeTraceMark();
    }
  }