3131import java .util .function .Function ;
3232
3333import org .scijava .function .Functions ;
34+ import org .scijava .ops .spi .Nullable ;
3435import org .scijava .ops .spi .OpDependency ;
3536
3637import net .imglib2 .RandomAccessibleInterval ;
4748 *@implNote op names='image.cooccurrenceMatrix'
4849 */
4950public class CooccurrenceMatrix <T extends RealType <T >>
50- implements Functions .Arity4 <RandomAccessibleInterval <T >, Integer , Integer , MatrixOrientation , double [][]> {
51+ implements Functions .Arity4 <RandomAccessibleInterval <T >, MatrixOrientation , Integer , Integer , double [][]> {
5152
5253 @ OpDependency (name = "stats.minMax" )
5354 private Function <RandomAccessibleInterval <T >, Pair <T , T >> minmax ;
@@ -63,8 +64,27 @@ public class CooccurrenceMatrix<T extends RealType<T>>
6364 * @return the co-occurence matrix
6465 */
6566 @ Override
66- public double [][] apply (RandomAccessibleInterval <T > input , Integer nrGreyLevels , Integer distance ,
67- MatrixOrientation orientation ) {
67+ public double [][] apply ( //
68+ RandomAccessibleInterval <T > input , //
69+ MatrixOrientation orientation , //
70+ @ Nullable Integer nrGreyLevels , //
71+ @ Nullable Integer distance //
72+ ) {
73+ // nrGreyLevels validation
74+ if (nrGreyLevels == null ) {
75+ nrGreyLevels = 32 ;
76+ }
77+ if (nrGreyLevels < 0 || nrGreyLevels > 128 ) {
78+ throw new IllegalArgumentException ("nrGreyLevels must be between 0 and 128 (inclusive) but was " + nrGreyLevels );
79+ }
80+ // distance validation
81+ if (distance == null ) {
82+ distance = 1 ;
83+ }
84+ if (distance < 0 || distance > 128 ) {
85+ throw new IllegalArgumentException ("distance must be between 0 and 128 (inclusive) but was " + distance );
86+ }
87+
6888 if (input .numDimensions () == 3 && orientation .isCompatible (3 )) {
6989 return CooccurrenceMatrix3D .apply (input , nrGreyLevels , distance , minmax , orientation );
7090 } else if (input .numDimensions () == 2 && orientation .isCompatible (2 )) {
0 commit comments