From 38d0f98b4d4b36e8d0bf5c6225a7e06d9dfb2690 Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 14:54:41 +0100 Subject: [PATCH 01/10] Add createLabelRegions method. --- .../ops/features/AbstractFeatureTest.java | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/test/java/net/imagej/ops/features/AbstractFeatureTest.java b/src/test/java/net/imagej/ops/features/AbstractFeatureTest.java index 5fe9bf3276..2cd3e00b41 100644 --- a/src/test/java/net/imagej/ops/features/AbstractFeatureTest.java +++ b/src/test/java/net/imagej/ops/features/AbstractFeatureTest.java @@ -309,30 +309,35 @@ protected static Mesh getMesh() { } protected static > LabelRegion createLabelRegion( - final RandomAccessibleInterval interval, final float min, final float max, long... dims) - { - if (dims == null || dims.length == 0) { - dims = new long[interval.numDimensions()]; - interval.dimensions(dims); - } - final ImgLabeling labeling = - new ImgLabeling<>(ArrayImgs.ints(dims)); - - final RandomAccess> ra = labeling.randomAccess(); - final RandomAccessibleIntervalCursor c = new RandomAccessibleIntervalCursor<>(interval); - final long[] pos = new long[labeling.numDimensions()]; - while (c.hasNext()) { - final T item = c.next(); - final float value = item.getRealFloat(); - if (value >= min && value <= max) { - c.localize(pos); - ra.setPosition(pos); - ra.get().add("1"); - } - } - final LabelRegions labelRegions = new LabelRegions<>(labeling); + final RandomAccessibleInterval interval, final float min, final float max, long... dims) { + final LabelRegions labelRegions = createLabelRegions(interval, min, max, dims); return labelRegions.getLabelRegion("1"); } + + protected static > LabelRegions createLabelRegions( + final RandomAccessibleInterval interval, final float min, final float max, long... dims) + { + if (dims == null || dims.length == 0) { + dims = new long[interval.numDimensions()]; + interval.dimensions(dims); + } + final ImgLabeling labeling = + new ImgLabeling<>(ArrayImgs.ints(dims)); + + final RandomAccess> ra = labeling.randomAccess(); + final RandomAccessibleIntervalCursor c = new RandomAccessibleIntervalCursor<>(interval); + final long[] pos = new long[labeling.numDimensions()]; + while (c.hasNext()) { + final T item = c.next(); + final float value = item.getRealFloat(); + if (value >= min && value <= max) { + c.localize(pos); + ra.setPosition(pos); + ra.get().add("1"); + } + } + return new LabelRegions<>(labeling); + } } From f62057607cca3a20399929ccd800a5e3d3e815db Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 14:55:27 +0100 Subject: [PATCH 02/10] Add ComputerSet. --- .../features/sets/AbstractComputerSet.java | 198 ++++++++++++++++++ .../imagej/ops/features/sets/ComputerSet.java | 81 +++++++ 2 files changed, 279 insertions(+) create mode 100644 src/main/java/net/imagej/ops/features/sets/AbstractComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/ComputerSet.java diff --git a/src/main/java/net/imagej/ops/features/sets/AbstractComputerSet.java b/src/main/java/net/imagej/ops/features/sets/AbstractComputerSet.java new file mode 100644 index 0000000000..0b5c22c0db --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/AbstractComputerSet.java @@ -0,0 +1,198 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.ops.features.sets; + +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import net.imagej.ops.CustomOpEnvironment; +import net.imagej.ops.Op; +import net.imagej.ops.OpEnvironment; +import net.imagej.ops.OpInfo; +import net.imagej.ops.special.computer.Computers; +import net.imagej.ops.special.computer.UnaryComputerOp; +import net.imagej.ops.special.function.AbstractUnaryFunctionOp; +import net.imglib2.type.Type; + +/** + * The abstract implementation of {@link ComputerSet}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * type of the common input + * @param + * type of the common output + */ +public abstract class AbstractComputerSet> extends AbstractUnaryFunctionOp> + implements ComputerSet { + + /** + * The computers of this {@link ComputerSet}. + */ + protected final Map, UnaryComputerOp> computers; + + /** + * The outputs by name of all computers. + */ + protected final Map namedOutputs; + + /** + * An instance of the output type. + */ + protected final O outputTypeInstance; + + /** + * The input type. + */ + private final Class inType; + + /** + * Create a new {@link AbstractComputerSet} with the default + * {@link OpEnvironment}. + * + * @param outputTypeInstance + * object of the output type + * @param inType + * the input type + */ + public AbstractComputerSet(final O outputTypeInstance, final Class inType) { + this(null, outputTypeInstance, inType); + } + + /** + * Create a new {@link AbstractComputerSet} with a custom + * {@link OpEnvironment}. + * + * @param opEnv + * the custom {@link OpEnvironment} + * @param outputTypeInstance + * object of the output type + * @param inType + * the input type + */ + public AbstractComputerSet(final OpEnvironment opEnv, final O outputTypeInstance, final Class inType) { + if (opEnv != null) { + setEnvironment(opEnv); + } + + this.outputTypeInstance = outputTypeInstance; + this.inType = inType; + this.computers = new HashMap<>(); + this.namedOutputs = new HashMap<>(); + } + + /** + * TEMP + * TODO: https://github.com/imagej/imagej-ops/issues/351 + * + * A fake input is need for the matching of Ops. This can be removed if the + * matcher gets improved. + * + * @return an empty input object. + */ + protected abstract I getFakeInput(); + + @Override + public void initialize() { + setInput(getFakeInput()); + initialize(null); + } + + /** + * Set {@link CustomOpEnvironment} and create all computers of this + * {@link ComputerSet}. + * + * @param infos + * for the {@link CustomOpEnvironment} + */ + protected void initialize(final Collection infos) { + if (infos != null) { + setEnvironment(new CustomOpEnvironment(ops(), infos)); + } + for (final Class computer : getComputers()) { + addComputer(computer); + } + } + + /** + * Create instance and output object for the {@link Computers}. Add both to the + * datastructures. + * + * @param clazz + * the class of the {@link Computers} + */ + protected void addComputer(final Class clazz) { + @SuppressWarnings("unchecked") + final UnaryComputerOp computer = Computers.unary(ops(), clazz, (Class) outputTypeInstance.getClass(), + in()); + final O output = outputTypeInstance.createVariable(); + namedOutputs.put(clazz.getSimpleName(), output); + computer.setOutput(output); + computers.put(clazz, computer); + } + + /** + * {@inheritDoc} + */ + @Override + public Map calculate(I input) { + computers.values().parallelStream().forEach(c -> c.compute(input, c.out())); + + return namedOutputs; + } + + @Override + public List> getActiveComputers() { + return Arrays.asList(getComputers()); + } + + /** + * {@inheritDoc} + */ + @Override + public String[] getComputerNames() { + return Arrays.asList(getComputers()).stream().map(a -> a.getSimpleName()).collect(Collectors.toList()) + .toArray(new String[computers.size()]); + } + + /** + * {@inheritDoc} + */ + @Override + public Class getInType() { + return inType; + } +} diff --git a/src/main/java/net/imagej/ops/features/sets/ComputerSet.java b/src/main/java/net/imagej/ops/features/sets/ComputerSet.java new file mode 100644 index 0000000000..359c948ee3 --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/ComputerSet.java @@ -0,0 +1,81 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.ops.features.sets; + +import java.util.List; +import java.util.Map; + +import net.imagej.ops.Op; +import net.imagej.ops.special.computer.Computers; +import net.imagej.ops.special.function.UnaryFunctionOp; + +/** + * An {@link ComputerSet} holds different {@link Computers} which can be + * computed on the same input and generate outputs of the same type. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * type of the common input + * @param + * type of the common output + */ +public interface ComputerSet extends UnaryFunctionOp> { + + /** + * The input type of the {@link Computers} of this {@link ComputerSet}. + * + * @return the input type + */ + Class getInType(); + + /** + * The {@link Computers} which define this {@link ComputerSet}. + * + * @return all {@link Computers} of this {@link ComputerSet} + */ + Class[] getComputers(); + + /** + * An array of the names of all {@link Computers} which will be executed. + * + * @return the names of all active {@link Computers}. + */ + String[] getComputerNames(); + + /** + * Get all active {@link Computers} of this {@link ComputerSet}. + * + * @return the active {@link Computers} + */ + List> getActiveComputers(); + +} From 09e745ad1b5af923b491068d9a0fe376c9cb16c9 Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 14:55:45 +0100 Subject: [PATCH 03/10] Add ConfigurableComputerSet. --- .../sets/AbstractConfigurableComputerSet.java | 177 ++++++++++++++++++ .../sets/ConfigurableComputerSet.java | 59 ++++++ 2 files changed, 236 insertions(+) create mode 100644 src/main/java/net/imagej/ops/features/sets/AbstractConfigurableComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/ConfigurableComputerSet.java diff --git a/src/main/java/net/imagej/ops/features/sets/AbstractConfigurableComputerSet.java b/src/main/java/net/imagej/ops/features/sets/AbstractConfigurableComputerSet.java new file mode 100644 index 0000000000..92dc373aff --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/AbstractConfigurableComputerSet.java @@ -0,0 +1,177 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.ops.features.sets; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import net.imagej.ops.CustomOpEnvironment; +import net.imagej.ops.Op; +import net.imagej.ops.OpEnvironment; +import net.imagej.ops.OpInfo; +import net.imagej.ops.special.computer.Computers; +import net.imglib2.type.Type; + +import org.scijava.plugin.Parameter; + +/** + * An abstract implementation of {@link ComputerSet} which is configurable. + * + * {@link Computers} passed by construction will be activated and all remaining + * will be deactivated. If no {@link Computers} is passed, all {@link Computers} + * will be activated by default. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * type of the common input + * @param + * type of the common output + */ +public abstract class AbstractConfigurableComputerSet> extends AbstractComputerSet + implements ConfigurableComputerSet { + + @Parameter(required = false) + private List> active; + + /** + * The activated {@link Computers}. + */ + private final Map, Boolean> activated; + + /** + * Create a new {@link AbstractConfigurableComputerSet} with the default + * {@link OpEnvironment}. + * + * @param outputTypeInstance + * object of the output type + * @param inType + * the input type + */ + public AbstractConfigurableComputerSet(final O outputTypeInstance, final Class inType) { + super(null, outputTypeInstance, inType); + active = new ArrayList<>(); + activated = new HashMap<>(); + } + + /** + * Create a new {@link AbstractConfigurableComputerSet} with a custom + * {@link OpEnvironment}. + * + * @param opEnv + * the custom {@link OpEnvironment} + * @param outputTypeInstance + * object of the output type + * @param inType + * the input type + */ + public AbstractConfigurableComputerSet(final OpEnvironment opEnv, final O outputTypeInstance, + final Class inType) { + super(opEnv, outputTypeInstance, inType); + active = new ArrayList<>(); + activated = new HashMap<>(); + } + + /** + * {@inheritDoc} + */ + @Override + public void initialize() { + if (active.isEmpty()) { + active.addAll(Arrays.asList(getComputers())); + } + super.initialize(); + } + + /** + * Set {@link CustomOpEnvironment} and create all computers of this + * {@link ComputerSet} and activate passed {@link Computers}. + * + * @param infos + * for the {@link CustomOpEnvironment} + */ + @Override + protected void initialize(final Collection infos) { + if (infos != null) { + setEnvironment(new CustomOpEnvironment(ops(), infos)); + } + + for (final Class computer : getComputers()) { + if (active.contains(computer)) { + activated.put(computer, true); + addComputer(computer); + } else { + activated.put(computer, false); + } + } + } + + /** + * {@inheritDoc} + */ + @Override + public Map calculate(final I input) { + + activated.entrySet().parallelStream().filter(a -> a.getValue()) + .map(a -> computers.get(a.getKey())).forEach(c -> c.compute(input, c.out())); + + return namedOutputs; + } + + /** + * {@inheritDoc} + */ + @Override + public List> getActiveComputers() { + return activated.entrySet().stream().filter(e -> e.getValue()).map(e -> e.getKey()) + .collect(Collectors.toList()); + } + + @Override + public String[] getComputerNames() { + return getActiveComputers().stream().map(a -> a.getSimpleName()).collect(Collectors.toList()) + .toArray(new String[computers.size()]); + } + + /** + * {@inheritDoc} + */ + @Override + public List> getInactiveComputers() { + return activated.entrySet().stream().filter(e -> !e.getValue()).map(e -> e.getKey()) + .collect(Collectors.toList()); + } +} diff --git a/src/main/java/net/imagej/ops/features/sets/ConfigurableComputerSet.java b/src/main/java/net/imagej/ops/features/sets/ConfigurableComputerSet.java new file mode 100644 index 0000000000..7caf948e84 --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/ConfigurableComputerSet.java @@ -0,0 +1,59 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets; + +import java.util.List; + +import net.imagej.ops.Op; +import net.imagej.ops.special.computer.Computers; + +/** + * A {@link ConfigurableComputerSet} can be initialized with only a subset of + * activated {@link Computers}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * type of the common input + * @param + * type of the common output + */ +public interface ConfigurableComputerSet extends ComputerSet { + + + /** + * Get all inactive {@link Computers} of this + * {@link ConfigurableComputerSet}. + * + * @return the inactive {@link Computers} + */ + List> getInactiveComputers(); + +} From da3981b707618913948aa8bd3e648579f355b81b Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 14:56:14 +0100 Subject: [PATCH 04/10] Add ComputerSetTableService. --- .../sets/tables/ComputerSetTableService.java | 84 +++++++++++++++++ .../DefaultComputerSetTableService.java | 94 +++++++++++++++++++ 2 files changed, 178 insertions(+) create mode 100644 src/main/java/net/imagej/ops/features/sets/tables/ComputerSetTableService.java create mode 100644 src/main/java/net/imagej/ops/features/sets/tables/DefaultComputerSetTableService.java diff --git a/src/main/java/net/imagej/ops/features/sets/tables/ComputerSetTableService.java b/src/main/java/net/imagej/ops/features/sets/tables/ComputerSetTableService.java new file mode 100644 index 0000000000..3be064e5cb --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/tables/ComputerSetTableService.java @@ -0,0 +1,84 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.tables; + +import java.util.Map; + +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.processors.ComputerSetProcessor; +import net.imagej.ops.special.computer.Computers; +import net.imagej.table.GenericTable; +import net.imglib2.type.Type; + +/** + * This class creates a result table for a {@link ComputerSetProcessor}. + * + * @author Tim-Oliver Buchholz, University of Konstanz. + * + * @param + * datatype of the table entries + */ +public interface ComputerSetTableService> { + + /** + * Create a new {@link GenericTable} to store the results of a + * {@link ComputerSetProcessor}. + * + * @param computerSets + * of the {@link ComputerSetProcessor} + * @param names + * a map which maps a unique name to each {@link ComputerSet} + * @param numRows + * number of rows + * @return a table with a column for each {@link Computers} and numRows + * rows. + */ + public GenericTable createTable(final ComputerSet[] computerSets, final Map, String> names, + final int numRows); + + /** + * Create a new {@link GenericTable} to store the results of a + * {@link ComputerSetProcessor} and the label name. The name of the label is + * stored in the first column. + * + * @param computerSets + * of the {@link ComputerSetProcessor} + * @param names + * a map which maps a unique name to each {@link ComputerSet} + * @param labelColumnName + * the name of the label column. The column name has to be unique. + * @param numRows + * number of rows + * @return a table with a column for each {@link Computers} and numRows + * rows. + */ + public GenericTable createTable(final ComputerSet[] computerSets, final Map, String> names, + final String labelColumnName, final int numRows); +} diff --git a/src/main/java/net/imagej/ops/features/sets/tables/DefaultComputerSetTableService.java b/src/main/java/net/imagej/ops/features/sets/tables/DefaultComputerSetTableService.java new file mode 100644 index 0000000000..f663753eff --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/tables/DefaultComputerSetTableService.java @@ -0,0 +1,94 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.tables; + +import java.util.Map; + +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.processors.ComputerSetProcessor; +import net.imagej.ops.features.sets.processors.ComputerSetProcessorUtils; +import net.imagej.table.DefaultGenericTable; +import net.imagej.table.GenericTable; +import net.imglib2.type.Type; + +/** + * Default implementation of {@link ComputerSetTableService}. + * + * The columns are added in the same order the {@link ComputerSet}s were added + * to the {@link ComputerSetProcessor}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +public class DefaultComputerSetTableService> implements ComputerSetTableService { + + private final GenericTable table; + + public DefaultComputerSetTableService() { + table = new DefaultGenericTable(); + } + + @Override + public GenericTable createTable(final ComputerSet[] computerSets, + final Map, String> names, final int numRows) { + for (final ComputerSet computerSet : computerSets) { + final String computerSetName = names.get(computerSet); + + for (final String computerName : computerSet.getComputerNames()) { + table.appendColumn(ComputerSetProcessorUtils.getComputerTableName(computerSetName, computerName)); + + } + } + + for (int i = 0; i < numRows; i++) { + table.appendRow(); + } + return table; + } + + @Override + public GenericTable createTable(ComputerSet[] computerSets, Map, String> names, + String labelColumnName, int numRows) { + table.appendColumn(labelColumnName); + for (final ComputerSet computerSet : computerSets) { + final String computerSetName = names.get(computerSet); + + for (final String computerName : computerSet.getComputerNames()) { + table.appendColumn(ComputerSetProcessorUtils.getComputerTableName(computerSetName, computerName)); + + } + } + + for (int i = 0; i < numRows; i++) { + table.appendRow(); + } + return table; + } +} From 5ae2ab52a2626da0cbebddf9aa81ad43b5e4854c Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 14:57:56 +0100 Subject: [PATCH 05/10] Add ComputerSetProcessor. --- .../AbstractBinaryComputerSetProcessor.java | 74 ++++++++ .../AbstractUnaryComputerSetProcessor.java | 72 ++++++++ .../sets/processors/ComputerSetProcessor.java | 51 ++++++ .../processors/ComputerSetProcessorUtils.java | 164 ++++++++++++++++++ 4 files changed, 361 insertions(+) create mode 100644 src/main/java/net/imagej/ops/features/sets/processors/AbstractBinaryComputerSetProcessor.java create mode 100644 src/main/java/net/imagej/ops/features/sets/processors/AbstractUnaryComputerSetProcessor.java create mode 100644 src/main/java/net/imagej/ops/features/sets/processors/ComputerSetProcessor.java create mode 100644 src/main/java/net/imagej/ops/features/sets/processors/ComputerSetProcessorUtils.java diff --git a/src/main/java/net/imagej/ops/features/sets/processors/AbstractBinaryComputerSetProcessor.java b/src/main/java/net/imagej/ops/features/sets/processors/AbstractBinaryComputerSetProcessor.java new file mode 100644 index 0000000000..cdb486cafb --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/processors/AbstractBinaryComputerSetProcessor.java @@ -0,0 +1,74 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.concurrent.ExecutorService; + +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.special.hybrid.AbstractBinaryHybridCF; +import net.imagej.table.GenericTable; +import net.imglib2.type.Type; + +import org.scijava.convert.ConvertService; +import org.scijava.plugin.Parameter; +import org.scijava.thread.ThreadService; + +/** + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * Type of the input object. + * @param + * Type of the second input object. + * @param + * Inputtype of the {@link ComputerSet}. + * @param + * Outputtype of the {@link ComputerSet}. + */ +public abstract class AbstractBinaryComputerSetProcessor> + extends AbstractBinaryHybridCF implements ComputerSetProcessor { + + @Parameter + protected ComputerSet[] computerSets; + + @Parameter + protected ThreadService ts; + + @Parameter + protected ConvertService cs; + + protected ExecutorService es; + + @Override + public void initialize() { + es = ts.getExecutorService(); + } + +} diff --git a/src/main/java/net/imagej/ops/features/sets/processors/AbstractUnaryComputerSetProcessor.java b/src/main/java/net/imagej/ops/features/sets/processors/AbstractUnaryComputerSetProcessor.java new file mode 100644 index 0000000000..612f99ab5d --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/processors/AbstractUnaryComputerSetProcessor.java @@ -0,0 +1,72 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.concurrent.ExecutorService; + +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.special.hybrid.AbstractUnaryHybridCF; +import net.imagej.table.GenericTable; +import net.imglib2.type.Type; + +import org.scijava.convert.ConvertService; +import org.scijava.plugin.Parameter; +import org.scijava.thread.ThreadService; + +/** + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * Type of the input object. + * @param + * Inputtype of the {@link ComputerSet}. + * @param + * Outputtype of the {@link ComputerSet}. + */ +public abstract class AbstractUnaryComputerSetProcessor> + extends AbstractUnaryHybridCF implements ComputerSetProcessor { + + @Parameter + protected ComputerSet[] computerSets; + + @Parameter + protected ThreadService ts; + + @Parameter + protected ConvertService cs; + + protected ExecutorService es; + + @Override + public void initialize() { + es = ts.getExecutorService(); + } + +} diff --git a/src/main/java/net/imagej/ops/features/sets/processors/ComputerSetProcessor.java b/src/main/java/net/imagej/ops/features/sets/processors/ComputerSetProcessor.java new file mode 100644 index 0000000000..c8f62a35ea --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/processors/ComputerSetProcessor.java @@ -0,0 +1,51 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.ops.features.sets.processors; + +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.special.computer.Computers; +import net.imagej.ops.special.hybrid.UnaryHybridCF; +import net.imagej.table.GenericTable; +import net.imagej.table.Table; + +/** + * A {@link ComputerSetProcessor} holds arbitrary many {@link ComputerSet} of + * the same types. All active {@link Computers} from every {@link ComputerSet} are + * computed on the input object and written to a {@link Table}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * Input type + */ +public interface ComputerSetProcessor extends UnaryHybridCF { + // NB: Marker Interface +} diff --git a/src/main/java/net/imagej/ops/features/sets/processors/ComputerSetProcessorUtils.java b/src/main/java/net/imagej/ops/features/sets/processors/ComputerSetProcessorUtils.java new file mode 100644 index 0000000000..30d7fc484d --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/processors/ComputerSetProcessorUtils.java @@ -0,0 +1,164 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.DefaultFirstOrderStatsComputerSet; +import net.imagej.ops.features.sets.DefaultGeometric2DComputerSet; +import net.imagej.ops.features.sets.DefaultZernikeComputerSet; +import net.imagej.ops.special.computer.Computers; +import net.imglib2.RealPoint; +import net.imglib2.img.array.ArrayImg; +import net.imglib2.img.array.ArrayImgFactory; +import net.imglib2.roi.geometric.Polygon; +import net.imglib2.type.Type; +import net.imglib2.type.numeric.real.DoubleType; + +/** + * A utility class to handle {@link ComputerSet} with a + * {@link ComputerSetProcessor}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +public class ComputerSetProcessorUtils { + + /** + * Add unique suffix if needed. + * + * @param names + * already used names + * @param n + * the new suggested name + * @return the unique name + */ + protected static String uniqueName(final Collection names, final String n) { + + if (!names.contains(n)) { + return n; + } + + int c = 0; + + while (names.contains(n + "[" + c + "]")) { + c++; + } + + return n + "[" + c + "]"; + } + + /** + * Concatenate {@link ComputerSet} name with feature name. + * + * @param computerSetName + * the name of the {@link ComputerSet} + * @param computerName + * the name of the {@link Computers} + * @return the concatenated string + */ + public static String getComputerTableName(final String computerSetName, final String computerName) { + return computerSetName + "_" + computerName; + } + + /** + * Creates a map from {@link ComputerSet} to a unique String. If a + * {@link ComputerSet} has a duplicate the suffix "[i]" (i = 0,...) is + * added. + * + * @param computerSets + * for which unique names are required + * @return map from computerSets to unique names + */ + protected static Map, String> getUniqueNames(final List> computerSets) { + + final Map, String> names = new HashMap<>(); + + for (final ComputerSet computerSet : computerSets) { + final String n = uniqueName(names.values(), computerSet.getClass().getSimpleName()); + names.put(computerSet, n); + } + + return names; + } + + /** + * This method is used in {@link DefaultGeometric2DComputerSet} as input + * object which is needed for the matching. + * + * Note: This is just a workaround. + * + * @return polygon with two vertices. + */ + public static Polygon get2DPolygon() { + final List v = new ArrayList<>(); + + v.add(new RealPoint(0, 0)); + v.add(new RealPoint(1, 1)); + return new Polygon(v); + } + + /** + * This method is used in {@link DefaultFirstOrderStatsComputerSet} as input + * object which is needed for the matching. + * + * Note: This is just a workaround. + * + * @return an Iterable + */ + public static > Iterable getIterable() { + return new Iterable() { + + @Override + public Iterator iterator() { + // just a fake object + return null; + } + }; + } + + /** + * This method is used in {@link DefaultZernikeComputerSet} as input object + * which is needed for the matching. + * + * Note: This is just a workaround. + * + * @return a 2D img + */ + public static > ArrayImg get2DImg() { + return new ArrayImgFactory().create(new long[] { 2, 2 }, new DoubleType()); + } +} From c69a32c8f2c73aac3849b0647ad563b1d288b098 Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 14:58:27 +0100 Subject: [PATCH 06/10] Add IterableComputerSetProcessor. --- .../IterableComputerSetProcessor.java | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 src/main/java/net/imagej/ops/features/sets/processors/IterableComputerSetProcessor.java diff --git a/src/main/java/net/imagej/ops/features/sets/processors/IterableComputerSetProcessor.java b/src/main/java/net/imagej/ops/features/sets/processors/IterableComputerSetProcessor.java new file mode 100644 index 0000000000..8105159c8b --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/processors/IterableComputerSetProcessor.java @@ -0,0 +1,94 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.Arrays; +import java.util.Map; +import java.util.Map.Entry; + +import net.imagej.ops.Op; +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.tables.ComputerSetTableService; +import net.imagej.ops.special.computer.Computers; +import net.imagej.table.GenericTable; +import net.imglib2.type.Type; + +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; + +/** + * An IterableProcessor holds {@link ComputerSet}s and + * {@link IterableComputerSetProcessor#compute(Iterable, GenericTable)} computes + * the {@link Computers} on the given {@link Iterable} and returns a + * {@link GenericTable}. + * + * The {@link GenericTable} has one row and as many columns as {@link Computers} + * were calculated. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * Iterable type + * @param + * Output type of the {@link Computers}. + */ +@Plugin(type = Op.class) +public class IterableComputerSetProcessor> + extends AbstractUnaryComputerSetProcessor, Iterable, O> { + + @Parameter + private ComputerSetTableService csts; + + /** + * Maps each {@link ComputerSet} to a unique name. This ensures unique + * column names in the {@link GenericTable}. + */ + private Map, String> names; + + @Override + public GenericTable createOutput(final Iterable input1) { + names = ComputerSetProcessorUtils.getUniqueNames(Arrays.asList(computerSets)); + return csts.createTable(computerSets, names, 1); + } + + @Override + public void compute(final Iterable input1, final GenericTable output) { + + Arrays.asList(computerSets).parallelStream().forEach(c -> { + final Map result = c.calculate(input1); + for (final Entry entry : result.entrySet()) { + output.set(ComputerSetProcessorUtils.getComputerTableName(names.get(c), entry.getKey()), 0, + entry.getValue()); + } + }); + + } + +} From 2e9c3a513193913fb6f27f483ec3a70ee3dbd47e Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 14:58:42 +0100 Subject: [PATCH 07/10] Add LabelRegionsComputerSetProcessor. --- .../LabelRegionsComputerSetProcessor.java | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 src/main/java/net/imagej/ops/features/sets/processors/LabelRegionsComputerSetProcessor.java diff --git a/src/main/java/net/imagej/ops/features/sets/processors/LabelRegionsComputerSetProcessor.java b/src/main/java/net/imagej/ops/features/sets/processors/LabelRegionsComputerSetProcessor.java new file mode 100644 index 0000000000..684a6335a6 --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/processors/LabelRegionsComputerSetProcessor.java @@ -0,0 +1,113 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.Arrays; +import java.util.Map; +import java.util.Map.Entry; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.StreamSupport; + +import net.imagej.ops.Op; +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.tables.ComputerSetTableService; +import net.imagej.ops.special.computer.Computers; +import net.imagej.table.GenericTable; +import net.imglib2.roi.labeling.LabelRegion; +import net.imglib2.roi.labeling.LabelRegions; +import net.imglib2.type.Type; + +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; + +/** + * A LabelRegionsProcessor holds {@link ComputerSet}s and + * {@link LabelRegionsComputerSetProcessor#compute(LabelRegions, GenericTable)} + * computes the {@link Computers} on the given {@link LabelRegions} and returns a + * {@link GenericTable}. + * + * The {@link GenericTable} holds for each {@link LabelRegion} a row and has as + * many columns as {@link Computers} were calculated. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * LabelRegions type + * @param + * Type of the converted {@link LabelRegion} + * @param + * Output type of the {@link Computers}. + */ +@Plugin(type = Op.class) +public class LabelRegionsComputerSetProcessor> + extends AbstractUnaryComputerSetProcessor, F, O> { + + @Parameter + private ComputerSetTableService csts; + + /** + * Maps each {@link ComputerSet} to a unique name. This ensures unique + * column names in the {@link GenericTable}. + */ + private Map, String> names; + + /** + * Name of the column where the label is stored. + */ + private String labelColumnName; + + @Override + public GenericTable createOutput(final LabelRegions input1) { + names = ComputerSetProcessorUtils.getUniqueNames(Arrays.asList(computerSets)); + labelColumnName = ComputerSetProcessorUtils.uniqueName(names.values(), "Label"); + return csts.createTable(computerSets, names, labelColumnName, input1.getExistingLabels().size()); + } + + @Override + public void compute(final LabelRegions input1, final GenericTable output) { + + AtomicInteger rowIdx = new AtomicInteger(0); + + StreamSupport.stream(input1.spliterator(), true).parallel().forEach(r -> { + final int j = rowIdx.getAndIncrement(); + for (final ComputerSet computerSet : computerSets) { + // LabelRegion has to be converted to Polygon or Mesh. + final Map result = computerSet.calculate(cs.convert(r, computerSet.getInType())); + for (final Entry entry : result.entrySet()) { + output.set(ComputerSetProcessorUtils.getComputerTableName(names.get(computerSet), entry.getKey()), j, + result.get(entry.getValue())); + } + } + output.set(labelColumnName, j, r.getLabel()); + }); + + } + +} From 935717cd37e0a8f1bace3b0d556ca6ff932594cb Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 14:58:53 +0100 Subject: [PATCH 08/10] Add ROIComputerSetProcessor. --- .../processors/ROIComputerSetProcessor.java | 120 ++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/main/java/net/imagej/ops/features/sets/processors/ROIComputerSetProcessor.java diff --git a/src/main/java/net/imagej/ops/features/sets/processors/ROIComputerSetProcessor.java b/src/main/java/net/imagej/ops/features/sets/processors/ROIComputerSetProcessor.java new file mode 100644 index 0000000000..7ad1672196 --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/processors/ROIComputerSetProcessor.java @@ -0,0 +1,120 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; +import java.util.concurrent.atomic.AtomicInteger; + +import net.imagej.ops.Op; +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.tables.ComputerSetTableService; +import net.imagej.ops.special.computer.Computers; +import net.imagej.table.GenericTable; +import net.imglib2.RandomAccessible; +import net.imglib2.roi.Regions; +import net.imglib2.roi.labeling.LabelRegion; +import net.imglib2.roi.labeling.LabelRegions; +import net.imglib2.type.Type; +import net.imglib2.util.Pair; +import net.imglib2.util.ValuePair; + +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; + +/** + * A ROIProcessor holds {@link ComputerSet}s and + * {@link ROIComputerSetProcessor#compute(RandomAccessible, LabelRegions, GenericTable)} + * computes the {@link Computers} on the sampled {@link LabelRegion} of I and + * returns a {@link GenericTable}. + * + * The {@link GenericTable} holds for each {@link LabelRegion} a row and has as + * many columns as {@link Computers} were calculated. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * type of the {@link RandomAccessible} + * @param + * type of the {@link LabelRegions} + * @param + * output type of the {@link Computers} + */ +@Plugin(type = Op.class) +public class ROIComputerSetProcessor, S, O extends Type> + extends AbstractBinaryComputerSetProcessor, LabelRegions, Iterable, O> { + + @Parameter + private ComputerSetTableService csts; + + /** + * Maps each {@link ComputerSet} to a unique name. This ensures unique + * column names in the {@link GenericTable}. + */ + private Map, String> names; + + /** + * Name of the column where the label is stored. + */ + private String labelColumnName; + + @Override + public GenericTable createOutput(final RandomAccessible input1, final LabelRegions input2) { + names = ComputerSetProcessorUtils.getUniqueNames(Arrays.asList(computerSets)); + labelColumnName = ComputerSetProcessorUtils.uniqueName(names.values(), "Label"); + return csts.createTable(computerSets, names, labelColumnName, input2.getExistingLabels().size()); + } + + @Override + public void compute(final RandomAccessible input1, final LabelRegions input2, final GenericTable output) { + + Set, S>> regions = new HashSet<>(); + input2.forEach(r -> regions.add(new ValuePair, S>(Regions.sample(r, input1), r.getLabel()))); + + AtomicInteger rowIdx = new AtomicInteger(0); + + regions.parallelStream().forEach(p -> { + final int j = rowIdx.getAndIncrement(); + for (final ComputerSet, O> computerSet : computerSets) { + final Map result = computerSet.calculate(p.getA()); + for (final Entry entry : result.entrySet()) { + output.set(ComputerSetProcessorUtils.getComputerTableName(names.get(computerSet), entry.getKey()), + j, entry.getValue()); + } + } + output.set(labelColumnName, j, p.getB()); + }); + + } + +} From b2c8899330e3e4d392d1e224d93769ad2651920c Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 15:00:30 +0100 Subject: [PATCH 09/10] Add FirstOrderStats-, Geometric2D-, Histogram- and ZernikeComputerSet. --- .../DefaultFirstOrderStatsComputerSet.java | 101 +++++++++++++++ .../sets/DefaultGeometric2DComputerSet.java | 81 ++++++++++++ .../sets/DefaultHistogramComputerSet.java | 115 ++++++++++++++++++ .../sets/DefaultZernikeComputerSet.java | 115 ++++++++++++++++++ .../sets/FirstOrderStatsComputerSet.java | 47 +++++++ .../features/sets/Geometric2DComputerSet.java | 47 +++++++ .../features/sets/HistogramComputerSet.java | 47 +++++++ .../ops/features/sets/ZernikeComputerSet.java | 47 +++++++ 8 files changed, 600 insertions(+) create mode 100644 src/main/java/net/imagej/ops/features/sets/DefaultFirstOrderStatsComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/DefaultGeometric2DComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/DefaultHistogramComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/DefaultZernikeComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/FirstOrderStatsComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/Geometric2DComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/HistogramComputerSet.java create mode 100644 src/main/java/net/imagej/ops/features/sets/ZernikeComputerSet.java diff --git a/src/main/java/net/imagej/ops/features/sets/DefaultFirstOrderStatsComputerSet.java b/src/main/java/net/imagej/ops/features/sets/DefaultFirstOrderStatsComputerSet.java new file mode 100644 index 0000000000..4d7fdf3033 --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/DefaultFirstOrderStatsComputerSet.java @@ -0,0 +1,101 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ + +package net.imagej.ops.features.sets; + +import net.imagej.ops.Op; +import net.imagej.ops.Ops.Stats.GeometricMean; +import net.imagej.ops.Ops.Stats.HarmonicMean; +import net.imagej.ops.Ops.Stats.Kurtosis; +import net.imagej.ops.Ops.Stats.Max; +import net.imagej.ops.Ops.Stats.Mean; +import net.imagej.ops.Ops.Stats.Median; +import net.imagej.ops.Ops.Stats.Min; +import net.imagej.ops.Ops.Stats.Moment1AboutMean; +import net.imagej.ops.Ops.Stats.Moment2AboutMean; +import net.imagej.ops.Ops.Stats.Moment3AboutMean; +import net.imagej.ops.Ops.Stats.Moment4AboutMean; +import net.imagej.ops.Ops.Stats.Size; +import net.imagej.ops.Ops.Stats.Skewness; +import net.imagej.ops.Ops.Stats.StdDev; +import net.imagej.ops.Ops.Stats.Sum; +import net.imagej.ops.Ops.Stats.SumOfInverses; +import net.imagej.ops.Ops.Stats.SumOfLogs; +import net.imagej.ops.Ops.Stats.SumOfSquares; +import net.imagej.ops.Ops.Stats.Variance; +import net.imagej.ops.features.sets.processors.ComputerSetProcessorUtils; +import net.imglib2.type.numeric.real.DoubleType; + +import org.scijava.plugin.Plugin; + +/** + * Default implementation of {@link FirstOrderStatsComputerSet}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +@Plugin(type = ComputerSet.class, label = "First Order Statistic Computers") +@SuppressWarnings("rawtypes") +public class DefaultFirstOrderStatsComputerSet extends AbstractConfigurableComputerSet + implements FirstOrderStatsComputerSet { + + public DefaultFirstOrderStatsComputerSet() { + super(new DoubleType(), Iterable.class); + } + + @SuppressWarnings("unused") + @Override + public void initialize() { + if (false) { + // Add special implementations if needed. + // initialize(Arrays.asList(MinBasedOnMinMax.class, + // MaxBasedOnMinMax.class)); + } else { + super.initialize(); + } + } + + @SuppressWarnings("unchecked") + @Override + public Class[] getComputers() { + return new Class[] { GeometricMean.class, HarmonicMean.class, Kurtosis.class, Mean.class, Median.class, + Min.class, Max.class, Moment1AboutMean.class, Moment2AboutMean.class, Moment3AboutMean.class, + Moment4AboutMean.class, Size.class, Skewness.class, StdDev.class, Sum.class, SumOfInverses.class, + SumOfLogs.class, SumOfSquares.class, Variance.class }; + } + + /** + * {@inheritDoc} + */ + @Override + protected Iterable getFakeInput() { + return ComputerSetProcessorUtils.getIterable(); + } +} diff --git a/src/main/java/net/imagej/ops/features/sets/DefaultGeometric2DComputerSet.java b/src/main/java/net/imagej/ops/features/sets/DefaultGeometric2DComputerSet.java new file mode 100644 index 0000000000..569960e802 --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/DefaultGeometric2DComputerSet.java @@ -0,0 +1,81 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets; + +import net.imagej.ops.Op; +import net.imagej.ops.Ops.Geometric.BoundarySize; +import net.imagej.ops.Ops.Geometric.Boxivity; +import net.imagej.ops.Ops.Geometric.Circularity; +import net.imagej.ops.Ops.Geometric.Convexity; +import net.imagej.ops.Ops.Geometric.Eccentricity; +import net.imagej.ops.Ops.Geometric.MainElongation; +import net.imagej.ops.Ops.Geometric.MajorAxis; +import net.imagej.ops.Ops.Geometric.MaximumFeretsAngle; +import net.imagej.ops.Ops.Geometric.MaximumFeretsDiameter; +import net.imagej.ops.Ops.Geometric.MinimumFeretsAngle; +import net.imagej.ops.Ops.Geometric.MinimumFeretsDiameter; +import net.imagej.ops.Ops.Geometric.MinorAxis; +import net.imagej.ops.Ops.Geometric.Roundness; +import net.imagej.ops.Ops.Geometric.Size; +import net.imagej.ops.Ops.Geometric.Solidity; +import net.imagej.ops.features.sets.processors.ComputerSetProcessorUtils; +import net.imglib2.roi.geometric.Polygon; +import net.imglib2.type.numeric.real.DoubleType; + +import org.scijava.plugin.Plugin; + +/** + * Default implementation of {@link Geometric2DComputerSet}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +@Plugin(type = ComputerSet.class, label = "Geometric 2D Computers") +public class DefaultGeometric2DComputerSet extends AbstractConfigurableComputerSet + implements Geometric2DComputerSet { + + public DefaultGeometric2DComputerSet() { + super(new DoubleType(), Polygon.class); + } + + @SuppressWarnings("unchecked") + @Override + public Class[] getComputers() { + return new Class[] { Boxivity.class, Convexity.class, Circularity.class, Eccentricity.class, + MainElongation.class, MinimumFeretsAngle.class, MaximumFeretsAngle.class, MinimumFeretsDiameter.class, + MaximumFeretsDiameter.class, MajorAxis.class, MinorAxis.class, BoundarySize.class, Roundness.class, + Solidity.class, Size.class }; + } + + @Override + protected Polygon getFakeInput() { + return ComputerSetProcessorUtils.get2DPolygon(); + } +} diff --git a/src/main/java/net/imagej/ops/features/sets/DefaultHistogramComputerSet.java b/src/main/java/net/imagej/ops/features/sets/DefaultHistogramComputerSet.java new file mode 100644 index 0000000000..b7a78dcaaa --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/DefaultHistogramComputerSet.java @@ -0,0 +1,115 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.imagej.ops.Op; +import net.imagej.ops.features.sets.processors.ComputerSetProcessorUtils; +import net.imagej.ops.image.histogram.HistogramCreate; +import net.imagej.ops.special.function.Functions; +import net.imagej.ops.special.function.UnaryFunctionOp; +import net.imglib2.histogram.Histogram1d; +import net.imglib2.type.numeric.integer.LongType; + +import org.scijava.ItemIO; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; + +/** + * Default implementation of {@link HistogramComputerSet}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + */ +@Plugin(type = ComputerSet.class, label = "Histogram Computerset") +@SuppressWarnings("rawtypes") +public class DefaultHistogramComputerSet extends AbstractComputerSet + implements HistogramComputerSet { + + @Parameter(type = ItemIO.INPUT, label = "Number of Bins", description = "The number of bins of the histogram", min = "1", max = "2147483647", stepSize = "1") + private int numBins = 256; + + private UnaryFunctionOp histogramFunc; + + public DefaultHistogramComputerSet() { + super(new LongType(), Iterable.class); + } + + @Override + public void initialize() { + super.initialize(); + histogramFunc = Functions.unary(ops(), HistogramCreate.class, Histogram1d.class, in(), numBins); + } + + @SuppressWarnings("unchecked") + @Override + public Class[] getComputers() { + return new Class[] { HistogramCreate.class }; + } + + @Override + protected Iterable getFakeInput() { + return ComputerSetProcessorUtils.getIterable(); + } + + @Override + protected void addComputer(final Class clazz) { + for (int i = 0; i < numBins; i++) { + final LongType output = outputTypeInstance.createVariable(); + namedOutputs.put(getKey(i), output); + } + } + + @Override + public Map calculate(final Iterable input) { + final Histogram1d histogram = histogramFunc.calculate(input); + final Map result = new HashMap<>(); + for (int i = 0; i < numBins; i++) { + result.put(getKey(i), new LongType(histogram.frequency(i))); + } + return result; + } + + private String getKey(final int bin) { + return "Histogram Bin[" + bin + "]"; + } + + @Override + public String[] getComputerNames() { + final List names = new ArrayList<>(); + for (int i = 0; i < numBins; i++) { + names.add(getKey(i)); + } + return names.toArray(new String[names.size()]); + } +} diff --git a/src/main/java/net/imagej/ops/features/sets/DefaultZernikeComputerSet.java b/src/main/java/net/imagej/ops/features/sets/DefaultZernikeComputerSet.java new file mode 100644 index 0000000000..dfde3ca11e --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/DefaultZernikeComputerSet.java @@ -0,0 +1,115 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets; + +import java.util.ArrayList; +import java.util.List; + +import net.imagej.ops.Op; +import net.imagej.ops.Ops.Zernike.Magnitude; +import net.imagej.ops.Ops.Zernike.Phase; +import net.imagej.ops.features.sets.processors.ComputerSetProcessorUtils; +import net.imagej.ops.special.computer.Computers; +import net.imagej.ops.special.computer.UnaryComputerOp; +import net.imglib2.type.numeric.real.DoubleType; + +import org.scijava.ItemIO; +import org.scijava.plugin.Parameter; +import org.scijava.plugin.Plugin; + +/** + * Default implementation of {@link ZernikeComputerSet}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +@Plugin(type = ComputerSet.class, label = "Zernike Computerset") +@SuppressWarnings("rawtypes") +public class DefaultZernikeComputerSet extends AbstractConfigurableComputerSet + implements ZernikeComputerSet { + + @Parameter(type = ItemIO.INPUT, label = "Minimum Order of Zernike Moment", description = "The minimum order of the zernike moment to be calculated.", min = "1", max = "2147483647", stepSize = "1") + private int orderMin = 2; + + @Parameter(type = ItemIO.INPUT, label = "Maximum Order of Zernike Moment", description = "The maximum order of the zernike moment to be calculated.", min = "1", max = "2147483647", stepSize = "1") + private int orderMax = 4; + + public DefaultZernikeComputerSet() { + super(new DoubleType(), Iterable.class); + } + + @SuppressWarnings("unchecked") + @Override + public Class[] getComputers() { + return new Class[] { Phase.class, Magnitude.class }; + } + + @Override + protected Iterable getFakeInput() { + return ComputerSetProcessorUtils.get2DImg(); + } + + @Override + protected void addComputer(final Class clazz) { + for (int order = orderMin; order <= orderMax; order++) { + for (int repetition = 0; repetition <= order; repetition++) { + if (Math.abs(order - repetition) % 2 == 0) { + @SuppressWarnings("unchecked") + final UnaryComputerOp computer = Computers.unary(ops(), clazz, + (Class) outputTypeInstance.getClass(), in(), order, repetition); + final DoubleType output = outputTypeInstance.createVariable(); + namedOutputs.put(getKey(clazz, order, repetition), output); + computer.setOutput(output); + computers.put(clazz, computer); + } + } + } + } + + private String getKey(final Class clazz, final int order, final int repetition) { + return clazz.getSimpleName() + " for Order " + order + " and Repetition " + repetition; + } + + @Override + public String[] getComputerNames() { + final List names = new ArrayList<>(); + for (final Class clazz : getActiveComputers()) { + for (int order = orderMin; order <= orderMax; order++) { + for (int repetition = 0; repetition <= order; repetition++) { + if (Math.abs(order - repetition) % 2 == 0) { + names.add(getKey(clazz, order, repetition)); + } + } + } + } + return names.toArray(new String[names.size()]); + } + +} diff --git a/src/main/java/net/imagej/ops/features/sets/FirstOrderStatsComputerSet.java b/src/main/java/net/imagej/ops/features/sets/FirstOrderStatsComputerSet.java new file mode 100644 index 0000000000..2a359447cf --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/FirstOrderStatsComputerSet.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets; + +import net.imagej.ops.special.computer.Computers; + +/** + * A {@link ComputerSet} which holds all {@link Computers} needed for a First + * Order Statistic analysis. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * input type + * @param + * output type + */ +public interface FirstOrderStatsComputerSet extends ComputerSet { + // NB: marker interface +} diff --git a/src/main/java/net/imagej/ops/features/sets/Geometric2DComputerSet.java b/src/main/java/net/imagej/ops/features/sets/Geometric2DComputerSet.java new file mode 100644 index 0000000000..8a9aa69d61 --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/Geometric2DComputerSet.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets; + +import net.imagej.ops.special.computer.Computers; + +/** + * A {@link ComputerSet} which holds all {@link Computers} needed for the + * analysis of 2D segments. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * input type + * @param + * output type + */ +public interface Geometric2DComputerSet extends ComputerSet { + // NB: Marker Interface +} diff --git a/src/main/java/net/imagej/ops/features/sets/HistogramComputerSet.java b/src/main/java/net/imagej/ops/features/sets/HistogramComputerSet.java new file mode 100644 index 0000000000..4321cce8d7 --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/HistogramComputerSet.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets; + +import net.imagej.ops.special.computer.Computers; + +/** + * A {@link ComputerSet} which holds all {@link Computers} needed for a + * Histogram. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * input type + * @param + * output type + */ +public interface HistogramComputerSet extends ComputerSet { + // NB: Marker Interface +} diff --git a/src/main/java/net/imagej/ops/features/sets/ZernikeComputerSet.java b/src/main/java/net/imagej/ops/features/sets/ZernikeComputerSet.java new file mode 100644 index 0000000000..003d1533ee --- /dev/null +++ b/src/main/java/net/imagej/ops/features/sets/ZernikeComputerSet.java @@ -0,0 +1,47 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets; + +import net.imagej.ops.special.computer.Computers; + +/** + * A {@link ComputerSet} which holds all {@link Computers} needed for a Zernike + * analysis. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + * @param + * input type + * @param + * output type + */ +public interface ZernikeComputerSet extends ComputerSet { + // NB: Marker Interface +} From 88fd7128d3542aa0d7303ddef7103f3d6f82e055 Mon Sep 17 00:00:00 2001 From: tibuch Date: Wed, 1 Mar 2017 15:00:58 +0100 Subject: [PATCH 10/10] Add ComputerSetProcessor tests. --- .../AbstractComputerSetProcessorTest.java | 97 +++++++++++++++ .../ComputerSetProcessorUtilsTest.java | 85 +++++++++++++ .../IterableComputerSetProcessorTest.java | 106 ++++++++++++++++ .../LabelRegionsComputerSetProcessorTest.java | 116 ++++++++++++++++++ .../ROIComputerSetProcessorTest.java | 111 +++++++++++++++++ 5 files changed, 515 insertions(+) create mode 100644 src/test/java/net/imagej/ops/features/sets/processors/AbstractComputerSetProcessorTest.java create mode 100644 src/test/java/net/imagej/ops/features/sets/processors/ComputerSetProcessorUtilsTest.java create mode 100644 src/test/java/net/imagej/ops/features/sets/processors/IterableComputerSetProcessorTest.java create mode 100644 src/test/java/net/imagej/ops/features/sets/processors/LabelRegionsComputerSetProcessorTest.java create mode 100644 src/test/java/net/imagej/ops/features/sets/processors/ROIComputerSetProcessorTest.java diff --git a/src/test/java/net/imagej/ops/features/sets/processors/AbstractComputerSetProcessorTest.java b/src/test/java/net/imagej/ops/features/sets/processors/AbstractComputerSetProcessorTest.java new file mode 100644 index 0000000000..0a435b8850 --- /dev/null +++ b/src/test/java/net/imagej/ops/features/sets/processors/AbstractComputerSetProcessorTest.java @@ -0,0 +1,97 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.List; +import java.util.Map; + +import net.imagej.ops.features.AbstractFeatureTest; +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.table.GenericTable; +import net.imglib2.type.numeric.real.DoubleType; + +import org.junit.Assert; + +/** + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +public abstract class AbstractComputerSetProcessorTest extends AbstractFeatureTest { + + /** + * Check for the correct column names from a start index. If the result + * table was generate based on a labeling, the label would be stored in the + * first column. + * + * Note: No duplicate ComputerSets. + * + * @param result the result table + * @param computerSets the computer sets + * @param startIdx the start index + */ + protected void checkAllResultTableForOneComputerSet(final GenericTable result, + final List> computerSets, final int startIdx) { + String computerSetName = ComputerSetProcessorUtils.getUniqueNames(computerSets).get(computerSets.get(0)); + + String[] names = computerSets.get(0).getComputerNames(); + + for (int i = startIdx; i < result.getColumnCount(); i++) { + String tmpName = computerSetName + "_" + names[i-startIdx]; + Assert.assertTrue("Wrong column order.", tmpName.equals(result.get(i).getHeader())); + } + } + + /** + * Check for the correct column names from a start index. If the result + * table was generate based on a labeling, the label would be stored in the + * first column. + * + * Note: Checks correct column names for duplicate ComputerSets. + * + * @param result the result table + * @param computerSets the computer sets + * @param startIdx the start index + */ + protected void checkResultTableForManyComputerSets(final GenericTable result, + final List> computerSets, final int startIdx) { + Map, String> computerSetNames = ComputerSetProcessorUtils.getUniqueNames(computerSets); + + int i = startIdx; + for (ComputerSet set : computerSets) { + String computerSetName = computerSetNames.get(set); + String[] names = set.getComputerNames(); + for (String s : names) { + String tmpName = computerSetName + "_" + s; + Assert.assertTrue("Wrong column order.", tmpName.equals(result.get(i++).getHeader())); + } + } + } +} diff --git a/src/test/java/net/imagej/ops/features/sets/processors/ComputerSetProcessorUtilsTest.java b/src/test/java/net/imagej/ops/features/sets/processors/ComputerSetProcessorUtilsTest.java new file mode 100644 index 0000000000..303c0029f4 --- /dev/null +++ b/src/test/java/net/imagej/ops/features/sets/processors/ComputerSetProcessorUtilsTest.java @@ -0,0 +1,85 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import net.imagej.ops.AbstractOpTest; +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.FirstOrderStatsComputerSet; +import net.imglib2.type.numeric.real.DoubleType; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Test for the {@link ComputerSetProcessorUtils}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +public class ComputerSetProcessorUtilsTest extends AbstractOpTest { + + @SuppressWarnings({ "cast", "unchecked" }) + @Test + public void uniqueNamesTest() { + List> sets = new ArrayList<>(); + sets.add((FirstOrderStatsComputerSet) ops.op(FirstOrderStatsComputerSet.class, Iterable.class)); + sets.add((FirstOrderStatsComputerSet) ops.op(FirstOrderStatsComputerSet.class, Iterable.class)); + + Map, String> uniqueNames = ComputerSetProcessorUtils.getUniqueNames(sets); + + Collection names = uniqueNames.values(); + Collection copy = new HashSet<>(names); + + for (String s : names) { + copy.remove(s); + Assert.assertTrue("Duplicated name.", !copy.contains(s)); + } + + int i = -1; + for (ComputerSet computerSet : sets) { + if (i == -1) { + Assert.assertTrue("No suffix is needed.", + computerSet.getClass().getSimpleName().equals(uniqueNames.get(computerSet))); + i++; + } else { + String tmp = computerSet.getClass().getSimpleName(); + tmp = tmp + "[" + i + "]"; + Assert.assertTrue("Incorrect suffix.", tmp.equals(uniqueNames.get(computerSet))); + } + } + } + +} diff --git a/src/test/java/net/imagej/ops/features/sets/processors/IterableComputerSetProcessorTest.java b/src/test/java/net/imagej/ops/features/sets/processors/IterableComputerSetProcessorTest.java new file mode 100644 index 0000000000..09a8052234 --- /dev/null +++ b/src/test/java/net/imagej/ops/features/sets/processors/IterableComputerSetProcessorTest.java @@ -0,0 +1,106 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.imagej.ops.Ops.Stats.Max; +import net.imagej.ops.Ops.Stats.Mean; +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.FirstOrderStatsComputerSet; +import net.imagej.ops.features.sets.tables.DefaultComputerSetTableService; +import net.imagej.table.GenericTable; +import net.imglib2.type.numeric.real.DoubleType; +import net.imglib2.type.numeric.real.FloatType; + +import org.junit.Test; + +/** + * Test for the {@link IterableComputerSetProcessor}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +public class IterableComputerSetProcessorTest extends AbstractComputerSetProcessorTest { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void allComputersAreActiveTest() { + FirstOrderStatsComputerSet stats = ops.op(FirstOrderStatsComputerSet.class, + Iterable.class); + + IterableComputerSetProcessor processor = ops.op(IterableComputerSetProcessor.class, + Iterable.class, new ComputerSet[] { stats }, new DefaultComputerSetTableService<>()); + + GenericTable result = processor.calculate(getTestImage2D()); + + List> computerSets = new ArrayList<>(); + computerSets.add(stats); + checkAllResultTableForOneComputerSet(result, computerSets, 0); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void someComputersAreActiveTest() { + FirstOrderStatsComputerSet stats = ops.op(FirstOrderStatsComputerSet.class, + Iterable.class, Arrays.asList(new Class[] { Mean.class, Max.class })); + + IterableComputerSetProcessor processor = ops.op(IterableComputerSetProcessor.class, + Iterable.class, new ComputerSet[] { stats }, new DefaultComputerSetTableService<>()); + + GenericTable result = processor.calculate(getTestImage2D()); + + List> computerSets = new ArrayList<>(); + computerSets.add(stats); + checkAllResultTableForOneComputerSet(result, computerSets, 0); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void multiComputerSetProcessingTest() { + FirstOrderStatsComputerSet stats = ops.op(FirstOrderStatsComputerSet.class, + Iterable.class); + FirstOrderStatsComputerSet stats1 = ops.op(FirstOrderStatsComputerSet.class, + Iterable.class, Arrays.asList(new Class[] { Mean.class, Max.class })); + + IterableComputerSetProcessor processor = ops.op(IterableComputerSetProcessor.class, + Iterable.class, new ComputerSet[] { stats, stats1 }, new DefaultComputerSetTableService<>()); + + final GenericTable result = processor.calculate(getTestImage2D()); + + final List> computerSets = new ArrayList<>(); + computerSets.add(stats); + computerSets.add(stats1); + checkResultTableForManyComputerSets(result, computerSets, 0); + } + +} diff --git a/src/test/java/net/imagej/ops/features/sets/processors/LabelRegionsComputerSetProcessorTest.java b/src/test/java/net/imagej/ops/features/sets/processors/LabelRegionsComputerSetProcessorTest.java new file mode 100644 index 0000000000..47cc8f5e1a --- /dev/null +++ b/src/test/java/net/imagej/ops/features/sets/processors/LabelRegionsComputerSetProcessorTest.java @@ -0,0 +1,116 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.imagej.ops.Ops.Geometric.Circularity; +import net.imagej.ops.Ops.Geometric.Size; +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.Geometric2DComputerSet; +import net.imagej.ops.features.sets.tables.DefaultComputerSetTableService; +import net.imagej.table.GenericTable; +import net.imglib2.roi.geometric.Polygon; +import net.imglib2.roi.labeling.LabelRegions; +import net.imglib2.type.numeric.real.DoubleType; + +import org.junit.Before; +import org.junit.Test; + +/** + * Test for the {@link LabelRegionsComputerSetProcessor}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +public class LabelRegionsComputerSetProcessorTest extends AbstractComputerSetProcessorTest { + + private LabelRegions roi; + + @Before + public void createROI() { + roi = createLabelRegions(getTestImage2D(), 1, 255); + } + + @SuppressWarnings("unchecked") + @Test + public void allComputersAreActiveTest() { + Geometric2DComputerSet geom = ops.op(Geometric2DComputerSet.class, Polygon.class); + + LabelRegionsComputerSetProcessor processor = ops.op( + LabelRegionsComputerSetProcessor.class, LabelRegions.class, new ComputerSet[] { geom }, + new DefaultComputerSetTableService<>()); + + GenericTable result = processor.calculate(roi); + + List> computerSets = new ArrayList<>(); + computerSets.add(geom); + checkAllResultTableForOneComputerSet(result, computerSets, 1); + } + + @SuppressWarnings({ "unchecked" }) + @Test + public void somecomputersAreActiveTest() { + Geometric2DComputerSet geom = ops.op(Geometric2DComputerSet.class, Polygon.class, + Arrays.asList(new Class[] { Circularity.class, Size.class })); + + LabelRegionsComputerSetProcessor processor = ops.op( + LabelRegionsComputerSetProcessor.class, LabelRegions.class, new ComputerSet[] { geom }, + new DefaultComputerSetTableService<>()); + + GenericTable result = processor.calculate(roi); + + List> computerSets = new ArrayList<>(); + computerSets.add(geom); + checkAllResultTableForOneComputerSet(result, computerSets, 1); + } + + @SuppressWarnings({ "unchecked" }) + @Test + public void mutliComputerSetProcessingTest() { + Geometric2DComputerSet geom = ops.op(Geometric2DComputerSet.class, Polygon.class); + Geometric2DComputerSet geom1 = ops.op(Geometric2DComputerSet.class, Polygon.class, + Arrays.asList(new Class[] { Circularity.class, Size.class })); + + LabelRegionsComputerSetProcessor processor = ops.op( + LabelRegionsComputerSetProcessor.class, LabelRegions.class, new ComputerSet[] { geom, geom1 }, + new DefaultComputerSetTableService<>()); + + GenericTable result = processor.calculate(roi); + + List> computerSets = new ArrayList<>(); + computerSets.add(geom); + computerSets.add(geom1); + checkResultTableForManyComputerSets(result, computerSets, 1); + } + +} diff --git a/src/test/java/net/imagej/ops/features/sets/processors/ROIComputerSetProcessorTest.java b/src/test/java/net/imagej/ops/features/sets/processors/ROIComputerSetProcessorTest.java new file mode 100644 index 0000000000..2f3b21faf6 --- /dev/null +++ b/src/test/java/net/imagej/ops/features/sets/processors/ROIComputerSetProcessorTest.java @@ -0,0 +1,111 @@ +/* + * #%L + * ImageJ software for multidimensional image processing and analysis. + * %% + * Copyright (C) 2014 - 2016 Board of Regents of the University of + * Wisconsin-Madison, University of Konstanz and Brian Northan. + * %% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * #L% + */ +package net.imagej.ops.features.sets.processors; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import net.imagej.ops.Ops.Stats.Max; +import net.imagej.ops.Ops.Stats.Mean; +import net.imagej.ops.features.sets.ComputerSet; +import net.imagej.ops.features.sets.FirstOrderStatsComputerSet; +import net.imagej.ops.features.sets.tables.DefaultComputerSetTableService; +import net.imagej.table.GenericTable; +import net.imglib2.RandomAccessible; +import net.imglib2.roi.labeling.LabelRegions; +import net.imglib2.type.numeric.real.DoubleType; +import net.imglib2.type.numeric.real.FloatType; + +import org.junit.Test; + +/** + * Test for the {@link ROIComputerSetProcessor}. + * + * @author Tim-Oliver Buchholz, University of Konstanz + * + */ +public class ROIComputerSetProcessorTest extends AbstractComputerSetProcessorTest { + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void allComputersAreActiveTest() { + FirstOrderStatsComputerSet stats = ops.op(FirstOrderStatsComputerSet.class, + Iterable.class); + + ROIComputerSetProcessor processor = ops.op(ROIComputerSetProcessor.class, + RandomAccessible.class, LabelRegions.class, new ComputerSet[] { stats }, + new DefaultComputerSetTableService<>()); + + GenericTable result = processor.calculate(getTestImage2D(), createLabelRegions(getTestImage2D(), 1, 255)); + + List> computerSets = new ArrayList<>(); + computerSets.add(stats); + checkAllResultTableForOneComputerSet(result, computerSets, 1); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void someComputersAreActiveTest() { + FirstOrderStatsComputerSet stats = ops.op(FirstOrderStatsComputerSet.class, + Iterable.class, Arrays.asList(new Class[] { Mean.class, Max.class })); + + ROIComputerSetProcessor processor = ops.op(ROIComputerSetProcessor.class, + RandomAccessible.class, LabelRegions.class, new ComputerSet[] { stats }, + new DefaultComputerSetTableService<>()); + + GenericTable result = processor.calculate(getTestImage2D(), createLabelRegions(getTestImage2D(), 1, 255)); + + List> computerSets = new ArrayList<>(); + computerSets.add(stats); + checkAllResultTableForOneComputerSet(result, computerSets, 1); + } + + @SuppressWarnings({ "rawtypes", "unchecked" }) + @Test + public void multiComputerSetProcessingTest() { + FirstOrderStatsComputerSet stats = ops.op(FirstOrderStatsComputerSet.class, + Iterable.class); + FirstOrderStatsComputerSet stats1 = ops.op(FirstOrderStatsComputerSet.class, + Iterable.class, Arrays.asList(new Class[] { Mean.class, Max.class })); + + ROIComputerSetProcessor processor = ops.op(ROIComputerSetProcessor.class, + RandomAccessible.class, LabelRegions.class, new ComputerSet[] { stats, stats1 }, + new DefaultComputerSetTableService<>()); + + GenericTable result = processor.calculate(getTestImage2D(), createLabelRegions(getTestImage2D(), 1, 255)); + + List> computerSets = new ArrayList<>(); + computerSets.add(stats); + computerSets.add(stats1); + checkResultTableForManyComputerSets(result, computerSets, 1); + } + +}