Class ContinuedMorphology
- All Implemented Interfaces:
ArrayProcessor,ArrayProcessorWithContextSwitching,Morphology
- Direct Known Subclasses:
ContinuedRankMorphology
The filter allowing to transform any Morphology object to another instance of that interface,
which uses some non-trivial form of continuation outside the source matrix.
This object is built on the base of some parent object,
implementing Morphology, and some continuation mode.
This object works almost identically to the parent object with the only exception,
that it uses the specified continuation model instead of the default pseudo-cyclic continuation.
More precisely, all methods of this object call the corresponding methods of the parent one.
But before calling any processing method, the source matrix is appended (outside its bounds)
by some area of additional values
with help of Matrix.subMatrix(long[], long[], net.algart.arrays.Matrix.ContinuationMode) method,
using the continuation mode of this filter.
So, all dimensions of the appended matrix are little greater than the corresponding dimensions
of the source one, and extra elements are (virtually) filled by some values according the given continuation mode.
The size of extension along all coordinates depends on the patterns and the performed operation.
After this, the corresponding method of parent object processes the appended matrix,
and the method of this class returns the corresponding submatrix of the result, with dimensions, equal
to the dimensions of the source matrix.
The processing is little different for methods, placing the result into the first argument
dilation(Matrix, Matrix, Pattern) and erosion(Matrix, Matrix, Pattern).
In these cases, the destination (updatable) matrix is (virtually) extended like the source matrix
before calculations with help of
Matrix.subMatrix(long[], long[], net.algart.arrays.Matrix.ContinuationMode) method;
so, the calculated data are correctly stored into the original destination matrix.
The appending along all coordinates is performed in such a way, that the resulting matrix
is the same, as if the source matrix would be virtually appended until the infinity along all directions,
according the selected continuation mode.
Note: Matrix.ContinuationMode.NONE continuation mode cannot be used in this class:
such value of continuationMode argument of the instantiation method
getInstance(Morphology, Matrix.ContinuationMode) leads
to IllegalArgumentException.
Note: in improbable cases, when the dimensions of the source matrix and/or
the sizes of the pattern are extremely large (about 263),
so that the necessary appended matrices should have dimensions or total number of elements,
greater than
This class is 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.matrices.morphology.Morphology
Morphology.SubtractionMode -
Method Summary
Modifier and TypeMethodDescriptionasDilation(Matrix<? extends PArray> src, Pattern pattern) Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the dilation of the source matrix by the specified pattern.Returns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the erosion of the source matrix by the specified pattern.Matrix<? extends UpdatablePArray>beucherGradient(Matrix<? extends PArray> src, Pattern pattern) Matrix<? extends UpdatablePArray>closing(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode) Returns a new updatable matrix, containing the closing of the source matrix by the specified pattern.context()Returns the current context used by this instance for all operations.context(ArrayContext newContext) Switches the context: returns an instance, identical to this one excepting that it uses the specified newContext for all operations.Returns the continuation mode, used by this object for virtual continuing the source matrix.Matrix<? extends UpdatablePArray>Returns a new updatable matrix, containing the dilation of the source matrix by the specified pattern.Matrix<? extends UpdatablePArray>dilation(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode) Extended version ofMorphology.dilation(Matrix, Pattern)method: if subtractionMode argument is notMorphology.SubtractionMode.NONE, returns the difference between the dilation and the src matrix, according the specified mode.voidEquivalent todilation(dest, src, pattern, false).voiddilation(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean disableMemoryAllocation) Equivalent toMorphology.dilation(Matrix, Pattern)method, but the result matrix will be placed in the dest argument.Matrix<? extends UpdatablePArray>dilationErosion(Matrix<? extends PArray> src, Pattern ptn1, Pattern ptn2, Morphology.SubtractionMode subtractionMode) Returns a new updatable matrix, containing the result of sequentialdilation(src, dilationPattern)anderosion(src, erosionPattern)of the source matrix by the specified patterns.Matrix<? extends UpdatablePArray>Returns a new updatable matrix, containing the erosion of the source matrix by the specified pattern.Matrix<? extends UpdatablePArray>erosion(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode) Extended version ofMorphology.erosion(Matrix, Pattern)method: if subtractionMode argument is notMorphology.SubtractionMode.NONE, returns the difference between the erosion and the src matrix, according the specified mode.voidEquivalent toerosion(dest, src, pattern, false).voiderosion(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean disableMemoryAllocation) Equivalent toMorphology.erosion(Matrix, Pattern)method, but the result matrix will be placed in the dest argument.Matrix<? extends UpdatablePArray>erosionDilation(Matrix<? extends PArray> src, Pattern ptn1, Pattern ptn2, Morphology.SubtractionMode subtractionMode) Returns a new updatable matrix, containing the result of sequentialerosion(src, erosionPattern)anddilation(src, dilationPattern)of the source matrix by the specified patterns.static ContinuedMorphologygetInstance(Morphology parent, Matrix.ContinuationMode continuationMode) Returns new instance of this class with the passed parentMorphologyobject and the specified continuation mode.booleanReturns true, if this class works in the defaultpseudo-cyclic continuation mode.Matrix<? extends UpdatablePArray>maskedDilationErosion(Matrix<? extends PArray> src, Pattern ptn1, Pattern ptn2) Returns the elementwise minimum between the source matrix and the result ofdilationErosion(src, dilationPattern, erosionPattern,Morphology.SubtractionMode.NONE) call.Matrix<? extends UpdatablePArray>maskedErosionDilation(Matrix<? extends PArray> src, Pattern ptn1, Pattern ptn2) Returns the elementwise maximum between the source matrix and the result oferosionDilation(src, erosionPattern, dilationPattern,Morphology.SubtractionMode.NONE) call.Matrix<? extends UpdatablePArray>opening(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode) Returns a new updatable matrix, containing the opening of the source matrix by the specified pattern.parent()Returns the parentMorphologyobject, passed togetInstance(Morphology, Matrix.ContinuationMode)method.Matrix<? extends UpdatablePArray>weakDilation(Matrix<? extends PArray> src, Pattern pattern) Returns a new updatable matrix, containing the weak dilation of the source matrix by the specified pattern.Matrix<? extends UpdatablePArray>weakErosion(Matrix<? extends PArray> src, Pattern pattern) Returns a new updatable matrix, containing the weak erosion of the source matrix by the specified pattern.
-
Method Details
-
getInstance
public static ContinuedMorphology getInstance(Morphology parent, Matrix.ContinuationMode continuationMode) Returns new instance of this class with the passed parentMorphologyobject and the specified continuation mode. See comments toMatrix.ContinuationModeclass for more information about possible continuations.- Parameters:
parent- the instance ofMorphologyinterface that will perform all operations.continuationMode- the mode of continuation outside the source matrix.- Returns:
- new instance of this class.
- Throws:
NullPointerException- if parent or continuationMode argument is null.IllegalArgumentException- if continuationMode==Matrix.ContinuationMode.NONE.- See Also:
-
parent
Returns the parentMorphologyobject, passed togetInstance(Morphology, Matrix.ContinuationMode)method.- Returns:
- the parent
Morphologyobject.
-
continuationMode
Returns the continuation mode, used by this object for virtual continuing the source matrix. The returned value is equal to the corresponding argument ofgetInstance(Morphology, Matrix.ContinuationMode)orContinuedRankMorphology.getInstance(RankMorphology, Matrix.ContinuationMode)method.- Returns:
- the continuation mode, that will be used for continuation outside the source matrix.
-
context
Description copied from interface:ArrayProcessorReturns the current context used by this instance for all operations. This method may return null; the classes, implementing this interface, should work in this situation as while usingArrayContext.DEFAULTcontext.- Specified by:
contextin interfaceArrayProcessor- Returns:
- the current context used by this instance; may be null.
-
context
Description copied from interface:ArrayProcessorWithContextSwitchingSwitches the context: returns an instance, identical to this one excepting that it uses the specified newContext for all operations. The returned instance is usually a clone of this one, but there is no guarantees that it is a deep clone. Usually, the returned instance is used only for performing asubtaskof the full task.- Specified by:
contextin interfaceArrayProcessorWithContextSwitching- Specified by:
contextin interfaceMorphology- Parameters:
newContext- another context, used by the returned instance; may be null.- Returns:
- new instance with another context.
-
isPseudoCyclic
public boolean isPseudoCyclic()Description copied from interface:MorphologyReturns true, if this class works in the defaultpseudo-cyclic continuation mode.More precisely, it means that when the value in some element of the processed matrix, returned by a method of this class, depends on elements of the source matrix, lying outside its bounds, then it is supposed that the values outside the source matrix are calculated as described in
Matrix.ContinuationMode.PSEUDO_CYCLIC. Exactly such behaviour is specified in the comments to the basicMorphology.dilation(Matrix, Pattern)andMorphology.erosion(Matrix, Pattern)methods as the default definition of dilation and erosion.This method returns true in
BasicMorphologyandBasicRankMorphologyimplementation. However, it usually returns false inContinuedMorphologyandContinuedRankMorphologyclasses — excepting the only degenerated case when the usedcontinuation modeisPSEUDO_CYCLIC.- Specified by:
isPseudoCyclicin interfaceMorphology- Returns:
- whether this class works in the pseudo-cyclic continuation mode.
-
asDilation
Description copied from interface:MorphologyReturns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the dilation of the source matrix by the specified pattern. SeeMorphology.dilation(Matrix, Pattern)method about the "dilation" term. Theelement typeof the created matrix is the same as the element type of the source one.The result is usually "lazy", that means that this method finishes immediately and all actual calculations are performed while getting elements of the returned matrix. It is true for all implementations provided by this package. However, some implementations may not support lazy dilation; then this method will be equivalent to
Morphology.dilation(Matrix, Pattern).Please note: this method does not require time (if the result is "lazy"), but the resulting matrix can work slowly! For example, reading all its content than work much slower than
Morphology.dilation(Matrix, Pattern)method for complex patterns. Usually you should use it only for very little patterns, or if you know that the implementation of this interface does not provide better algorithm for non-"lazy"Morphology.dilation(Matrix, Pattern)method.- Specified by:
asDilationin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.- Returns:
- the "lazy" matrix containing the dilation of the source matrix by the given pattern.
-
asErosion
Description copied from interface:MorphologyReturns an immutable view of the passed source matrix, such that any reading data from it calculates and returns the erosion of the source matrix by the specified pattern. SeeMorphology.erosion(Matrix, Pattern)method about the "erosion" term. Theelement typeof the created matrix is the same as the element type of the source one.The result is usually "lazy", that means that this method finishes immediately and all actual calculations are performed while getting elements of the returned matrix. It is true for all implementations provided by this package. However, some implementations may not support lazy erosion; then this method will be equivalent to
Morphology.erosion(Matrix, Pattern).Please note: this method does not require time (if the result is "lazy"), but the resulting matrix can work slowly! For example, reading all its content than work much slower than
Morphology.dilation(Matrix, Pattern)method for complex patterns. Usually you should use it only for very little patterns, or if you know that the implementation of this interface does not provide better algorithm for non-"lazy"Morphology.erosion(Matrix, Pattern)method.- Specified by:
asErosionin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.- Returns:
- the "lazy" matrix containing the erosion of the source matrix by the given pattern.
-
dilation
Description copied from interface:MorphologyReturns a new updatable matrix, containing the dilation of the source matrix by the specified pattern.Usually dilation means the elementwise maximum from the set of matrices, obtained by pseudo-cyclic shifting the source matrix by the vectors, equal to all pattern points. More precisely, let mi=
Matrices.asShifted(src,ip.coordinates()), where ip is the point #i from all points contained in the pattern. Then the every element of the returned matrix is the maximum from all corresponding elements of all mi matrices. Theelement typeof the created matrix is the same as the element type of the source one. The byte and short elements are considered to be unsigned. In a case of bit elements, the maximum is equivalent to logical OR.The basic morphology implementation
BasicMorphologystrictly complies with this definition. However, other implementations of this interface may use alternate definitions of the dilation term. For example, some percentile (90% or 80%) may be used instead of strict maximum (as in objects, returned byBasicRankMorphology.getInstance(ArrayContext, double, CustomRankPrecision)method), or elements outside the matrix may be supposed to be filled according some non-trivial rules instead of pseudo-cyclic continuation (as inContinuedMorphologyobjects), or only some region of the matrix may be processed, etc.Please see to know more about the dilation.
- Specified by:
dilationin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.- Returns:
- the result of dilation of the source matrix by the given pattern.
- See Also:
-
erosion
Description copied from interface:MorphologyReturns a new updatable matrix, containing the erosion of the source matrix by the specified pattern.Usually erosion means the elementwise minimum from the set of matrices, obtained by pseudo-cyclic shifting the source matrix by the vectors, symmetric to all pattern points relatively the origin of coordinates. More precisely, let mi=
Matrices.asShifted(src,ip.symmetric().coordinates()), where ip is the point #i from all points contained in the pattern. Then the every element of the returned matrix is the minimum from all corresponding elements of all mi matrices. Theelement typeof the created matrix is the same as the element type of the source one. The byte and short elements are considered to be unsigned. In a case of bit elements, the minimum is equivalent to logical AND.The basic morphology implementation
BasicMorphologystrictly complies with this definition. However, other implementations of this interface may use alternate definitions of the erosion term. For example, some percentile (10% or 20%) may be used instead of strict minimum (as in objects, returned byBasicRankMorphology.getInstance(ArrayContext, double, CustomRankPrecision)method), or elements outside the matrix may be supposed to be filled according some non-trivial rules instead of pseudo-cyclic continuation (as inContinuedMorphologyobjects), or only some region of the matrix may be processed, etc.Please see to know more about the erosion.
- Specified by:
erosionin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.- Returns:
- the result of erosion of the source matrix by the given pattern.
- See Also:
-
weakDilation
public Matrix<? extends UpdatablePArray> weakDilation(Matrix<? extends PArray> src, Pattern pattern) Description copied from interface:MorphologyReturns a new updatable matrix, containing the weak dilation of the source matrix by the specified pattern.Weak dilation of the matrix A is defined as an elementwise difference B=
dilation(A)-(closing(A)-A). It is obvious that, for any elements, A<=B<=dilation(A) (because both differencesdilation(A)-closing(A) andclosing(A)-A are non-negative).(In this method, the
closingis supposed to be performed with the last argumentMorphology.SubtractionMode.NONE.)- Specified by:
weakDilationin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.- Returns:
- the result of weak dilation of the source matrix by the given pattern.
-
weakErosion
Description copied from interface:MorphologyReturns a new updatable matrix, containing the weak erosion of the source matrix by the specified pattern.Weak erosion of the matrix A is defined as an elementwise sum B=
erosion(A)+(A-opening(A)). It is obvious that, for any elements, A>=B>=erosion(A) (because both differencesopening(A)-erosion(A) and A-opening(A) are non-negative).(In this method, the
openingis supposed to be performed with the last argumentMorphology.SubtractionMode.NONE.)- Specified by:
weakErosionin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.- Returns:
- the result of weak dilation of the source matrix by the given pattern.
-
beucherGradient
public Matrix<? extends UpdatablePArray> beucherGradient(Matrix<? extends PArray> src, Pattern pattern) Description copied from interface:MorphologyReturns a new updatable matrix, containing the Beucher gradient of the source matrix by the specified pattern, that means the elementwise difference betweendilationanderosionof the source matrix with the same pattern.More precisely, the Beucher gradient of the matrix A is defined as an elementwise positive difference B=max(0,
dilation(A)-erosion(A)).The
element typeof the created matrix is the same as the element type of the source one. The byte and short elements are considered to be unsigned.- Specified by:
beucherGradientin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.- Returns:
- the Beucher gradient of the source matrix by the given pattern.
-
dilation
public Matrix<? extends UpdatablePArray> dilation(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode) Description copied from interface:MorphologyExtended version ofMorphology.dilation(Matrix, Pattern)method: if subtractionMode argument is notMorphology.SubtractionMode.NONE, returns the difference between the dilation and the src matrix, according the specified mode.If subtractionMode==
Morphology.SubtractionMode.NONE, this method is strictly equivalent toMorphology.dilation(Matrix, Pattern).The result of this operation with subtractionMode==
Morphology.SubtractionMode.SUBTRACT_SRC_FROM_RESULTis also called the external gradient of the source matrix.- Specified by:
dilationin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.subtractionMode- whether the difference of the dilation and the source matrix should be returned.- Returns:
- the result of dilation of the source matrix by the given pattern or the difference of the dilation and the source matrix.
-
erosion
public Matrix<? extends UpdatablePArray> erosion(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode) Description copied from interface:MorphologyExtended version ofMorphology.erosion(Matrix, Pattern)method: if subtractionMode argument is notMorphology.SubtractionMode.NONE, returns the difference between the erosion and the src matrix, according the specified mode.If subtractionMode==
Morphology.SubtractionMode.NONE, this method is strictly equivalent toMorphology.erosion(Matrix, Pattern).The result of this operation with subtractionMode==
Morphology.SubtractionMode.SUBTRACT_RESULT_FROM_SRCis also called the internal gradient of the source matrix.- Specified by:
erosionin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.subtractionMode- whether the difference of the erosion and the source matrix should be returned.- Returns:
- the result of erosion of the source matrix by the given pattern or the difference of the erosion and the source matrix.
-
closing
public Matrix<? extends UpdatablePArray> closing(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode) Description copied from interface:MorphologyReturns a new updatable matrix, containing the closing of the source matrix by the specified pattern.Closing means the result of sequential performing
dilationanderosionof the source matrix with the same pattern.If subtractionMode is not
Morphology.SubtractionMode.NONE, the behaviour is little other: this method returns the difference between the closing and the src matrix, according the specified mode. For example,Morphology.SubtractionMode.SUBTRACT_SRC_FROM_RESULTargument with this method allows to remove "light" background from a gray-scale image, represented by src matrix.This method is equivalent to
dilationErosion(src, pattern, pattern, subtractionMode).Please see to know more about the closing.
- Specified by:
closingin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.subtractionMode- whether the difference of the closing and the source matrix should be returned.- Returns:
- the result of closing of the source matrix by the given pattern or the difference of the closing and the source matrix.
-
opening
public Matrix<? extends UpdatablePArray> opening(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode) Description copied from interface:MorphologyReturns a new updatable matrix, containing the opening of the source matrix by the specified pattern.Opening means the result of sequential performing
erosionanddilationof the source matrix with the same pattern.If subtractionMode is not
Morphology.SubtractionMode.NONE, the behaviour is little other: this method returns the difference between the opening and the src matrix, according the specified mode. For example,Morphology.SubtractionMode.SUBTRACT_RESULT_FROM_SRCargument with this method allows to remove "dark" background from a gray-scale image, represented by src matrix.This method is equivalent to
erosionDilation(src, pattern, pattern, subtractionMode).Please see to know more about the opening.
- Specified by:
openingin interfaceMorphology- Parameters:
src- the source matrix.pattern- the pattern.subtractionMode- whether the difference of the opening and the source matrix should be returned.- Returns:
- the result of opening of the source matrix by the given pattern or the difference of the opening and the source matrix.
-
dilationErosion
public Matrix<? extends UpdatablePArray> dilationErosion(Matrix<? extends PArray> src, Pattern ptn1, Pattern ptn2, Morphology.SubtractionMode subtractionMode) Description copied from interface:MorphologyReturns a new updatable matrix, containing the result of sequentialdilation(src, dilationPattern)anderosion(src, erosionPattern)of the source matrix by the specified patterns.If subtractionMode is not
Morphology.SubtractionMode.NONE, the behaviour is little other: this method returns the difference between the result of these two operation and the src matrix, according the specified mode.When both patterns are equal, the result is the
closingof the matrix.- Specified by:
dilationErosionin interfaceMorphology- Parameters:
src- the source matrix.ptn1- the pattern for dilation.ptn2- the pattern for erosion.subtractionMode- whether the difference with the source matrix should be returned.- Returns:
- the result of sequential dilation and erosion of the source matrix by the given patterns or the difference of such result and the source matrix.
-
erosionDilation
public Matrix<? extends UpdatablePArray> erosionDilation(Matrix<? extends PArray> src, Pattern ptn1, Pattern ptn2, Morphology.SubtractionMode subtractionMode) Description copied from interface:MorphologyReturns a new updatable matrix, containing the result of sequentialerosion(src, erosionPattern)anddilation(src, dilationPattern)of the source matrix by the specified patterns.If subtractionMode is not
Morphology.SubtractionMode.NONE, the behaviour is little other: this method returns the difference between the result of these two operation and the src matrix, according the specified mode.When both patterns are equal, the result is the
openingof the matrix.- Specified by:
erosionDilationin interfaceMorphology- Parameters:
src- the source matrix.ptn1- the pattern for erosion.ptn2- the pattern for dilation.subtractionMode- whether the difference with the source matrix should be returned.- Returns:
- the result of sequential erosion and dilation of the source matrix by the given patterns or the difference of such result and the source matrix.
-
maskedDilationErosion
public Matrix<? extends UpdatablePArray> maskedDilationErosion(Matrix<? extends PArray> src, Pattern ptn1, Pattern ptn2) Description copied from interface:MorphologyReturns the elementwise minimum between the source matrix and the result ofdilationErosion(src, dilationPattern, erosionPattern,Morphology.SubtractionMode.NONE) call.Let B is the result of this method, A is the source matrix, Q is dilationPattern, P is erosionPattern:
B=min(A,erosion(dilation(A,Q),P))
for any elements. It is obvious that (for any elements) A>=B>=erosion(A,P). But if Q is a some "boundary" or "carcass" of the erosion pattern P, then a stronger condition is true: A>=B>=opening(A,P).More precisely, there is the following theorem.
If Q is a subset of P and the Minkowski sum P⊕Q is equal to P⊕P (see
Pattern.carcass()method), then B>=opening(A,P).Below is the proof for the binary case. (For other element types, it's enough to consider the system of binary matrices A>=threshold for all possible real values threshold.)
Let some point x∈
opening(A,P). It means: there is such p1∈P, that for all p∈P we have x+p1-p∈A (the statement A). We already know, that x∈A (the case p=p1), and we also need to prove, that x∈erosion(dilation(A,Q),P).Let's suppose that it is not true. It means: there is such p2∈P, that for all q∈Q we have x+p2-q∉A (the statement B)
Let x will be the origin of coordinates: x=0. Then, let P1=-P+p1={p1-p, p∈P}. Note: the origin 0∈P1 (the case p=p1). We have P1⊂A (statement A), so, for all q∈Q we have p2-q∉P1 (because p2-q∉A, statement B). In other words, p2∉P1⊕Q (dilation of P by Q, or Minkowski sum of P and Q). On the other hand, it's obvious that p2∈P1⊕P, because 0∈P1 and, so, P⊂P⊕P1=P1⊕P.
There is a contradiction: according to the condition, there must be P1⊕P=P1⊕Q. The theorem is proved.
This fact allows to interpret this method, if dilationPattern is a "boundary" of erosionPattern (usually
UniformGridPattern.surface()or a similar point set), as a "weak" analog of opening. For binary images, it helps to remove small isolated objects, but (unlike usual opening) to preserve thin structures.- Specified by:
maskedDilationErosionin interfaceMorphology- Parameters:
src- the source matrix.ptn1- the pattern for dilation.ptn2- the pattern for erosion.- Returns:
- the elementwise minimum between the source matrix and its sequential dilation and erosion by the given patterns.
-
maskedErosionDilation
public Matrix<? extends UpdatablePArray> maskedErosionDilation(Matrix<? extends PArray> src, Pattern ptn1, Pattern ptn2) Description copied from interface:MorphologyReturns the elementwise maximum between the source matrix and the result oferosionDilation(src, erosionPattern, dilationPattern,Morphology.SubtractionMode.NONE) call.This is an inverse method for
Morphology.maskedDilationErosion(Matrix, Pattern, Pattern).- Specified by:
maskedErosionDilationin interfaceMorphology- Parameters:
src- the source matrix.ptn1- the pattern for erosion.ptn2- the pattern for dilation.- Returns:
- the elementwise maximum between the source matrix and its sequential erosion and dilation by the given patterns.
-
dilation
public void dilation(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean disableMemoryAllocation) Description copied from interface:MorphologyEquivalent toMorphology.dilation(Matrix, Pattern)method, but the result matrix will be placed in the dest argument. It allows to avoid extra memory allocation if you need to perform dilation many times from one matrix to another.Moreover, if disableMemoryAllocation argument is true, this method guarantees that no any additional memory will be allocated, even if it can optimize the algorithm speed. In this case, this method is always executed in one pass: it is equivalent to creating new lazy matrix by
Morphology.asDilation(Matrix src, Pattern pattern)method and further copying it into dest byMatrices.copy(ArrayContext, Matrix, Matrix)method. It can be useful if you are sure that the pattern is small enough (usually 2-10 points), and allocation additional work matrices can slow down the algorithm to greater extent than using the simple one-pass algorithm.If the element type of the dest matrix is not the same as the source element type (dest.
elementType()!=src.elementType()), the elements are automatically cast to the necessary type. More precisely, in this case the dest matrix, before all further calculations, is replaced withMatrices.asUpdatableFuncMatrix(true,Func.UPDATABLE_IDENTITY, src.updatableType(UpdatablePArray.class), dest)We do not recommend to pass matrices with different element types: it can slow down calculations.
- Specified by:
dilationin interfaceMorphology- Parameters:
dest- the target matrix.src- the source matrix.pattern- the pattern.disableMemoryAllocation- if false, this method may allocate additional temporary matrices for optimizing the algorithm speed; if true, no any work memory will be allocated.
-
erosion
public void erosion(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean disableMemoryAllocation) Description copied from interface:MorphologyEquivalent toMorphology.erosion(Matrix, Pattern)method, but the result matrix will be placed in the dest argument. It allows to avoid extra memory allocation if you need to perform erosion many times from one matrix to another.Moreover, if disableMemoryAllocation argument is true, this method guarantees that no any additional memory will be allocated, even if it can optimize the algorithm speed. In this case, this method is always executed in one pass: it is equivalent to creating new lazy matrix by
Morphology.asDilation(Matrix src, Pattern pattern)method and further copying it into dest byMatrices.copy(ArrayContext, Matrix, Matrix)method. It can be useful if you are sure that the pattern is small enough (usually 2-10 points), and allocation additional work matrices can slow down the algorithm to greater extent than using the simple one-pass algorithm.If the element type of the dest matrix is not the same as the source element type (dest.
elementType()!=src.elementType()), the elements are automatically cast to the necessary type. More precisely, in this case the dest matrix, before all further calculations, is replaced withMatrices.asUpdatableFuncMatrix(true,Func.UPDATABLE_IDENTITY, src.updatableType(UpdatablePArray.class), dest)We do not recommend to pass matrices with different element types: it can slow down calculations.
- Specified by:
erosionin interfaceMorphology- Parameters:
dest- the target matrix.src- the source matrix.pattern- the pattern.disableMemoryAllocation- if false, this method may allocate additional temporary matrices for optimizing the algorithm speed; if true, no any work memory will be allocated.
-
dilation
public void dilation(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern) Description copied from interface:MorphologyEquivalent todilation(dest, src, pattern, false).- Specified by:
dilationin interfaceMorphology- Parameters:
dest- the target matrix.src- the source matrix.pattern- the pattern.
-
erosion
public void erosion(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern) Description copied from interface:MorphologyEquivalent toerosion(dest, src, pattern, false).- Specified by:
erosionin interfaceMorphology- Parameters:
dest- the target matrix.src- the source matrix.pattern- the pattern.
-