Class ContrastingFunc
- All Implemented Interfaces:
Func
Contrasting function: by default,
f(x0, x1, x2, x3) =
M * (x0/x1) * (x−x2) /
max(x3−x2,threshold),
where
If x0=x1=b is a brightness of some image pixel, x2..x3 represents some brightness range, and threshold is a positive value ≤x3−x2, this function performs contrasting of x2..x3 range to 0..M range: all values b≤x2 are transformed to 0, all values b≥x3 are transformed to M, and values between x2 and x3 are proportionally transformed to values between 0 and M. However, if x3−x2 is too small, i.e. <threshold, this value is used instead of x3−x2: b=x3 and greater values are transformed not to M, but only to M*(x3−x2)/threshold. It allows avoiding to perform very "strong" contrasting when x3−x2 is very small and, in particular, avoiding 0/0 when x3=x2. Usually x2 and x3 are the minimal (or almost minimal) and the maximal (or almost maximal) brightnesses of the image or of some image area.
If x0≠x1, this functions performs contrasting of x1
to the contrasted value
The described implementation is default and used when you create an instance by
getInstance(M,threshold)
call.
But you can create your own implementation of this abstract class, for example, with another
logic of threshold processing. It is supposed that any implementation of this class
in a case of 3 arguments performs some "contrasting" of the brightness, specified by the 1st argument,
accordingly the brightness range, specified by 2nd and 3rd argument, and that in a case of 4 arguments
The get(double...)
method of the instances of this class requires at least 3 arguments
and throws IndexOutOfBoundsException if the number of arguments is 0, 1 or 2.
All implementations of this class are immutable and thread-safe: there are no ways to modify settings of the created instance.
- Author:
- Daniel Alievsky
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.algart.math.functions.Func
Func.Updatable
-
Field Summary
Fields inherited from interface net.algart.math.functions.Func
ABS, ABS_DIFF, HALF_X_MINUS_Y, HALF_X_PLUS_Y, HALF_Y_MINUS_X, IDENTITY, MAX, MIN, POSITIVE_DIFF, REVERSE, SELECT, SELECT_FROM_8_DIRECTIONS_2D, SELECT_IF_GREATER, SELECT_IF_GREATER_OR_EQUAL, SHIFTS_ALONG_8_DIRECTIONS_2D, UPDATABLE_IDENTITY, X_MINUS_Y, X_PLUS_Y, Y_MINUS_X
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal double
get()
Equivalent toget
(new double[0]).final double
get
(double x0) Equivalent toget
(new double[] {x0}).double
get
(double... x) This method is fully implemented in this class: it returnsget(x[0],x[1],x[2],x[3])
, if x.length>=4, returnsget(x[0],x[1],x[2])
, if x.length==3, and throws IndexOutOfBoundsException, if x.length<3.final double
get
(double x0, double x1) Equivalent toget
(new double[] {x0, x1}).abstract double
get
(double x0, double x1, double x2) Equivalent toget
(new double[] {x0, x1, x2}).double
get
(double x0, double x1, double x2, double x3) This method is fully implemented in this class: it returns x0/x1*get(x1,x2,x3)
.static ContrastingFunc
getInstance
(double m, double threshold) Returns an instance of this class, providing the default behaviour described in thecomments to this class
.
-
Constructor Details
-
ContrastingFunc
protected ContrastingFunc()Creates an instance of this class.
-
-
Method Details
-
getInstance
Returns an instance of this class, providing the default behaviour described in thecomments to this class
.- Parameters:
m
- the M constant: maximal value returned by this function.threshold
- the threshold constant.- Returns:
- the contrasting function with the given parameters.
-
get
public double get(double... x) This method is fully implemented in this class: it returnsget(x[0],x[1],x[2],x[3])
, if x.length>=4, returnsget(x[0],x[1],x[2])
, if x.length==3, and throws IndexOutOfBoundsException, if x.length<3.- Specified by:
get
in interfaceFunc
- Parameters:
x
- the function arguments.- Returns:
- the function result.
- Throws:
IndexOutOfBoundsException
- if the number of passed arguments is 0, 1 or 2.
-
get
public final double get()Description copied from interface:Func
Equivalent toget
(new double[0]). Provides better performance because it does not require Java array creation. -
get
public final double get(double x0) Description copied from interface:Func
Equivalent toget
(new double[] {x0}). Provides better performance because it does not require Java array creation. -
get
public final double get(double x0, double x1) Description copied from interface:Func
Equivalent toget
(new double[] {x0, x1}). Provides better performance because it does not require Java array creation. -
get
public abstract double get(double x0, double x1, double x2) Description copied from interface:Func
Equivalent toget
(new double[] {x0, x1, x2}). Provides better performance because it does not require Java array creation. -
get
public double get(double x0, double x1, double x2, double x3) This method is fully implemented in this class: it returns x0/x1*get(x1,x2,x3)
. You can override it toe provide better performance or precision.
-