Class MaxFromTwoSelectedNumbersFunc

java.lang.Object
net.algart.math.functions.AbstractFunc
net.algart.math.functions.MaxFromTwoSelectedNumbersFunc
All Implemented Interfaces:
Func

public class MaxFromTwoSelectedNumbersFunc extends AbstractFunc implements Func

Maximum from 2 arguments, selected by 1st argument: f(x0, x1, ..., xn-1) = max(xi+1, xj+1), i=(int)x[0] (x0 cast to integer type), j=(i−1+indexShift)%(n−1)+1, where indexShift is an integer constant, passed to getInstance(int) method.

More precisely, the get(double...) method of this object performs the following actions:

     int k1 = (int)x[0] + 1;
     // it is supposed that always 1<=(int)x[0]<=x.length
     int k2 = k1 + indexShift;
     if (k2 >= x.length) {
         // it is supposed that indexShift<x.length-1
         k2 -= x.length - 1;
     }
     return x[k1] > x[k2] ? x[k1] : x[k2];
 

If k1 or k2 index, calculated in such a way, is out of range 0..x.length-1, this method throws IndexOutOfBoundsException.

This function can be useful for algorithms of non-maximum suppression, usually in combination with Func.SELECT_FROM_8_DIRECTIONS_2D, for example, in algorithms like Canny edge detector.

This class is immutable and thread-safe: there are no ways to modify settings of the created instance.

Author:
Daniel Alievsky
  • Method Details

    • getInstance

      public static MaxFromTwoSelectedNumbersFunc getInstance(int indexShift)
      Returns an instance of this class for the given index shift.

      Parameters:
      indexShift - the index shift (distance between compared numbers); must be non-negative.
      Returns:
      an instance of this class
      Throws:
      IllegalArgumentException - if indexShift<0.
    • get

      public double get(double... x)
      Description copied from interface: Func
      Returns the result of this function for the given arguments: f(x0, x1, ..., xx.length-1).

      This method must not change the values of x elements!

      Specified by:
      get in interface Func
      Specified by:
      get in class AbstractFunc
      Parameters:
      x - the function arguments.
      Returns:
      the function result.
    • toString

      public String toString()
      Returns a brief string description of this object.
      Overrides:
      toString in class Object
      Returns:
      a brief string description of this object.