Skip to content

Commit 76b27fd

Browse files
gselzerwiedenm
authored andcommitted
WIP: Port features namespace
TODO: Port ops that this namespace depends on (the main one is filter.mean?)
1 parent 39e5b7b commit 76b27fd

37 files changed

Lines changed: 3584 additions & 0 deletions
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package net.imagej.ops.features.haralick;
31+
32+
import net.imagej.ops.image.cooccurrenceMatrix.CooccurrenceMatrix2D;
33+
import net.imagej.ops.image.cooccurrenceMatrix.MatrixOrientation;
34+
import net.imglib2.IterableInterval;
35+
import net.imglib2.type.numeric.RealType;
36+
import net.imglib2.type.numeric.real.DoubleType;
37+
38+
import org.scijava.ops.OpDependency;
39+
import org.scijava.ops.core.function.Function4;
40+
41+
/**
42+
* Abstract class for HaralickFeatures.
43+
*
44+
* @author Christian Dietz (University of Konstanz)
45+
* @param <T>
46+
*/
47+
public abstract class AbstractHaralickFeature<T extends RealType<T>>
48+
implements Function4<IterableInterval<T>, Integer, Integer, MatrixOrientation, DoubleType> {
49+
50+
@OpDependency(name = "image.cooccurrenceMatrix")
51+
private Function4<IterableInterval<T>, Integer, Integer, MatrixOrientation, double[][]> coocFunc;
52+
53+
/**
54+
* Creates {@link CooccurrenceMatrix2D} from {@link IterableInterval} on demand,
55+
* given the specified parameters. No caching!
56+
*
57+
* @return the {@link CooccurrenceMatrix2D}
58+
*/
59+
protected double[][] getCooccurrenceMatrix(final IterableInterval<T> input, final Integer numGreyLevels,
60+
final Integer distance, final MatrixOrientation matrixOrientation) {
61+
if (matrixOrientation.numDims() != input.numDimensions())
62+
throw new IllegalArgumentException("MatrixOrientation must be of the same dimensions as the input!");
63+
return coocFunc.apply(input, numGreyLevels, distance, matrixOrientation);
64+
}
65+
66+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.features.haralick;
30+
31+
import net.imagej.ops.image.cooccurrenceMatrix.MatrixOrientation;
32+
import net.imglib2.IterableInterval;
33+
import net.imglib2.type.numeric.RealType;
34+
import net.imglib2.type.numeric.real.DoubleType;
35+
36+
import org.scijava.ops.core.Op;
37+
import org.scijava.param.Parameter;
38+
import org.scijava.plugin.Plugin;
39+
import org.scijava.struct.ItemIO;
40+
41+
/**
42+
*
43+
* Implementation of Angular Second Moment Haralick Feature
44+
*
45+
* @author Andreas Graumann (University of Konstanz)
46+
* @author Christian Dietz (University of Konstanz)
47+
*
48+
*/
49+
@Plugin(type = Op.class, name = "features.haralick.asm")
50+
@Parameter(key = "input")
51+
@Parameter(key = "numGreyLevels")
52+
@Parameter(key = "distance")
53+
@Parameter(key = "matrixOrientation")
54+
@Parameter(key = "output", type = ItemIO.OUTPUT)
55+
public class DefaultASM<T extends RealType<T>> extends AbstractHaralickFeature<T> {
56+
57+
@Override
58+
public DoubleType apply(final IterableInterval<T> input, final Integer numGreyLevels, final Integer distance,
59+
final MatrixOrientation orientation) {
60+
final double[][] matrix = getCooccurrenceMatrix(input, numGreyLevels, distance, orientation);
61+
final int nrGrayLevels = matrix.length;
62+
63+
double res = 0;
64+
for (int i = 0; i < nrGrayLevels; i++) {
65+
for (int j = 0; j < nrGrayLevels; j++) {
66+
res += matrix[i][j] * matrix[i][j];
67+
}
68+
}
69+
70+
DoubleType output = new DoubleType();
71+
output.setReal(res);
72+
return output;
73+
}
74+
75+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.features.haralick;
30+
31+
import java.util.function.Function;
32+
33+
import net.imagej.ops.image.cooccurrenceMatrix.MatrixOrientation;
34+
import net.imglib2.IterableInterval;
35+
import net.imglib2.type.numeric.RealType;
36+
import net.imglib2.type.numeric.real.DoubleType;
37+
38+
import org.scijava.ops.OpDependency;
39+
import org.scijava.ops.core.Op;
40+
import org.scijava.param.Parameter;
41+
import org.scijava.plugin.Plugin;
42+
import org.scijava.struct.ItemIO;
43+
44+
/**
45+
*
46+
* Implementation of Cluster Promenence Haralick Feature
47+
*
48+
* @author Andreas Graumann (University of Konstanz)
49+
* @author Christian Dietz (University of Konstanz)
50+
*
51+
*/
52+
@Plugin(type = Op.class, name = "features.haralick.clusterPromenence")
53+
@Parameter(key = "input")
54+
@Parameter(key = "numGreyLevels")
55+
@Parameter(key = "distance")
56+
@Parameter(key = "matrixOrientation")
57+
@Parameter(key = "output", type = ItemIO.OUTPUT)
58+
public class DefaultClusterPromenence<T extends RealType<T>> extends AbstractHaralickFeature<T> {
59+
60+
@OpDependency(name = "features.haralick.coocMeanX")
61+
private Function<double[][], DoubleType> coocMeanXFunc;
62+
@OpDependency(name = "features.haralick.coocMeanY")
63+
private Function<double[][], DoubleType> coocMeanYFunc;
64+
65+
@Override
66+
public DoubleType apply(final IterableInterval<T> input, final Integer numGreyLevels, final Integer distance,
67+
final MatrixOrientation orientation) {
68+
final double[][] matrix = getCooccurrenceMatrix(input, numGreyLevels, distance, orientation);
69+
70+
final int nrGrayLevels = matrix.length;
71+
72+
final double mux = coocMeanXFunc.apply(matrix).getRealDouble();
73+
final double muy = coocMeanYFunc.apply(matrix).getRealDouble();
74+
75+
double res = 0;
76+
for (int i = 0; i < nrGrayLevels; i++) {
77+
for (int j = 0; j < nrGrayLevels; j++) {
78+
res += Math.pow(i + j - mux - muy, 4) * matrix[i][j];
79+
}
80+
}
81+
DoubleType output = new DoubleType();
82+
output.setReal(res);
83+
return output;
84+
}
85+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.features.haralick;
30+
31+
import java.util.function.Function;
32+
33+
import net.imagej.ops.image.cooccurrenceMatrix.MatrixOrientation;
34+
import net.imglib2.IterableInterval;
35+
import net.imglib2.type.numeric.RealType;
36+
import net.imglib2.type.numeric.real.DoubleType;
37+
38+
import org.scijava.ops.OpDependency;
39+
import org.scijava.ops.core.Op;
40+
import org.scijava.param.Parameter;
41+
import org.scijava.plugin.Plugin;
42+
import org.scijava.struct.ItemIO;
43+
44+
/**
45+
* Implementation of Cluster Shade Haralick Feature
46+
*
47+
* @author Andreas Graumann (University of Konstanz)
48+
* @author Christian Dietz (University of Konstanz)
49+
*
50+
*/
51+
@Plugin(type = Op.class, name = "features.haralick.clusterShade")
52+
@Parameter(key = "input")
53+
@Parameter(key = "numGreyLevels")
54+
@Parameter(key = "distance")
55+
@Parameter(key = "matrixOrientation")
56+
@Parameter(key = "output", type = ItemIO.OUTPUT)
57+
public class DefaultClusterShade<T extends RealType<T>> extends AbstractHaralickFeature<T> {
58+
59+
@OpDependency(name = "features.haralick.coocMeanX")
60+
private Function<double[][], DoubleType> coocMeanXFunc;
61+
@OpDependency(name = "features.haralick.coocMeanY")
62+
private Function<double[][], DoubleType> coocMeanYFunc;
63+
64+
@Override
65+
public DoubleType apply(final IterableInterval<T> input, final Integer numGreyLevels, final Integer distance,
66+
final MatrixOrientation orientation) {
67+
final double[][] matrix = getCooccurrenceMatrix(input, numGreyLevels, distance, orientation);
68+
69+
final double mux = coocMeanXFunc.apply(matrix).getRealDouble();
70+
final double muy = coocMeanYFunc.apply(matrix).getRealDouble();
71+
72+
double res = 0;
73+
for (int j = 0; j < matrix.length; j++) {
74+
for (int i = 0; i < matrix.length; i++) {
75+
res += Math.pow(i + j - mux - muy, 3) * matrix[j][i];
76+
}
77+
}
78+
DoubleType output = new DoubleType();
79+
output.setReal(res);
80+
return output;
81+
}
82+
83+
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
package net.imagej.ops.features.haralick;
30+
31+
import java.util.function.Function;
32+
33+
import net.imagej.ops.image.cooccurrenceMatrix.MatrixOrientation;
34+
import net.imglib2.IterableInterval;
35+
import net.imglib2.type.numeric.RealType;
36+
import net.imglib2.type.numeric.real.DoubleType;
37+
38+
import org.scijava.ops.OpDependency;
39+
import org.scijava.ops.core.Op;
40+
import org.scijava.param.Parameter;
41+
import org.scijava.plugin.Plugin;
42+
import org.scijava.struct.ItemIO;
43+
44+
/**
45+
*
46+
* Implementation of texture contrast haralick feature.
47+
*
48+
* @author Andreas Graumann (University of Konstanz)
49+
* @author Christian Dietz (University of Konstanz)
50+
*
51+
*/
52+
@Plugin(type = Op.class, name = "features.haralick.contrast")
53+
@Parameter(key = "input")
54+
@Parameter(key = "numGreyLevels")
55+
@Parameter(key = "distance")
56+
@Parameter(key = "matrixOrientation")
57+
@Parameter(key = "output", type = ItemIO.OUTPUT)
58+
public class DefaultContrast<T extends RealType<T>> extends AbstractHaralickFeature<T> {
59+
60+
@OpDependency(name = "features.haralick.coocPXMinusY")
61+
private Function<double[][], double[]> coocPXMinusYFunc;
62+
63+
@Override
64+
public DoubleType apply(final IterableInterval<T> input, final Integer numGreyLevels, final Integer distance,
65+
final MatrixOrientation orientation) {
66+
final double[][] matrix = getCooccurrenceMatrix(input, numGreyLevels, distance, orientation);
67+
final double[] pxminusxy = coocPXMinusYFunc.apply(matrix);
68+
69+
double res = 0;
70+
for (int k = 0; k <= matrix.length - 1; k++) {
71+
res += k * k * pxminusxy[k];
72+
}
73+
74+
DoubleType output = new DoubleType();
75+
output.set(res);
76+
return output;
77+
}
78+
79+
}

0 commit comments

Comments
 (0)