Class IterativeErosion
- All Implemented Interfaces:
- ArrayProcessor,- IterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
Iterative erosion of the matrix.
This class is an implementation of IterativeArrayProcessor interface,
 performing erosion
 of some source matrix (Matrix(UpdatablePArray))
 by sequential Minkowski multiples
 of some pattern: k⊗P, k=1,2,....
 Every erosion is added to some accumulator matrix, named result and returned by
 result() method.
 If the source matrix is binary, then each element of the result matrix will be an integer,
 which is non-zero only for non-zero elements of the source one and which shows the distance from this point
 to the nearest zero element, "measured" in the "sizes" of the pattern.
More precisely, in this implementation:
- the current contextin the returned instance is equal to the current context of theMorphologyobject, passed togetInstancemethod.
- performIteration(ArrayContext)method calculates
 - erosion(source_matrix,- Patterns.newMinkowskiSum(ptn0,ptn1,...,ptnk)) (k+1 summands),
 where k is the index of the current iteration (0, 1, 2, ...) and ptni=patterns[i%patterns.length], patterns is the argument of- getInstancemethod. If only one pattern P was passed to- getInstancemethod, it means the erosion by- Minkowski multiple pattern(k+1)⊗P. This erosion is arithmetically added, with truncation of overflows, to the result matrix, by- Matrices.applyFunc(ArrayContext, Func, Matrix, Matrix, Matrix)with- Func.X_PLUS_Yfunction. (Really, this method does not actually perform these operation, but performs equivalent calculations with some optimization.)
- done()method returns true if the last erosion was the same as the previous erosion: for bit matrices, it usually means that both erosions are zero-filled (all "objects" were removed).
- result()method always returns the reference to the accumulator matrix result.
The result matrix is created and zero-filled by getInstance method,
 and before the first iteration the source matrix is added to it (that means just copying).
Please note: there is no guarantees that result matrix, returned by result() method,
 is updated after each iteration. This class contains some optimization, that can lead to updating result
 only after some iteration, for example, after iteration #8, #16, etc.
 There is only the guarantee that result() returns valid matrix
 when done() returns true.
This class may be applied to a matrix with any number of dimensions.
- Author:
- Daniel Alievsky
- 
Field SummaryFields inherited from class net.algart.arrays.AbstractIterativeArrayProcessorcontext, memoryModel
- 
Method SummaryModifier and TypeMethodDescriptionbooleandone()Returns true if and only if the algorithm was successfully finished and there is no sense to perform further iterations.longEstimates the number of iterations, that should be performed from this moment to finish the algorithm.static longestimatedNumberOfIterations(Matrix<? extends PArray> matrix, Pattern pattern) voidfreeResources(ArrayContext context) If there are some resources, allocated by this object, which are not controlled by Java garbage collectors — files, streams, sockets, locks, etc. — this method tries to release them (for example, to close any files).static IterativeErosiongetInstance(Morphology morphology, Class<? extends UpdatablePArray> requiredType, Matrix<? extends PArray> matrix, Pattern... patterns) Creates new instance of this class.voidperformIteration(ArrayContext context) Performs the next iteration of the iterative algorithm.Matrix<? extends UpdatablePArray>result()Returns the result of the previous iteration.toString()Returns a brief string description of this object.Methods inherited from class net.algart.arrays.AbstractIterativeArrayProcessorchain, context, limitIterations, part, processMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.algart.arrays.ArrayProcessorcontextMethods inherited from interface net.algart.arrays.IterativeArrayProcessorchain, limitIterations, process
- 
Method Details- 
getInstancepublic static IterativeErosion getInstance(Morphology morphology, Class<? extends UpdatablePArray> requiredType, Matrix<? extends PArray> matrix, Pattern... patterns) Creates new instance of this class.- Parameters:
- morphology- the- Morphologyobject that will be used for performing erosions.
- requiredType- the type of built-in AlgART array for- result()matrix. Should be enough for storing elementwise sums of hundreds of eroded matrices; in other case, overflows will lead to trunctation of the sums.
- matrix- the source matrix, that will be eroded by Minkowski sums of the passed patterns (or just by Minkowski muptiples k⊗P, if patterns argument contains only 1 pattern).
- patterns- one or several patterns for performing erosion. For little pattern sizes, you may specify several patterns with near form to increase the precision of the resulting matrix.
- Returns:
- new instance of this class.
- Throws:
- NullPointerException- if one of arguments or one of passed patterns is null.
- IllegalArgumentException- if patterns.length==0 (no patterns passed).
 
- 
performIterationDescription copied from interface:IterativeArrayProcessorPerforms the next iteration of the iterative algorithm. If the algorithm isIterativeArrayProcessor.done(), the results are unspecified: please never call this method ifIterativeArrayProcessor.done()returns true.You usually don't need to call this method: please call IterativeArrayProcessor.process()instead. If you need to perform only one or n iterations, you may uselimitIterations(n)call.Warning: this method should ignore the current execution contextof this object. Instead, this method should use the context of execution specified by context argument. This method is called byIterativeArrayProcessor.process()method with the argument, describinga subtraskof the full algorithm. The context argument may be null: this method should work properly in this case (ignore the context).This method must be implemented while creating a new iterative array-processing algorithm. - Specified by:
- performIterationin interface- IterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Specified by:
- performIterationin class- AbstractIterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Parameters:
- context- the context used by this instance for all operations; may be null.
 
- 
donepublic boolean done()Description copied from interface:IterativeArrayProcessorReturns true if and only if the algorithm was successfully finished and there is no sense to perform further iterations.This method usually does not perform actual calculations and works very quickly (just returns and internal flag). However, this condition is not strict. You usually don't need to call this method: it is automatically called by IterativeArrayProcessor.process()method.This method must be implemented while creating a new iterative array-processing algorithm. - Specified by:
- donein interface- IterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Specified by:
- donein class- AbstractIterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Returns:
- true if and only if the algorithm was successfully finished.
 
- 
estimatedNumberOfIterationspublic long estimatedNumberOfIterations()Description copied from interface:IterativeArrayProcessorEstimates the number of iterations, that should be performed from this moment to finish the algorithm. Returns 0 if it is impossible or too difficult to estimate this number: it means that the remaining number of iteration is unknown.This method may require some time for its execution. You usually don't need to call this method: it is automatically called from time to time by IterativeArrayProcessor.process()method. It is used for creating subcontexts, describing apartof the full task.This method must be implemented while creating a new iterative array-processing algorithm. - Specified by:
- estimatedNumberOfIterationsin interface- IterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Specified by:
- estimatedNumberOfIterationsin class- AbstractIterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Returns:
- the estimated number of iterations, that should be performed from this moment to finish the algorithm.
 
- 
resultDescription copied from interface:IterativeArrayProcessorReturns the result of the previous iteration. Usually it isUpdatableArrayorMatrix<? extendsUpdatableArray>. This method returns valid result even if no iterations were performed yet. IfIterativeArrayProcessor.done()method returns true, the result of this method is the final result of iterative processing performed by this instance.This method may return null. In this case, the concrete implementation of this interface should provide additional methods for returning calculation results. This method does not perform actual calculations and works very quickly. This method must be implemented while creating a new iterative array-processing algorithm. - Specified by:
- resultin interface- IterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Specified by:
- resultin class- AbstractIterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Returns:
- the result of the previous iteration (may be null).
 
- 
freeResourcesDescription copied from interface:IterativeArrayProcessorIf there are some resources, allocated by this object, which are not controlled by Java garbage collectors — files, streams, sockets, locks, etc. — this method tries to release them (for example, to close any files). The object stays alive: if the resources will be necessary for following operations, they will be automatically re-acquired.Usually, this method just calls Array.freeResources(context)andMatrix.freeResources(context)for all temporary arrays and matrices, allocated by this object for storing work data.If IterativeArrayProcessor.result()method returns AlgART array or matrix (typical situation), this method callsArray.freeResources(context)/Matrix.freeResources(context)methods for this array / matrix.This method may be used in situations when the instance of this object has long time life and will be reused in future. This method must be implemented while creating a new iterative array-processing algorithm. - Specified by:
- freeResourcesin interface- IterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Specified by:
- freeResourcesin class- AbstractIterativeArrayProcessor<Matrix<? extends UpdatablePArray>>
- Parameters:
- context- the context of execution; may be null, then it will be ignored.
 
- 
toStringReturns a brief string description of this object.
- 
estimatedNumberOfIterations
 
-