Class AbstractRankMorphology
- All Implemented Interfaces:
Cloneable
,ArrayProcessor
,ArrayProcessorWithContextSwitching
,Morphology
,RankMorphology
- Direct Known Subclasses:
BasicRankMorphology
A skeletal implementation of the RankMorphology
interface to minimize
the effort required to implement this interface.
This class extends AbstractMorphology
and inherits from it all implementations of
Morphology
methods, excepting dilationOrErosion
, which is declared here as abstract.
Among methods of RankMorphology
interface, this class implements the 2nd method
from each triplet: 1) asOperation, 2) operation, creating new matrix and
3) operation, storing result in the 1st dest argument.
Every 2nd method from such a triplet is implemented via the 3rd one:
it creates the necessary resulting updatable matrix and pass it as dest
argument to the 3rd method. See more details in comments to the methods of this class.
In addition, this class fully implements all 3 methods
asMean
, mean
(creating new matrix) and
mean
(storing result in dest argument) via
the corresponding asFunctionOfSum
and functionOfSum
methods.
Also this class fully implements the methods which get the percentile indexes in a form of double
parameters: these methods are implemented via the analogous methods getting the percentile indexes in
Matrix
parameters.
Besides implementing methods of RankMorphology
, this class declares
constantPercentileMatrix(Matrix, double)
method, convenient for implementing
methods which get the percentile indexes in a form of double parameters.
- Author:
- Daniel Alievsky
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.algart.matrices.morphology.Morphology
Morphology.SubtractionMode
-
Field Summary
Fields inherited from interface net.algart.matrices.morphology.RankMorphology
FILL_MAX_VALUE, FILL_MIN_VALUE, FILL_NEAREST_VALUE
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractRankMorphology
(ArrayContext context) Creates an instance of this class with the given context. -
Method Summary
Modifier and TypeMethodDescriptionasDilationOrErosion
(Matrix<? extends PArray> src, Pattern pattern, boolean isDilation) This method must be equivalent toAbstractMorphology.asDilation(Matrix src, Pattern pattern)
if isDilation argument is true or toAbstractMorphology.asErosion(Matrix src, Pattern pattern)
if isDilation argument is false.asFunctionOfPercentilePair
(Matrix<? extends PArray> src, double percentileIndex1, double percentileIndex2, Pattern pattern, Func processingFunc) This implementation just callsasFunctionOfPercentilePair
(src,m1,m2,pattern,processingFunc), wherem1= andconstantPercentileMatrix
(src,percentileIndex1)m2= .constantPercentileMatrix
(src,percentileIndex2)asFunctionOfPercentilePair
(Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes1, Matrix<? extends PArray> percentileIndexes2, Pattern pattern, Func processingFunc) Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the result of some given functionf(v, v1,v2) of the source matrix v and two percentiles v1,v2 of the source matrix by the specified pattern.asFunctionOfSum
(Matrix<? extends PArray> src, Pattern pattern, Func processingFunc) Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the result of some given functionf(S) of the aperture sum S of the source matrix by the specified pattern.This method is fully implemented in this class via the equivalent call ofasFunctionOfSum(Matrix, Pattern, Func)
method, as described incomments to this method
inRankMorphology
interface.asMeanBetweenPercentiles
(Matrix<? extends PArray> src, double fromPercentileIndex, double toPercentileIndex, Pattern pattern, double filler) This implementation just callsasMeanBetweenPercentiles
(src,m1,m2,pattern,filler), wherem1= andconstantPercentileMatrix
(src,fromPercentileIndex)m2= .constantPercentileMatrix
(src,toPercentileIndex)asMeanBetweenPercentiles
(Matrix<? extends PArray> src, Matrix<? extends PArray> fromPercentileIndexes, Matrix<? extends PArray> toPercentileIndexes, Pattern pattern, double filler) Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the mean between 2 percentiles of the source matrix by the specified pattern.asMeanBetweenValues
(Matrix<? extends PArray> src, Matrix<? extends PArray> minValues, Matrix<? extends PArray> maxValues, Pattern pattern, double filler) Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the mean between 2 values of the source matrix by the specified pattern.asPercentile
(Matrix<? extends PArray> src, double percentileIndex, Pattern pattern) This implementation just callsasPercentile
(src,m,pattern), wherem= .constantPercentileMatrix
(src,percentileIndex)asPercentile
(Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes, Pattern pattern) Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the percentile of the source matrix by the specified pattern.asRank
(Class<? extends T> requiredType, Matrix<? extends PArray> baseMatrix, Matrix<? extends PArray> rankedMatrix, Pattern pattern) Returns an immutable view of the passed baseMatrix matrix, such that any reading data from it calculates and returns the ranks of some given values v regarding the source matrix baseMatrix with the specified pattern.constantPercentileMatrix
(Matrix<? extends PArray> src, double percentileIndex) Returns the matrix with the same dimensions as the given src matrix, backed by a constant array with the given value.context
(ArrayContext newContext) This method is implemented here via cloning this object (by standard clone() call) and replacing the value of the field, where a reference to the current context is stored, with newContext value.protected abstract Matrix<? extends UpdatablePArray>
dilationOrErosion
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean isDilation, boolean disableMemoryAllocation) This method must be equivalent toAbstractMorphology.dilation(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
if isDilation argument is true or toAbstractMorphology.erosion(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
if isDilation argument is false.Matrix<? extends UpdatablePArray>
functionOfPercentilePair
(Matrix<? extends PArray> src, double percentileIndex1, double percentileIndex2, Pattern pattern, Func processingFunc) This implementation just callsfunctionOfPercentilePair
(src,m1,m2,pattern,processingFunc), wherem1= andconstantPercentileMatrix
(src,percentileIndex1)m2= .constantPercentileMatrix
(src,percentileIndex2)Matrix<? extends UpdatablePArray>
functionOfPercentilePair
(Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes1, Matrix<? extends PArray> percentileIndexes2, Pattern pattern, Func processingFunc) This implementation creates a new updatable matrix dest by the calldest= , calculates the function of the source matrix and 2 percentiles by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result.functionOfPercentilePair
(dest,src,percentileIndexes1,percentileIndexes2,pattern,processingFunc)void
functionOfPercentilePair
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, double percentileIndex1, double percentileIndex2, Pattern pattern, Func processingFunc) This implementation just callsfunctionOfPercentilePair
(dest,src,m1,m2,pattern,processingFunc), wherem1= andconstantPercentileMatrix
(src,percentileIndex1)m2= .constantPercentileMatrix
(src,percentileIndex2)abstract void
functionOfPercentilePair
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes1, Matrix<? extends PArray> percentileIndexes2, Pattern pattern, Func processingFunc) Equivalent toRankMorphology.functionOfPercentilePair(Matrix, Matrix, Matrix, Pattern, Func)
method, but the result matrix will be placed in the dest argument.Matrix<? extends UpdatablePArray>
functionOfSum
(Matrix<? extends PArray> src, Pattern pattern, Func processingFunc) This implementation creates a new updatable matrix dest by the calldest= , calculates the function of aperture sum by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result.functionOfSum
(dest,src,pattern,processingFunc)abstract void
functionOfSum
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, Func processingFunc) Equivalent toRankMorphology.functionOfSum(Matrix, Pattern, Func)
method, but the result matrix will be placed in the dest argument.Matrix<? extends UpdatablePArray>
void
This method is fully implemented in this class via the equivalent call offunctionOfSum(Matrix, Matrix, Pattern, Func)
method, as described incomments to this method
inRankMorphology
interface.Matrix<? extends UpdatablePArray>
meanBetweenPercentiles
(Matrix<? extends PArray> src, double fromPercentileIndex, double toPercentileIndex, Pattern pattern, double filler) This implementation just callsmeanBetweenPercentiles
(src,m1,m2,pattern,filler), wherem1= andconstantPercentileMatrix
(src,fromPercentileIndex)m2= .constantPercentileMatrix
(src,toPercentileIndex)Matrix<? extends UpdatablePArray>
meanBetweenPercentiles
(Matrix<? extends PArray> src, Matrix<? extends PArray> fromPercentileIndexes, Matrix<? extends PArray> toPercentileIndexes, Pattern pattern, double filler) This implementation creates a new updatable matrix dest by the calldest= , calculates the mean between 2 percentiles by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result.meanBetweenPercentiles
(dest,src,fromPercentileIndexes,toPercentileIndexes,pattern,filler)void
meanBetweenPercentiles
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, double fromPercentileIndex, double toPercentileIndex, Pattern pattern, double filler) This implementation just callsmeanBetweenPercentiles
(dest,src,m1,m2,pattern,filler), wherem1= andconstantPercentileMatrix
(src,fromPercentileIndex)m2= .constantPercentileMatrix
(src,toPercentileIndex)abstract void
meanBetweenPercentiles
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Matrix<? extends PArray> fromPercentileIndexes, Matrix<? extends PArray> toPercentileIndexes, Pattern pattern, double filler) Equivalent toRankMorphology.meanBetweenPercentiles(Matrix, Matrix, Matrix, Pattern, double)
method, but the result matrix will be placed in the dest argument.Matrix<? extends UpdatablePArray>
meanBetweenValues
(Matrix<? extends PArray> src, Matrix<? extends PArray> minValues, Matrix<? extends PArray> maxValues, Pattern pattern, double filler) This implementation creates a new updatable matrix dest by the calldest= , calculates the mean between 2 values by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result.meanBetweenValues
(dest,src,minValues,maxValues,pattern,filler)abstract void
meanBetweenValues
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Matrix<? extends PArray> minValues, Matrix<? extends PArray> maxValues, Pattern pattern, double filler) Equivalent toRankMorphology.meanBetweenValues(Matrix, Matrix, Matrix, Pattern, double)
method, but the result matrix will be placed in the dest argument.Matrix<? extends UpdatablePArray>
percentile
(Matrix<? extends PArray> src, double percentileIndex, Pattern pattern) This implementation just callspercentile
(src,m,pattern), wherem= .constantPercentileMatrix
(src,percentileIndex)Matrix<? extends UpdatablePArray>
percentile
(Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes, Pattern pattern) This implementation creates a new updatable matrix dest by the calldest= , calculates the percentile by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result.percentile
(dest,src,percentileIndexes,pattern)void
percentile
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, double percentileIndex, Pattern pattern) This implementation just callspercentile
(dest,src,m,pattern), wherem= .constantPercentileMatrix
(src,percentileIndex)abstract void
percentile
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes, Pattern pattern) Equivalent toRankMorphology.percentile(Matrix, Matrix, Pattern)
method, but the result matrix will be placed in the dest argument.rank
(Class<? extends T> requiredType, Matrix<? extends PArray> baseMatrix, Matrix<? extends PArray> rankedMatrix, Pattern pattern) This implementation creates a new updatable matrix dest by the calldest= , calculates the rank by the callmemoryModel
.newMatrix
(UpdatablePArray.class,Arrays.elementType
(requiredType),baseMatrix.dimensions()) and returns dest as the result.rank
(dest,baseMatrix,rankedMatrix,pattern)abstract void
rank
(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> baseMatrix, Matrix<? extends PArray> rankedMatrix, Pattern pattern) Equivalent toRankMorphology.rank(Class, Matrix, Matrix, Pattern)
method, but the result matrix will be placed in the dest argument and the required type will be chosen automatically asdest. .type
(PArray.class)Methods inherited from class net.algart.matrices.morphology.AbstractMorphology
asDilation, asErosion, beucherGradient, closing, dilation, dilation, dilation, dilation, dilationErosion, dimensionsAllowed, erosion, erosion, erosion, erosion, erosionDilation, isPseudoCyclic, maskedDilationErosion, maskedErosionDilation, opening, weakDilation, weakErosion
Methods inherited from class net.algart.arrays.AbstractArrayProcessorWithContextSwitching
context, contextPart, memoryModel
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.algart.arrays.ArrayProcessor
context
Methods inherited from interface net.algart.matrices.morphology.Morphology
asDilation, asErosion, beucherGradient, closing, dilation, dilation, dilation, dilation, dilationErosion, erosion, erosion, erosion, erosion, erosionDilation, isPseudoCyclic, maskedDilationErosion, maskedErosionDilation, opening, weakDilation, weakErosion
-
Constructor Details
-
AbstractRankMorphology
Creates an instance of this class with the given context.- Parameters:
context
- the context used by this instance for all operations.
-
-
Method Details
-
context
Description copied from class:AbstractArrayProcessorWithContextSwitching
This method is implemented here via cloning this object (by standard clone() call) and replacing the value of the field, where a reference to the current context is stored, with newContext value. This technique is suitable for most implementation. However, if you need, you can override this method; maybe, it is enough to override clone() instead.
- Specified by:
context
in interfaceArrayProcessorWithContextSwitching
- Specified by:
context
in interfaceMorphology
- Specified by:
context
in interfaceRankMorphology
- Overrides:
context
in classAbstractMorphology
- Parameters:
newContext
- another context, used by the returned instance; may be null.- Returns:
- new instance with another context.
-
asDilationOrErosion
protected abstract Matrix<? extends PArray> asDilationOrErosion(Matrix<? extends PArray> src, Pattern pattern, boolean isDilation) Description copied from class:AbstractMorphology
This method must be equivalent toAbstractMorphology.asDilation(Matrix src, Pattern pattern)
if isDilation argument is true or toAbstractMorphology.asErosion(Matrix src, Pattern pattern)
if isDilation argument is false.The implementations of those methods, provided by this class, just call this method with corresponding isDilation argument.
- Specified by:
asDilationOrErosion
in classAbstractMorphology
- Parameters:
src
- the source matrix.pattern
- the pattern.isDilation
- what should return this method: dilation or erosion.- Returns:
- the "lazy" matrix containing the dilation or erosion of the source matrix.
-
dilationOrErosion
protected abstract Matrix<? extends UpdatablePArray> dilationOrErosion(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean isDilation, boolean disableMemoryAllocation) Description copied from class:AbstractMorphology
This method must be equivalent toAbstractMorphology.dilation(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
if isDilation argument is true or toAbstractMorphology.erosion(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
if isDilation argument is false. There is the only little difference: if dest argument is null, this methods does not throw NullPointerException, but allocates new matrix with the same dimensions and element type as src and use it for storing the result. The result (newly created matrix or non-null dest argument) is returned as the result of this method.The implementations of
AbstractMorphology.dilation(Matrix dest, Pattern pattern)
,AbstractMorphology.erosion(Matrix dest, Pattern pattern)
,AbstractMorphology.dilation(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
,AbstractMorphology.erosion(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
methods, provided by this class, just call this method with corresponding isDilation argument and with dest==null in a case of first two methods.The implementation of this method, provided by
AbstractMorphology
class, just copies the result ofAbstractMorphology.asDilationOrErosion(Matrix, Pattern, boolean)
asDilationOrErosion} method to dest matrix:Matrices.copy
(context, castDest,AbstractMorphology.asDilationOrErosion(Matrix, Pattern, boolean)
asDilationOrErosion}(src, pattern, isDilation));where castDest is dest if dest.elementType()==src.elementType(), the newly created matrix if dest==null or the dest matrix, cast to the necessary element type, if the source and destination element types are different:
Matrices.asUpdatableFuncMatrix
(true,Func.UPDATABLE_IDENTITY
, src.updatableType(UpdatablePArray.class), dest)The implementations of this method in the inheritors usually provide better algorithms, especially if disableMemoryAllocation argument is false.
- Overrides:
dilationOrErosion
in classAbstractMorphology
- Parameters:
dest
- the target matrix (or null for creating a new matrix).src
- the source matrix.pattern
- the pattern.isDilation
- what should perform this method: dilation or erosion.disableMemoryAllocation
- if false, this method may allocate additional temporary matrices for optimizing the algorithm speed; if true, no any work memory will be allocated.- Returns:
- the reference to dest argument if it is not null, newly allocated resulting matrix in other case.
-
asPercentile
public abstract Matrix<? extends PArray> asPercentile(Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes, Pattern pattern) Description copied from interface:RankMorphology
Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the percentile of the source matrix by the specified pattern. See thecomments to this class
, section 4 about the "percentile" term. The real index r of the percentile for every element of the result is equal to the corresponding element of percentileIndexes matrix. Theelement type
of the created matrix is the same as the element type of the source one.If the element type of the source matrix (and, thus, of the result) is fixed-point — boolean, char, byte, short, int or long — then we need to round the real percentile
v(r)/σ , defined in the comments to this class. In this case, this method, instead of the real valuev(r)/σ , returns an integerw/σ , where w is:- either the integer result of
, if this object works in the simple histogram model (where b is the histogram, corresponding to every aperture position),Histogram.iValue
(b, (long)Math.floor(r)) - or the integer result of
, if it works in the precise histogram model.Histogram.iPreciseValue
(b, r)
1/σ is a positive integer number, andw/σ=w*2β−μ ,β = src. , μ is the binary logarithm of the histogram length M — see thearray()
.bitsPerElement()
comments to this class
, section 3. So, if μ is chosen less than the precision of this matrix β (8 for byte, 16 for short, etc.), thenβ−μ lowest bits in the result will be always zero. ForBasicRankMorphology
object, μ is chosen whileinstantiating this object
asmin(bitLevels[bitLevels.length-1], β) .- Specified by:
asPercentile
in interfaceRankMorphology
- Parameters:
src
- the source matrix.percentileIndexes
- the matrix containing r argument: the indexes of the percentile for every element of the result.pattern
- the pattern: the shape of the aperture.- Returns:
- the "lazy" matrix containing the percentile of the source matrix.
- See Also:
- either the integer result of
-
asPercentile
public Matrix<? extends PArray> asPercentile(Matrix<? extends PArray> src, double percentileIndex, Pattern pattern) This implementation just callsasPercentile
(src,m,pattern), wherem= .constantPercentileMatrix
(src,percentileIndex)- Specified by:
asPercentile
in interfaceRankMorphology
- Parameters:
src
- the source matrix.percentileIndex
- r argument of the percentile.pattern
- the pattern: the shape of the aperture.- Returns:
- the "lazy" matrix containing the percentile of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
percentile
public Matrix<? extends UpdatablePArray> percentile(Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes, Pattern pattern) This implementation creates a new updatable matrix dest by the calldest= , calculates the percentile by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result. All necessary checks of correctness of the arguments are performed before allocating new matrix.percentile
(dest,src,percentileIndexes,pattern)- Specified by:
percentile
in interfaceRankMorphology
- Parameters:
src
- the source matrix.percentileIndexes
- the matrix containing r argument: the indexes of the percentile for every element of the result.pattern
- the pattern: the shape of the aperture.- Returns:
- the percentile of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
percentile
public Matrix<? extends UpdatablePArray> percentile(Matrix<? extends PArray> src, double percentileIndex, Pattern pattern) This implementation just callspercentile
(src,m,pattern), wherem= .constantPercentileMatrix
(src,percentileIndex)- Specified by:
percentile
in interfaceRankMorphology
- Parameters:
src
- the source matrix.percentileIndex
- r argument of the percentile.pattern
- the pattern: the shape of the aperture.- Returns:
- the percentile of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
percentile
public abstract void percentile(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes, Pattern pattern) Description copied from interface:RankMorphology
Equivalent toRankMorphology.percentile(Matrix, Matrix, Pattern)
method, but the result matrix will be placed in the dest argument.If the
element type
of the passed dest matrix is the same as the element type of the source one, the result, saved in dest, will be identically equal to the result ofRankMorphology.percentile(Matrix, Matrix, Pattern)
method with the same src, percentileIndexes and pattern arguments. In other case, the result, saved in dest, will be equal toMatrices.asFuncMatrix
(true,Func.IDENTITY
, dest.array().type()
,percentile
(src, percentileIndexes, pattern))So, even if the precision of dest matrix is better than the precision of src — for example, if
src. is byte, butelementType()
dest. is double — this method does not try to calculate more precise percentile and rounds results likeelementType()
andRankMorphology.asPercentile(Matrix, Matrix, Pattern)
methods.RankMorphology.percentile(Matrix, Matrix, Pattern)
- Specified by:
percentile
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.percentileIndexes
- the matrix containing r argument: the indexes of the percentile for every element of the result.pattern
- the pattern: the shape of the aperture.- See Also:
-
percentile
public void percentile(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, double percentileIndex, Pattern pattern) This implementation just callspercentile
(dest,src,m,pattern), wherem= .constantPercentileMatrix
(src,percentileIndex)- Specified by:
percentile
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.percentileIndex
- r argument of the percentile.pattern
- the pattern: the shape of the aperture.- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
asRank
public abstract <T extends PArray> Matrix<T> asRank(Class<? extends T> requiredType, Matrix<? extends PArray> baseMatrix, Matrix<? extends PArray> rankedMatrix, Pattern pattern) Description copied from interface:RankMorphology
Returns an immutable view of the passed baseMatrix matrix, such that any reading data from it calculates and returns the ranks of some given values v regarding the source matrix baseMatrix with the specified pattern. See thecomments to this class
, section 4 about the "rank" term. The real value v for every element of the result is equal to the corresponding element of rankedMatrix matrix.The matrix, returned by this method, is immutable, and the class of its built-in array implements one of the basic interfaces
BitArray
,CharArray
,ByteArray
,ShortArray
,IntArray
,LongArray
,FloatArray
orDoubleArray
. The class of desired interface (one of 8 possible classes) must be passed as requiredType argument. So, it defines the element type of the returned matrix. The rules of casting the floating-point ranks to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.The element types of baseMatrix and rankedMatrix are usually equal. If they are different (
baseMatrix. ), this method replaces rankedMatrix withelementType()
!=rankedMatrix.elementType()
Matrices.asFuncMatrix
(true,Func.IDENTITY
, baseMatrix.array().type()
, rankedMatrix)before all other calculations. In other words, this method always casts the type of the ranked elements to the type of baseMatrix elements. As a result, we can be sure, that if the source baseMatrix matrix is fixed-point (boolean, char, byte, short, int or long elements), then the rank
r(v*σ) , according to the definition of the "rank" term, will be an integer number. In this case, you can specify requiredType=IntArray.class and get the precise rank without precision loss. Moreover, if you know that the number of points in the pattern (pattern. ) is less thanpointCount()
216=65536 or28=256 , it is enough to specify correspondingly requiredType=ShortArray.class or ByteArray.class.- Specified by:
asRank
in interfaceRankMorphology
- Parameters:
requiredType
- the desired type of the built-in array in the returned matrix.baseMatrix
- the source matrix.rankedMatrix
- the matrix containing v argument: the values, the rank of which should be calculated.pattern
- the pattern: the shape of the aperture.- Returns:
- the "lazy" matrix containing the rank of the given values.
- See Also:
-
rank
public <T extends PArray> Matrix<? extends T> rank(Class<? extends T> requiredType, Matrix<? extends PArray> baseMatrix, Matrix<? extends PArray> rankedMatrix, Pattern pattern) This implementation creates a new updatable matrix dest by the calldest= , calculates the rank by the callmemoryModel
.newMatrix
(UpdatablePArray.class,Arrays.elementType
(requiredType),baseMatrix.dimensions()) and returns dest as the result. All necessary checks of correctness of the arguments are performed before allocating new matrix.rank
(dest,baseMatrix,rankedMatrix,pattern)- Specified by:
rank
in interfaceRankMorphology
- Parameters:
requiredType
- the desired type of the built-in array in the returned matrix.baseMatrix
- the source matrix.rankedMatrix
- the matrix containing v argument: the values, the rank of which should be calculated.pattern
- the pattern: the shape of the aperture.- Returns:
- the rank of the given values.
- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to baseMatrix.dimCount()
, or if requiredType is not one of classesUpdatableBitArray
.class /BitArray
.class,UpdatableCharArray
.class /CharArray
.class,UpdatableByteArray
.class /ByteArray
.class,UpdatableShortArray
.class /ShortArray
.class,UpdatableIntArray
.class /IntArray
.class,UpdatableLongArray
.class /LongArray
.class,UpdatableFloatArray
.class /FloatArray
.class orUpdatableDoubleArray
.class /DoubleArray
.class.- See Also:
-
rank
public abstract void rank(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> baseMatrix, Matrix<? extends PArray> rankedMatrix, Pattern pattern) Description copied from interface:RankMorphology
Equivalent toRankMorphology.rank(Class, Matrix, Matrix, Pattern)
method, but the result matrix will be placed in the dest argument and the required type will be chosen automatically asdest. . More precisely, the result, saved in dest, will be equal totype
(PArray.class)rank
(dest.array().type()
, baseMatrix, rankedMatrix, pattern)The element types of baseMatrix and rankedMatrix are usually equal. If they are different (
baseMatrix. ), this method replaces rankedMatrix withelementType()
!=rankedMatrix.elementType()
Matrices.asFuncMatrix
(true,Func.IDENTITY
, baseMatrix.array().type()
, rankedMatrix)before all other calculations. In other words, this method always casts the type of the ranked elements to the type of baseMatrix elements. As a result, we can be sure, that if the source baseMatrix matrix is fixed-point (boolean, char, byte, short, int or long elements), then the rank
r(v*σ) , according to the definition of the "rank" term, will be an integer number. In this case, you can specify requiredType=IntArray.class and get the precise rank without precision loss. Moreover, if you know that the number of points in the pattern (pattern. ) is less thanpointCount()
216=65536 or28=256 , it is enough to specify correspondingly requiredType=ShortArray.class or ByteArray.class. The less result precision allows you to save memory.- Specified by:
rank
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.baseMatrix
- the source matrix.rankedMatrix
- the matrix containing v argument: the values, the rank of which should be calculated.pattern
- the pattern: the shape of the aperture.- See Also:
-
asMeanBetweenPercentiles
public abstract Matrix<? extends PArray> asMeanBetweenPercentiles(Matrix<? extends PArray> src, Matrix<? extends PArray> fromPercentileIndexes, Matrix<? extends PArray> toPercentileIndexes, Pattern pattern, double filler) Description copied from interface:RankMorphology
Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the mean between 2 percentiles of the source matrix by the specified pattern. See thecomments to this class
, section 4 about the "mean between 2 percentiles" term. The real indexes r1 and r2 of the percentiles for every element of the result are equal to the corresponding elements of fromPercentileIndexes and toPercentileIndexes matrices. The reserved value filler is specified by the last argument of this method. Theelement type
of the created matrix is the same as the element type of the source one.If the element type of the source matrix (and, thus, of the result) is fixed-point — boolean, char, byte, short, int or long — then we need to round the real mean, defined in the comments to this class. In this case, the found mean value m is usually truncated to its integer part
⌊m⌋=(long)m (remember that the mean value, according to our definition, is always ≥0). More precisely, the rules of casting the floating-point means to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.- Specified by:
asMeanBetweenPercentiles
in interfaceRankMorphology
- Parameters:
src
- the source matrix.fromPercentileIndexes
- the matrix containing r1 argument: the indexes of the less percentile of the averaged range for every element of the result.toPercentileIndexes
- the matrix containing r2 argument: the indexes of the greater percentile of the averaged range for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr1≥r2 .- Returns:
- the "lazy" matrix containing the mean between 2 given percentiles of the source matrix.
- See Also:
-
asMeanBetweenPercentiles
public Matrix<? extends PArray> asMeanBetweenPercentiles(Matrix<? extends PArray> src, double fromPercentileIndex, double toPercentileIndex, Pattern pattern, double filler) This implementation just callsasMeanBetweenPercentiles
(src,m1,m2,pattern,filler), wherem1= andconstantPercentileMatrix
(src,fromPercentileIndex)m2= .constantPercentileMatrix
(src,toPercentileIndex)- Specified by:
asMeanBetweenPercentiles
in interfaceRankMorphology
- Parameters:
src
- the source matrix.fromPercentileIndex
- r1 argument: the index of the less percentile of the averaged range for every element of the result.toPercentileIndex
- r2 argument: the indexes of the greater percentile of the averaged range for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr1≥r2 .- Returns:
- the "lazy" matrix containing the mean between 2 given percentiles of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
meanBetweenPercentiles
public Matrix<? extends UpdatablePArray> meanBetweenPercentiles(Matrix<? extends PArray> src, Matrix<? extends PArray> fromPercentileIndexes, Matrix<? extends PArray> toPercentileIndexes, Pattern pattern, double filler) This implementation creates a new updatable matrix dest by the calldest= , calculates the mean between 2 percentiles by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result. All necessary checks of correctness of the arguments are performed before allocating new matrix.meanBetweenPercentiles
(dest,src,fromPercentileIndexes,toPercentileIndexes,pattern,filler)- Specified by:
meanBetweenPercentiles
in interfaceRankMorphology
- Parameters:
src
- the source matrix.fromPercentileIndexes
- the matrix containing r1 argument: the indexes of the less percentile of the averaged range for every element of the result.toPercentileIndexes
- the matrix containing r2 argument: the indexes of the greater percentile of the averaged range for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr1≥r2 .- Returns:
- the mean between 2 given percentiles of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
meanBetweenPercentiles
public Matrix<? extends UpdatablePArray> meanBetweenPercentiles(Matrix<? extends PArray> src, double fromPercentileIndex, double toPercentileIndex, Pattern pattern, double filler) This implementation just callsmeanBetweenPercentiles
(src,m1,m2,pattern,filler), wherem1= andconstantPercentileMatrix
(src,fromPercentileIndex)m2= .constantPercentileMatrix
(src,toPercentileIndex)- Specified by:
meanBetweenPercentiles
in interfaceRankMorphology
- Parameters:
src
- the source matrix.fromPercentileIndex
- r1 argument: the index of the less percentile of the averaged range for every element of the result.toPercentileIndex
- r2 argument: the indexes of the greater percentile of the averaged range for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr1≥r2 .- Returns:
- the mean between 2 given percentiles of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
meanBetweenPercentiles
public abstract void meanBetweenPercentiles(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Matrix<? extends PArray> fromPercentileIndexes, Matrix<? extends PArray> toPercentileIndexes, Pattern pattern, double filler) Description copied from interface:RankMorphology
Equivalent toRankMorphology.meanBetweenPercentiles(Matrix, Matrix, Matrix, Pattern, double)
method, but the result matrix will be placed in the dest argument.If the element type of dest matrix is fixed-point — boolean, char, byte, short, int or long — then we need to round the real mean, defined in the comments to this class. In this case, the found mean value m is usually truncated to its integer part
⌊m⌋=(long)m (remember that the mean value, according to our definition, is always ≥0). More precisely, the rules of casting the floating-point means to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.- Specified by:
meanBetweenPercentiles
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.fromPercentileIndexes
- the matrix containing r1 argument: the indexes of the less percentile of the averaged range for every element of the result.toPercentileIndexes
- the matrix containing r2 argument: the indexes of the greater percentile of the averaged range for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr1≥r2 .- See Also:
-
meanBetweenPercentiles
public void meanBetweenPercentiles(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, double fromPercentileIndex, double toPercentileIndex, Pattern pattern, double filler) This implementation just callsmeanBetweenPercentiles
(dest,src,m1,m2,pattern,filler), wherem1= andconstantPercentileMatrix
(src,fromPercentileIndex)m2= .constantPercentileMatrix
(src,toPercentileIndex)- Specified by:
meanBetweenPercentiles
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.fromPercentileIndex
- r1 argument: the index of the less percentile of the averaged range for every element of the result.toPercentileIndex
- r2 argument: the indexes of the greater percentile of the averaged range for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr1≥r2 .- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
asMeanBetweenValues
public abstract Matrix<? extends PArray> asMeanBetweenValues(Matrix<? extends PArray> src, Matrix<? extends PArray> minValues, Matrix<? extends PArray> maxValues, Pattern pattern, double filler) Description copied from interface:RankMorphology
Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the mean between 2 values of the source matrix by the specified pattern. See thecomments to this class
, section 4 about the "mean between 2 values" term. The real numbers v1 and v2 for every element of the result are equal to the corresponding elements of minValues and maxValues matrices. The reserved value filler and the mode of calculation (for the caser(v1*σ)≥r(v2*σ) ) are specified by the last filler argument of this method:- if filler argument is
RankMorphology.FILL_MIN_VALUE
(Double.NEGATIVE_INFINITY), the mode B is used; - if filler argument is
RankMorphology.FILL_MAX_VALUE
(Double.POSITIVE_INFINITY), the mode C is used; - if filler argument is
RankMorphology.FILL_NEAREST_VALUE
(Double.NaN), the mode D is used; - if filler argument contains any other value, the mode A is used and this argument specifies the reserved value filler.
element type
of the created matrix is the same as the element type of the source one.If the element type of the source matrix (and, thus, of the result) is fixed-point — boolean, char, byte, short, int or long — then we need to round the real mean, defined in the comments to this class. In this case, the found mean value m is usually truncated to its integer part
⌊m⌋=(long)m (remember that the mean value, according to our definition, is always ≥0). More precisely, the rules of casting the floating-point means to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.- Specified by:
asMeanBetweenValues
in interfaceRankMorphology
- Parameters:
src
- the source matrix.minValues
- the matrix containing v1 argument: the low bound of the averaged range of values for every element of the result.maxValues
- the matrix containing v2 argument: the high bound of the averaged range of values for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr(v1*σ)≥r(v2*σ) , or one of the special keysRankMorphology.FILL_MIN_VALUE
,RankMorphology.FILL_MAX_VALUE
,RankMorphology.FILL_NEAREST_VALUE
, which mean using of special calculation modes B, C, D.- Returns:
- the "lazy" matrix containing the mean between 2 given values of the source matrix.
- See Also:
- if filler argument is
-
meanBetweenValues
public Matrix<? extends UpdatablePArray> meanBetweenValues(Matrix<? extends PArray> src, Matrix<? extends PArray> minValues, Matrix<? extends PArray> maxValues, Pattern pattern, double filler) This implementation creates a new updatable matrix dest by the calldest= , calculates the mean between 2 values by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result. All necessary checks of correctness of the arguments are performed before allocating new matrix.meanBetweenValues
(dest,src,minValues,maxValues,pattern,filler)- Specified by:
meanBetweenValues
in interfaceRankMorphology
- Parameters:
src
- the source matrix.minValues
- the matrix containing v1 argument: the low bound of the averaged range of values for every element of the result.maxValues
- the matrix containing v2 argument: the high bound of the averaged range of values for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr(v1*σ)≥r(v2*σ) , or one of the special keysRankMorphology.FILL_MIN_VALUE
,RankMorphology.FILL_MAX_VALUE
,RankMorphology.FILL_NEAREST_VALUE
, which mean using of special calculation modes B, C, D.- Returns:
- the mean between 2 given values of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
meanBetweenValues
public abstract void meanBetweenValues(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Matrix<? extends PArray> minValues, Matrix<? extends PArray> maxValues, Pattern pattern, double filler) Description copied from interface:RankMorphology
Equivalent toRankMorphology.meanBetweenValues(Matrix, Matrix, Matrix, Pattern, double)
method, but the result matrix will be placed in the dest argument.If the element type of dest matrix is fixed-point — boolean, char, byte, short, int or long — then we need to round the real mean, defined in the comments to this class. In this case, the found mean value m is usually truncated to its integer part
⌊m⌋=(long)m (remember that the mean value, according to our definition, is always ≥0). More precisely, the rules of casting the floating-point means to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.- Specified by:
meanBetweenValues
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.minValues
- the matrix containing v1 argument: the low bound of the averaged range of values for every element of the result.maxValues
- the matrix containing v2 argument: the high bound of the averaged range of values for every element of the result.pattern
- the pattern: the shape of the aperture.filler
- the reserved value, returned whenr(v1*σ)≥r(v2*σ) , or one of the special keysRankMorphology.FILL_MIN_VALUE
,RankMorphology.FILL_MAX_VALUE
,RankMorphology.FILL_NEAREST_VALUE
, which mean using of special calculation modes B, C, D.- See Also:
-
asMean
This method is fully implemented in this class via the equivalent call ofasFunctionOfSum(Matrix, Pattern, Func)
method, as described incomments to this method
inRankMorphology
interface.- Specified by:
asMean
in interfaceRankMorphology
- Parameters:
src
- the source matrix.pattern
- the pattern: the shape of the aperture.- Returns:
- the "lazy" matrix containing the mean of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
mean
This implementation creates a new updatable matrix dest by the calldest= , calculates the mean by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result. All necessary checks of correctness of the arguments are performed before allocating new matrix.mean
(dest,src,pattern)- Specified by:
mean
in interfaceRankMorphology
- Parameters:
src
- the source matrix.pattern
- the pattern: the shape of the aperture.- Returns:
- the mean of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
mean
public void mean(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern) This method is fully implemented in this class via the equivalent call offunctionOfSum(Matrix, Matrix, Pattern, Func)
method, as described incomments to this method
inRankMorphology
interface.- Specified by:
mean
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.pattern
- the pattern: the shape of the aperture.- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
asFunctionOfSum
public abstract Matrix<? extends PArray> asFunctionOfSum(Matrix<? extends PArray> src, Pattern pattern, Func processingFunc) Description copied from interface:RankMorphology
Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the result of some given functionf(S) of the aperture sum S of the source matrix by the specified pattern. See thecomments to this class
, section 4 about the "aperture sum" term. Theelement type
of the created matrix is the same as the element type of the source one.The function, applied to each calculated aperture sum S, is specified via processingFunc argument. Namely, for each aperture position this method calculates the aperture sum S of the source matrix and returns
processingFunc. in the corresponding element of the resulting matrix.get
(S)If the element type of the source matrix (and, thus, of the result) is fixed-point — boolean, char, byte, short, int or long — then we need to round the real function result. In this case, the found function result f is usually truncated to its integer part
(long)f . More precisely, the rules of casting the floating-point function results to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.This method can be considered as a generalization of
RankMorphology.asMean(Matrix, Pattern)
.- Specified by:
asFunctionOfSum
in interfaceRankMorphology
- Parameters:
src
- the source matrix.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated aperture sum.- Returns:
- the "lazy" matrix containing the result of the given function for the aperture sum of the source matrix.
- See Also:
-
functionOfSum
public Matrix<? extends UpdatablePArray> functionOfSum(Matrix<? extends PArray> src, Pattern pattern, Func processingFunc) This implementation creates a new updatable matrix dest by the calldest= , calculates the function of aperture sum by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result. All necessary checks of correctness of the arguments are performed before allocating new matrix.functionOfSum
(dest,src,pattern,processingFunc)- Specified by:
functionOfSum
in interfaceRankMorphology
- Parameters:
src
- the source matrix.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated aperture sum.- Returns:
- the result of the given function for the aperture sum of the source matrix.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
functionOfSum
public abstract void functionOfSum(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, Func processingFunc) Description copied from interface:RankMorphology
Equivalent toRankMorphology.functionOfSum(Matrix, Pattern, Func)
method, but the result matrix will be placed in the dest argument.If the element type of dest matrix is fixed-point — boolean, char, byte, short, int or long — then we need to round the real function result. In this case, the found function result f is usually truncated to its integer part
(long)f . More precisely, the rules of casting the floating-point function results to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.This method can be considered as a generalization of
RankMorphology.mean(Matrix, Matrix, Pattern)
.- Specified by:
functionOfSum
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated aperture sum.- See Also:
-
asFunctionOfPercentilePair
public abstract Matrix<? extends PArray> asFunctionOfPercentilePair(Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes1, Matrix<? extends PArray> percentileIndexes2, Pattern pattern, Func processingFunc) Description copied from interface:RankMorphology
Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the result of some given functionf(v, v1,v2) of the source matrix v and two percentiles v1,v2 of the source matrix by the specified pattern. See thecomments to this class
, section 4 about the "percentile" term. The real indexes r of two percentiles for every element of the result are equal to the corresponding elements of percentileIndexes1 (for v1) or percentileIndexes2 matrix (for v2). Theelement type
of the created matrix is the same as the element type of the source one.The function, applied to each calculated three
(v,v1,v2) , is specified via processingFunc argument. Namely, for each aperture position x this method takes the value v — the element of the source matrix src at this aperture position x, calculates two percentiles v1 and v2 of the source matrix and returnsprocessingFunc. in the corresponding element of the resulting matrix.get
(v,v1,v2)If the element type of the source matrix (and, thus, of the result) is fixed-point — boolean, char, byte, short, int or long — then we need to round the real function result. In this case, the found function result f is usually truncated to its integer part
(long)f . More precisely, the rules of casting the floating-point function results to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.You can get the same results by 2 calls of
RankMorphology.asPercentile(Matrix, Matrix, Pattern)
method for both matrices of percentile indexes and applying the function to them and to the source matrix via method. But such a way works slower and is less convenient, than this method. A typical application of this method in image processing area is the contrasting image — in this case, we recommend usingMatrices.asFuncMatrix(Func, Class, Matrix, Matrix, Matrix)
ContrastingFunc
object as processingFunc argument.- Specified by:
asFunctionOfPercentilePair
in interfaceRankMorphology
- Parameters:
src
- the source matrix.percentileIndexes1
- the 1st matrix containing r argument: the indexes of the 1st percentile v1 for every element of the result.percentileIndexes2
- the 2nd matrix containing r argument: the indexes of the 2nd percentile v2 for every element of the result.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated three(v,v1,v2) , where v is the element of the source matrix, v1 and v2 are the corresponding percentiles.- Returns:
- the "lazy" matrix containing the result of the given function.
- See Also:
-
asFunctionOfPercentilePair
public Matrix<? extends PArray> asFunctionOfPercentilePair(Matrix<? extends PArray> src, double percentileIndex1, double percentileIndex2, Pattern pattern, Func processingFunc) This implementation just callsasFunctionOfPercentilePair
(src,m1,m2,pattern,processingFunc), wherem1= andconstantPercentileMatrix
(src,percentileIndex1)m2= .constantPercentileMatrix
(src,percentileIndex2)- Specified by:
asFunctionOfPercentilePair
in interfaceRankMorphology
- Parameters:
src
- the source matrix.percentileIndex1
- the 1st r argument: the index of the 1st percentile v1.percentileIndex2
- the 2nd r argument: the index of the 2nd percentile v2.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated three(v,v1,v2) , where v is the element of the source matrix, v1 and v2 are the corresponding percentiles.- Returns:
- the "lazy" matrix containing the result of the given function.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
functionOfPercentilePair
public Matrix<? extends UpdatablePArray> functionOfPercentilePair(Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes1, Matrix<? extends PArray> percentileIndexes2, Pattern pattern, Func processingFunc) This implementation creates a new updatable matrix dest by the calldest= , calculates the function of the source matrix and 2 percentiles by the callmemoryModel
.newMatrix
(UpdatablePArray.class,src) and returns dest as the result. All necessary checks of correctness of the arguments are performed before allocating new matrix.functionOfPercentilePair
(dest,src,percentileIndexes1,percentileIndexes2,pattern,processingFunc)- Specified by:
functionOfPercentilePair
in interfaceRankMorphology
- Parameters:
src
- the source matrix.percentileIndexes1
- the 1st matrix containing r argument: the indexes of the 1st percentile v1 for every element of the result.percentileIndexes2
- the 2nd matrix containing r argument: the indexes of the 2nd percentile v2 for every element of the result.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated three(v,v1,v2) , where v is the element of the source matrix, v1 and v2 are the corresponding percentiles.- Returns:
- the result of the given function.
- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
functionOfPercentilePair
public Matrix<? extends UpdatablePArray> functionOfPercentilePair(Matrix<? extends PArray> src, double percentileIndex1, double percentileIndex2, Pattern pattern, Func processingFunc) This implementation just callsfunctionOfPercentilePair
(src,m1,m2,pattern,processingFunc), wherem1= andconstantPercentileMatrix
(src,percentileIndex1)m2= .constantPercentileMatrix
(src,percentileIndex2)- Specified by:
functionOfPercentilePair
in interfaceRankMorphology
- Parameters:
src
- the source matrix.percentileIndex1
- the 1st r argument: the index of the 1st percentile v1.percentileIndex2
- the 2nd r argument: the index of the 2nd percentile v2.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated three(v,v1,v2) , where v is the element of the source matrix, v1 and v2 are the corresponding percentiles.- Returns:
- the result of the given function.
- Throws:
NullPointerException
- if one of the arguments is null.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
functionOfPercentilePair
public abstract void functionOfPercentilePair(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Matrix<? extends PArray> percentileIndexes1, Matrix<? extends PArray> percentileIndexes2, Pattern pattern, Func processingFunc) Description copied from interface:RankMorphology
Equivalent toRankMorphology.functionOfPercentilePair(Matrix, Matrix, Matrix, Pattern, Func)
method, but the result matrix will be placed in the dest argument.If the element type of dest matrix is fixed-point — boolean, char, byte, short, int or long — then we need to round the real function result. In this case, the found function result f is usually truncated to its integer part
(long)f . More precisely, the rules of casting the floating-point function results to the desired element type are the same as inArrays.asFuncArray(boolean, Func, Class, PArray...)
method with the argument truncateOverflows=true.- Specified by:
functionOfPercentilePair
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.percentileIndexes1
- the 1st matrix containing r argument: the indexes of the 1st percentile v1 for every element of the result.percentileIndexes2
- the 2nd matrix containing r argument: the indexes of the 2nd percentile v2 for every element of the result.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated three(v,v1,v2) , where v is the element of the source matrix, v1 and v2 are the corresponding percentiles.- See Also:
-
functionOfPercentilePair
public void functionOfPercentilePair(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, double percentileIndex1, double percentileIndex2, Pattern pattern, Func processingFunc) This implementation just callsfunctionOfPercentilePair
(dest,src,m1,m2,pattern,processingFunc), wherem1= andconstantPercentileMatrix
(src,percentileIndex1)m2= .constantPercentileMatrix
(src,percentileIndex2)- Specified by:
functionOfPercentilePair
in interfaceRankMorphology
- Parameters:
dest
- the target matrix.src
- the source matrix.percentileIndex1
- the 1st r argument: the index of the 1st percentile v1.percentileIndex2
- the 2nd r argument: the index of the 2nd percentile v2.pattern
- the pattern: the shape of the aperture.processingFunc
- the function, which should be applied to every calculated three(v,v1,v2) , where v is the element of the source matrix, v1 and v2 are the corresponding percentiles.- Throws:
NullPointerException
- if one of the arguments is null.SizeMismatchException
- if the passed matrices have different dimensions.IllegalArgumentException
- if the number of the pattern dimensions pattern.dimCount()
is not equal to src.dimCount()
.- See Also:
-
constantPercentileMatrix
public static Matrix<? extends PArray> constantPercentileMatrix(Matrix<? extends PArray> src, double percentileIndex) Returns the matrix with the same dimensions as the given src matrix, backed by a constant array with the given value. More precisely, returnssrc. , wherematrix
(const)const = , ifArrays.nLongCopies
(src.size(), (long)percentileIndex)percentileIndex==(long)percentileIndex ,- or
const = in other case.Arrays.nDoubleCopies
(src.size(), percentileIndex)
- Parameters:
src
- some matrix.percentileIndex
- some filler.- Returns:
- the constant matrix with the same dimensions, filled by percentileIndex.
-