Skip to content

Commit a8cabdc

Browse files
committed
Beautify AbstractHaralickFeature
1 parent f88cadc commit a8cabdc

3 files changed

Lines changed: 26 additions & 6 deletions

File tree

scijava-ops-image/src/main/java/org/scijava/ops/image/features/haralick/AbstractHaralickFeature.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public abstract class AbstractHaralickFeature<T extends RealType<T>>
4848
implements Functions.Arity4<RandomAccessibleInterval<T>, Integer, Integer, MatrixOrientation, DoubleType> {
4949

5050
@OpDependency(name = "image.cooccurrenceMatrix")
51-
private Functions.Arity4<RandomAccessibleInterval<T>, Integer, Integer, MatrixOrientation, double[][]> coocFunc;
51+
private Functions.Arity4<RandomAccessibleInterval<T>, MatrixOrientation, Integer, Integer, double[][]> coocFunc;
5252

5353
/**
5454
* given the specified parameters. No caching!
@@ -59,7 +59,7 @@ protected double[][] getCooccurrenceMatrix(final RandomAccessibleInterval<T> inp
5959
final Integer distance, final MatrixOrientation matrixOrientation) {
6060
if (matrixOrientation.numDims() != input.numDimensions())
6161
throw new IllegalArgumentException("MatrixOrientation must be of the same dimensions as the input!");
62-
return coocFunc.apply(input, numGreyLevels, distance, matrixOrientation);
62+
return coocFunc.apply(input, matrixOrientation, numGreyLevels, distance);
6363
}
6464

6565
}

scijava-ops-image/src/main/java/org/scijava/ops/image/image/cooccurrenceMatrix/CooccurrenceMatrix.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.function.Function;
3232

3333
import org.scijava.function.Functions;
34+
import org.scijava.ops.spi.Nullable;
3435
import org.scijava.ops.spi.OpDependency;
3536

3637
import net.imglib2.RandomAccessibleInterval;
@@ -47,7 +48,7 @@
4748
*@implNote op names='image.cooccurrenceMatrix'
4849
*/
4950
public 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)) {

scijava-ops-image/src/test/java/org/scijava/ops/image/OpRegressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class OpRegressionTest {
4242

4343
@Test
4444
public void opDiscoveryRegressionIT() {
45-
long expected = 1880;
45+
long expected = 1882;
4646
long actual = ops.infos().size();
4747
assertEquals(expected, actual);
4848
}

0 commit comments

Comments
 (0)