Skip to content

Commit f587edf

Browse files
committed
WIP: port imageMoments namespace
1 parent fbc74c5 commit f587edf

32 files changed

Lines changed: 2611 additions & 0 deletions
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.imagemoments;
31+
32+
import net.imagej.ops.OpService;
33+
import net.imglib2.IterableInterval;
34+
import net.imglib2.type.numeric.RealType;
35+
36+
import org.scijava.ops.core.computer.Computer;
37+
38+
/**
39+
* Abstract {@link ImageMomentOp}. Provides {@link OpService} and create the
40+
* output.
41+
*
42+
* @author Daniel Seebacher (University of Konstanz)
43+
* @author Christian Dietz (University of Konstanz)
44+
* @param <I>
45+
* input type
46+
* @param <O>
47+
* output type
48+
*/
49+
public interface AbstractImageMomentOp<I extends RealType<I>, O extends RealType<O>>
50+
extends Computer<IterableInterval<I>, O> {
51+
52+
public void computeMoment(IterableInterval<I> input, O output);
53+
54+
default void compute(IterableInterval<I> input, O output) {
55+
if (input.numDimensions() != 2)
56+
throw new IllegalArgumentException("Only two-dimensional inputs allowed!");
57+
computeMoment(input, output);
58+
}
59+
60+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.imagemoments.centralmoments;
31+
32+
import net.imagej.ops.imagemoments.AbstractImageMomentOp;
33+
import net.imagej.ops.special.computer.UnaryComputerOp;
34+
import net.imglib2.IterableInterval;
35+
import net.imglib2.type.numeric.RealType;
36+
37+
import org.scijava.ops.OpDependency;
38+
import org.scijava.ops.core.Op;
39+
import org.scijava.param.Parameter;
40+
import org.scijava.plugin.Plugin;
41+
import org.scijava.struct.ItemIO;
42+
43+
/**
44+
* {@link Op} to calculate the {@code imageMoments.centralMoment00}.
45+
*
46+
* @author Daniel Seebacher (University of Konstanz)
47+
* @author Christian Dietz (University of Konstanz)
48+
* @param <I> input type
49+
* @param <O> output type
50+
*/
51+
@Plugin(type = Op.class, name = "imageMoments.centralMoment00", label = "Image Moment: CentralMoment00")
52+
@Parameter(key = "input")
53+
@Parameter(key = "output", type = ItemIO.BOTH)
54+
public class DefaultCentralMoment00<I extends RealType<I>, O extends RealType<O>>
55+
implements AbstractImageMomentOp<I, O>
56+
{
57+
58+
@OpDependency(name = "imageMoments.moment00")
59+
private UnaryComputerOp<IterableInterval<I>, O> moment00Cmp;
60+
61+
@Override
62+
public void computeMoment(final IterableInterval<I> input, final O output) {
63+
moment00Cmp.compute(input, output);
64+
}
65+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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.imagemoments.centralmoments;
31+
32+
import net.imagej.ops.imagemoments.AbstractImageMomentOp;
33+
import net.imglib2.IterableInterval;
34+
import net.imglib2.type.numeric.RealType;
35+
36+
import org.scijava.Priority;
37+
import org.scijava.ops.core.Op;
38+
import org.scijava.param.Parameter;
39+
import org.scijava.plugin.Plugin;
40+
import org.scijava.struct.ItemIO;
41+
42+
/**
43+
* {@link Op} to calculate the {@code imageMoments.centralMoment01} directly.
44+
*
45+
* @author Daniel Seebacher (University of Konstanz)
46+
* @author Christian Dietz (University of Konstanz)
47+
* @param <I> input type
48+
* @param <O> output type
49+
*/
50+
@Plugin(type = Op.class, name = "imageMoments.centralMoment01", label = "Image Moment: CentralMoment01",
51+
priority = Priority.VERY_HIGH)
52+
@Parameter(key = "input")
53+
@Parameter(key = "output", type = ItemIO.BOTH)
54+
public class DefaultCentralMoment01<I extends RealType<I>, O extends RealType<O>>
55+
implements AbstractImageMomentOp<I, O>
56+
{
57+
58+
@Override
59+
public void computeMoment(final IterableInterval<I> input, final O output) {
60+
output.setReal(0d);
61+
}
62+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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.imagemoments.centralmoments;
31+
32+
import net.imagej.ops.imagemoments.AbstractImageMomentOp;
33+
import net.imglib2.Cursor;
34+
import net.imglib2.IterableInterval;
35+
import net.imglib2.type.numeric.RealType;
36+
37+
import org.scijava.ops.OpDependency;
38+
import org.scijava.ops.core.Op;
39+
import org.scijava.ops.core.computer.Computer;
40+
import org.scijava.param.Parameter;
41+
import org.scijava.plugin.Plugin;
42+
import org.scijava.struct.ItemIO;
43+
44+
/**
45+
* {@link Op} to calculate the {@code imageMoments.centralMoment02}.
46+
*
47+
* @author Daniel Seebacher (University of Konstanz)
48+
* @author Christian Dietz (University of Konstanz)
49+
* @param <I>
50+
* input type
51+
* @param <O>
52+
* output type
53+
*/
54+
@Plugin(type = Op.class, name = "imageMoments.centralMoment02", label = "Image Moment: CentralMoment02")
55+
@Parameter(key = "input")
56+
@Parameter(key = "output", type = ItemIO.BOTH)
57+
public class DefaultCentralMoment02<I extends RealType<I>, O extends RealType<O>>
58+
implements AbstractImageMomentOp<I, O> {
59+
60+
// Required
61+
@OpDependency(name = "imageMoments.moment00")
62+
private Computer<IterableInterval<I>, O> moment00Func;
63+
64+
@OpDependency(name = "imageMoments.moment01")
65+
private Computer<IterableInterval<I>, O> moment01Func;
66+
67+
@Override
68+
public void computeMoment(final IterableInterval<I> input, final O output) {
69+
70+
final O moment00 = output.createVariable();
71+
moment00Func.compute(input, moment00);
72+
final O moment01 = output.createVariable();
73+
moment01Func.compute(input, moment01);
74+
75+
final double centerY = moment01.getRealDouble() / moment00.getRealDouble();
76+
77+
double centralmoment02 = 0;
78+
79+
final Cursor<I> it = input.localizingCursor();
80+
while (it.hasNext()) {
81+
it.fwd();
82+
final double y = it.getDoublePosition(1) - centerY;
83+
final double val = it.get().getRealDouble();
84+
85+
centralmoment02 += val * y * y;
86+
}
87+
88+
output.setReal(centralmoment02);
89+
}
90+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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.imagemoments.centralmoments;
31+
32+
import net.imagej.ops.imagemoments.AbstractImageMomentOp;
33+
import net.imglib2.Cursor;
34+
import net.imglib2.IterableInterval;
35+
import net.imglib2.type.numeric.RealType;
36+
37+
import org.scijava.ops.OpDependency;
38+
import org.scijava.ops.core.Op;
39+
import org.scijava.ops.core.computer.Computer;
40+
import org.scijava.param.Parameter;
41+
import org.scijava.plugin.Plugin;
42+
import org.scijava.struct.ItemIO;
43+
44+
/**
45+
* {@link Op} to calculate the {@code imageMoments.centralMoment03} using
46+
*
47+
* @author Daniel Seebacher (University of Konstanz)
48+
* @author Christian Dietz (University of Konstanz)
49+
* @param <I>
50+
* input type
51+
* @param <O>
52+
* output type
53+
*/
54+
@Plugin(type = Op.class, name = "imageMoments.centralMoment03", label = "Image Moment: CentralMoment03")
55+
@Parameter(key = "input")
56+
@Parameter(key = "output", type = ItemIO.BOTH)
57+
public class DefaultCentralMoment03<I extends RealType<I>, O extends RealType<O>>
58+
implements AbstractImageMomentOp<I, O> {
59+
60+
@OpDependency(name = "imageMoments.moment00")
61+
private Computer<IterableInterval<I>, O> moment00Func;
62+
@OpDependency(name = "imageMoments.moment01")
63+
private Computer<IterableInterval<I>, O> moment01Func;
64+
65+
@Override
66+
public void computeMoment(final IterableInterval<I> input, final O output) {
67+
final O moment00 = output.createVariable();
68+
moment00Func.compute(input, moment00);
69+
final O moment01 = output.createVariable();
70+
moment01Func.compute(input, moment01);
71+
72+
final double centerY = moment01.getRealDouble() / moment00.getRealDouble();
73+
74+
double centralmoment03 = 0;
75+
76+
final Cursor<I> it = input.localizingCursor();
77+
while (it.hasNext()) {
78+
it.fwd();
79+
final double y = it.getDoublePosition(1) - centerY;
80+
final double val = it.get().getRealDouble();
81+
82+
centralmoment03 += val * y * y * y;
83+
}
84+
85+
output.setReal(centralmoment03);
86+
}
87+
}

0 commit comments

Comments
 (0)