public abstract class AbstractMorphology extends AbstractArrayProcessorWithContextSwitching implements Morphology
A skeletal implementation of the Morphology
interface to minimize
the effort required to implement this interface.
All methods of the interface are completely implemented here via 3 following methods:
context(ArrayContext newContext)
,asDilationOrErosion(Matrix src, Pattern pattern, boolean isDilation)
,dilationOrErosion(Matrix dest, Matrix src, Pattern pattern, boolean isDilation, boolean disableMemoryAllocation)
.
Usually the subclasses need to override only these 3 methods and isPseudoCyclic()
.
AlgART Laboratory 2007–2014
Morphology.SubtractionMode
Modifier  Constructor and Description 

protected 
AbstractMorphology(ArrayContext context)
Creates an instance of this class with the given context.

Modifier and Type  Method and Description 

Matrix<? extends PArray> 
asDilation(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.

protected abstract Matrix<? extends PArray> 
asDilationOrErosion(Matrix<? extends PArray> src,
Pattern pattern,
boolean isDilation)
This method must be equivalent to
asDilation(Matrix src, Pattern pattern)
if isDilation argument is true or to
asErosion(Matrix src, Pattern pattern)
if isDilation argument is false. 
Matrix<? extends PArray> 
asErosion(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 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.

Morphology 
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.

Matrix<? extends UpdatablePArray> 
dilation(Matrix<? extends PArray> src,
Pattern pattern)
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 of
Morphology.dilation(Matrix, Pattern) method: if subtractionMode argument
is not Morphology.SubtractionMode.NONE ,
returns the difference between the dilation and the src matrix,
according the specified mode. 
void 
dilation(Matrix<? extends UpdatablePArray> dest,
Matrix<? extends PArray> src,
Pattern pattern)
Equivalent to
dilation(dest, src, pattern, false) . 
void 
dilation(Matrix<? extends UpdatablePArray> dest,
Matrix<? extends PArray> src,
Pattern pattern,
boolean disableMemoryAllocation)
Equivalent to
Morphology.dilation(Matrix, Pattern) method, but the result matrix
will be placed in the dest argument. 
Matrix<? extends UpdatablePArray> 
dilationErosion(Matrix<? extends PArray> src,
Pattern dilationPattern,
Pattern erosionPattern,
Morphology.SubtractionMode subtractionMode)
Returns a new updatable matrix, containing the result of sequential
dilation(src, dilationPattern) and
erosion(src, erosionPattern)
of the source matrix by the specified patterns. 
protected Matrix<? extends UpdatablePArray> 
dilationOrErosion(Matrix<? extends UpdatablePArray> dest,
Matrix<? extends PArray> src,
Pattern pattern,
boolean isDilation,
boolean disableMemoryAllocation)
This method must be equivalent to
dilation(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
if isDilation argument is true or to
erosion(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
if isDilation argument is false. 
protected boolean 
dimensionsAllowed(Matrix<? extends PArray> matrix,
Pattern pattern) 
Matrix<? extends UpdatablePArray> 
erosion(Matrix<? extends PArray> src,
Pattern pattern)
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 of
Morphology.erosion(Matrix, Pattern) method: if subtractionMode argument
is not Morphology.SubtractionMode.NONE ,
returns the difference between the erosion and the src matrix,
according the specified mode. 
void 
erosion(Matrix<? extends UpdatablePArray> dest,
Matrix<? extends PArray> src,
Pattern pattern)
Equivalent to
erosion(dest, src, pattern, false) . 
void 
erosion(Matrix<? extends UpdatablePArray> dest,
Matrix<? extends PArray> src,
Pattern pattern,
boolean disableMemoryAllocation)
Equivalent to
Morphology.erosion(Matrix, Pattern) method, but the result matrix
will be placed in the dest argument. 
Matrix<? extends UpdatablePArray> 
erosionDilation(Matrix<? extends PArray> src,
Pattern erosionPattern,
Pattern dilationPattern,
Morphology.SubtractionMode subtractionMode)
Returns a new updatable matrix, containing the result of sequential
erosion(src, erosionPattern) and
dilation(src, dilationPattern)
of the source matrix by the specified patterns. 
abstract boolean 
isPseudoCyclic()
Returns true, if this class works in the default
pseudocyclic continuation mode . 
Matrix<? extends UpdatablePArray> 
maskedDilationErosion(Matrix<? extends PArray> src,
Pattern dilationPattern,
Pattern erosionPattern)
Returns the elementwise minimum between the source matrix and the result of
dilationErosion (src, dilationPattern, erosionPattern, Morphology.SubtractionMode.NONE ) call. 
Matrix<? extends UpdatablePArray> 
maskedErosionDilation(Matrix<? extends PArray> src,
Pattern erosionPattern,
Pattern dilationPattern)
Returns the elementwise maximum between the source matrix and the result of
erosionDilation (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.

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.

context, contextPart, memoryModel
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
context
protected AbstractMorphology(ArrayContext context)
context
 the context used by this instance for all operations.public Morphology context(ArrayContext newContext)
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.
context
in interface ArrayProcessorWithContextSwitching
context
in interface Morphology
context
in class AbstractArrayProcessorWithContextSwitching
newContext
 another context, used by the returned instance; may be null.public abstract boolean isPseudoCyclic()
Morphology
pseudocyclic 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 basic Morphology.dilation(Matrix, Pattern)
and Morphology.erosion(Matrix, Pattern)
methods as the default definition of dilation and erosion.
This method returns true in BasicMorphology
and BasicRankMorphology
implementation.
However, it usually returns false in ContinuedMorphology
and
ContinuedRankMorphology
classes — excepting the only degenerated case when the used
continuation mode
is
PSEUDO_CYCLIC
.
isPseudoCyclic
in interface Morphology
public Matrix<? extends PArray> asDilation(Matrix<? extends PArray> src, Pattern pattern)
Morphology
Morphology.dilation(Matrix, Pattern)
method about the "dilation" term.
The element type
of 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.
asDilation
in interface Morphology
src
 the source matrix.pattern
 the pattern.public Matrix<? extends PArray> asErosion(Matrix<? extends PArray> src, Pattern pattern)
Morphology
Morphology.erosion(Matrix, Pattern)
method about the "erosion" term.
The element type
of 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.
asErosion
in interface Morphology
src
 the source matrix.pattern
 the pattern.public Matrix<? extends UpdatablePArray> dilation(Matrix<? extends PArray> src, Pattern pattern)
Morphology
Usually dilation means the elementwise maximum from the set of matrices,
obtained by pseudocyclic shifting the source matrix by the vectors,
equal to all pattern points.
More precisely, let m_{i}=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 m_{i} matrices. The element type
of 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 BasicMorphology
strictly 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 by BasicRankMorphology.getInstance(ArrayContext, double, CustomRankPrecision)
method),
or elements outside the matrix may be supposed to be filled according some nontrivial rules
instead of pseudocyclic continuation
(as in ContinuedMorphology
objects),
or only some region of the matrix may be processed, etc.
Please see
dilation
in interface Morphology
src
 the source matrix.pattern
 the pattern.Morphology.asDilation(Matrix, Pattern)
,
Morphology.dilation(Matrix, Matrix, Pattern, boolean)
,
Morphology.dilation(Matrix, Pattern, Morphology.SubtractionMode)
public Matrix<? extends UpdatablePArray> erosion(Matrix<? extends PArray> src, Pattern pattern)
Morphology
Usually erosion means the elementwise minimum from the set of matrices,
obtained by pseudocyclic shifting the source matrix by the vectors,
symmetric to all pattern points relatively the origin of coordinates.
More precisely, let m_{i}=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 m_{i} matrices. The element type
of 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 BasicMorphology
strictly 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 by BasicRankMorphology.getInstance(ArrayContext, double, CustomRankPrecision)
method),
or elements outside the matrix may be supposed to be filled according some nontrivial rules
instead of pseudocyclic continuation
(as in ContinuedMorphology
objects),
or only some region of the matrix may be processed, etc.
Please see
erosion
in interface Morphology
src
 the source matrix.pattern
 the pattern.Morphology.asDilation(Matrix, Pattern)
,
Morphology.erosion(Matrix, Matrix, Pattern, boolean)
,
Morphology.erosion(Matrix, Pattern, Morphology.SubtractionMode)
public Matrix<? extends UpdatablePArray> dilation(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode)
Morphology
Morphology.dilation(Matrix, Pattern)
method: if subtractionMode argument
is not Morphology.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
to Morphology.dilation(Matrix, Pattern)
.
The result of this operation with subtractionMode==Morphology.SubtractionMode.SUBTRACT_SRC_FROM_RESULT
is also called the external gradient of the source matrix.
dilation
in interface Morphology
src
 the source matrix.pattern
 the pattern.subtractionMode
 whether the difference of the dilation and the source matrix should be returned.public Matrix<? extends UpdatablePArray> erosion(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode)
Morphology
Morphology.erosion(Matrix, Pattern)
method: if subtractionMode argument
is not Morphology.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
to Morphology.erosion(Matrix, Pattern)
.
The result of this operation with subtractionMode==Morphology.SubtractionMode.SUBTRACT_RESULT_FROM_SRC
is also called the internal gradient of the source matrix.
erosion
in interface Morphology
src
 the source matrix.pattern
 the pattern.subtractionMode
 whether the difference of the erosion and the source matrix should be returned.public void dilation(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean disableMemoryAllocation)
Morphology
Morphology.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 by Matrices.copy(ArrayContext, Matrix, Matrix)
method.
It can be useful if you are sure that the pattern is small enough (usually 210 points),
and allocation additional work matrices can slow down the algorithm to greater extent
than using the simple onepass 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 with
Matrices.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.
dilation
in interface Morphology
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.public void erosion(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean disableMemoryAllocation)
Morphology
Morphology.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 by Matrices.copy(ArrayContext, Matrix, Matrix)
method.
It can be useful if you are sure that the pattern is small enough (usually 210 points),
and allocation additional work matrices can slow down the algorithm to greater extent
than using the simple onepass 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 with
Matrices.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.
erosion
in interface Morphology
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.public void dilation(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern)
Morphology
dilation(dest, src, pattern, false)
.dilation
in interface Morphology
dest
 the target matrix.src
 the source matrix.pattern
 the pattern.public void erosion(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern)
Morphology
erosion(dest, src, pattern, false)
.erosion
in interface Morphology
dest
 the target matrix.src
 the source matrix.pattern
 the pattern.public Matrix<? extends UpdatablePArray> dilationErosion(Matrix<? extends PArray> src, Pattern dilationPattern, Pattern erosionPattern, Morphology.SubtractionMode subtractionMode)
Morphology
dilation(src, dilationPattern)
and
erosion(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 closing
of the matrix.
dilationErosion
in interface Morphology
src
 the source matrix.dilationPattern
 the pattern for dilation.erosionPattern
 the pattern for erosion.subtractionMode
 whether the difference with the source matrix should be returned.public Matrix<? extends UpdatablePArray> erosionDilation(Matrix<? extends PArray> src, Pattern erosionPattern, Pattern dilationPattern, Morphology.SubtractionMode subtractionMode)
Morphology
erosion(src, erosionPattern)
and
dilation(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 opening
of the matrix.
erosionDilation
in interface Morphology
src
 the source matrix.erosionPattern
 the pattern for erosion.dilationPattern
 the pattern for dilation.subtractionMode
 whether the difference with the source matrix should be returned.public Matrix<? extends UpdatablePArray> closing(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode)
Morphology
Closing means the result of sequential performing
dilation
and erosion
of 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_RESULT
argument
with this method allows to remove "light" background from a grayscale image,
represented by src matrix.
This method is equivalent to dilationErosion(src, pattern, pattern, subtractionMode)
.
Please see
closing
in interface Morphology
src
 the source matrix.pattern
 the pattern.subtractionMode
 whether the difference of the closing and the source matrix should be returned.public Matrix<? extends UpdatablePArray> opening(Matrix<? extends PArray> src, Pattern pattern, Morphology.SubtractionMode subtractionMode)
Morphology
Opening means the result of sequential performing
erosion
and dilation
of 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_SRC
argument
with this method allows to remove "dark" background from a grayscale image,
represented by src matrix.
This method is equivalent to erosionDilation(src, pattern, pattern, subtractionMode)
.
Please see
opening
in interface Morphology
src
 the source matrix.pattern
 the pattern.subtractionMode
 whether the difference of the opening and the source matrix should be returned.public Matrix<? extends UpdatablePArray> weakDilation(Matrix<? extends PArray> src, Pattern pattern)
Morphology
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 differences
dilation
(A)closing
(A)
and closing
(A)A are nonnegative).
(In this method, the closing
is supposed
to be performed with the last argument Morphology.SubtractionMode.NONE
.)
weakDilation
in interface Morphology
src
 the source matrix.pattern
 the pattern.public Matrix<? extends UpdatablePArray> weakErosion(Matrix<? extends PArray> src, Pattern pattern)
Morphology
Weak erosion of the matrix A is defined as an elementwise sum
B=erosion
(A)+(Aopening
(A)).
It is obvious that, for any elements, A>=B>=erosion
(A)
(because both differences
opening
(A)erosion
(A)
and Aopening
(A) are nonnegative).
(In this method, the opening
is supposed
to be performed with the last argument Morphology.SubtractionMode.NONE
.)
weakErosion
in interface Morphology
src
 the source matrix.pattern
 the pattern.public Matrix<? extends UpdatablePArray> maskedDilationErosion(Matrix<? extends PArray> src, Pattern dilationPattern, Pattern erosionPattern)
Morphology
dilationErosion
(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 p_{1}∈P, that for all p∈P we have x+p_{1}p∈A (the statement A). We already know, that x∈A (the case p=p_{1}), 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 p_{2}∈P, that for all q∈Q we have x+p_{2}q∉A (the statement B)
Let x will be the origin of coordinates: x=0. Then, let P_{1}=P+p_{1}={p_{1}p, p∈P}. Note: the origin 0∈P_{1} (the case p=p_{1}). We have P_{1}⊂A (statement A), so, for all q∈Q we have p_{2}q∉P_{1} (because p_{2}q∉A, statement B). In other words, p_{2}∉P_{1}⊕Q (dilation of P by Q, or Minkowski sum of P and Q). On the other hand, it's obvious that p_{2}∈P_{1}⊕P, because 0∈P_{1} and, so, P⊂P⊕P_{1}=P_{1}⊕P.
There is a contradiction: according to the condition, there must be P_{1}⊕P=P_{1}⊕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.
maskedDilationErosion
in interface Morphology
src
 the source matrix.dilationPattern
 the pattern for dilation.erosionPattern
 the pattern for erosion.public Matrix<? extends UpdatablePArray> maskedErosionDilation(Matrix<? extends PArray> src, Pattern erosionPattern, Pattern dilationPattern)
Morphology
erosionDilation
(src, erosionPattern, dilationPattern, Morphology.SubtractionMode.NONE
) call.
This is an inverse method for Morphology.maskedDilationErosion(Matrix, Pattern, Pattern)
.
maskedErosionDilation
in interface Morphology
src
 the source matrix.erosionPattern
 the pattern for erosion.dilationPattern
 the pattern for dilation.public Matrix<? extends UpdatablePArray> beucherGradient(Matrix<? extends PArray> src, Pattern pattern)
Morphology
dilation
and erosion
of 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 type
of the created matrix is the same as the element type of the source one.
The byte and short elements are considered to be unsigned.
beucherGradient
in interface Morphology
src
 the source matrix.pattern
 the pattern.protected abstract Matrix<? extends PArray> asDilationOrErosion(Matrix<? extends PArray> src, Pattern pattern, boolean isDilation)
asDilation(Matrix src, Pattern pattern)
if isDilation argument is true or to
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.
src
 the source matrix.pattern
 the pattern.isDilation
 what should return this method: dilation or erosion.java.lang.NullPointerException
 if one of the arguments is null.java.lang.IllegalArgumentException
 if the number of the pattern dimensions
pattern.dimCount()
is not equal
to src.dimCount()
.protected Matrix<? extends UpdatablePArray> dilationOrErosion(Matrix<? extends UpdatablePArray> dest, Matrix<? extends PArray> src, Pattern pattern, boolean isDilation, boolean disableMemoryAllocation)
dilation(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
if isDilation argument is true or to
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 nonnull dest argument) is returned
as the result of this method.
The implementations of
dilation(Matrix dest, Pattern pattern)
,
erosion(Matrix dest, Pattern pattern)
,
dilation(Matrix dest, Matrix src, Pattern pattern, boolean disableMemoryAllocation)
,
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
of asDilationOrErosion(Matrix, Pattern, boolean)
asDilationOrErosion} method to dest matrix:
Matrices.copy
(context, castDest,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.
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.java.lang.NullPointerException
 if src or pattern argument is null.SizeMismatchException
 if dest!=null and the passed matrices have different dimensions.java.lang.IllegalArgumentException
 if the number of the pattern dimensions
pattern.dimCount()
is not equal
to src.dimCount()
.