Skip to content

Commit edefad2

Browse files
committed
Further cleanup
1 parent d061c4d commit edefad2

File tree

3 files changed

+36
-75
lines changed

3 files changed

+36
-75
lines changed

scijava-ops-image/src/main/java/org/scijava/ops/image/threshold/AbstractApplyThresholdImg.java

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,48 @@
4141
import org.scijava.ops.spi.OpDependency;
4242

4343
/**
44+
* An abstract base class for Ops using a {@link Histogram1d} to compute a
45+
* threshold across an {@link Iterable}.
46+
* <p>
47+
* Note the use of type parameters {@code I} and {@code J}, allowing
48+
* dependencies to be matched on the concrete input types instead of just on
49+
* {@link Iterable}
50+
* </p>
51+
*
4452
* @author Curtis Rueden
4553
* @author Christian Dietz (University of Konstanz)
54+
* @author Gabriel Selzer
55+
* @param <T> the {@link RealType} implementation of input elements
56+
* @param <I> the {@link Iterable} subclass of the input
57+
* @param <J> the {@link Iterable} subclass of the output
4658
*/
47-
public abstract class AbstractApplyThresholdImg<T extends RealType<T>, I extends Iterable<T>, J extends Iterable<BitType>> extends
48-
AbstractApplyThresholdIterable<T, I, J>
49-
{
59+
public abstract class AbstractApplyThresholdImg< //
60+
T extends RealType<T>, //
61+
I extends Iterable<T>, //
62+
J extends Iterable<BitType> //
63+
> implements Computers.Arity1<I, J> {
5064

5165
@OpDependency(name = "image.histogram")
5266
private Function<I, Histogram1d<T>> createHistogramOp;
5367

68+
@OpDependency(name = "threshold.apply")
69+
private Computers.Arity2<I, T, J> applyThresholdOp;
70+
71+
/**
72+
* Thresholds {@code input}, storing the result in {@code output}.
73+
*
74+
* @param input the input dataset
75+
* @param output the output dataset
76+
*/
5477
@Override
55-
protected T computeThreshold(final I input) {
78+
public void compute(final I input, final J output) {
79+
// Compute the histogram
5680
final var inputHistogram = createHistogramOp.apply(input);
81+
// Compute the threshold value from the histogram
5782
final var threshold = input.iterator().next().createVariable();
58-
final var computeThresholdOp =
59-
getComputeThresholdOp();
60-
computeThresholdOp.compute(inputHistogram, threshold);
61-
return threshold;
83+
getComputeThresholdOp().compute(inputHistogram, threshold);
84+
// Threshold the image against the computed value
85+
applyThresholdOp.compute(input, threshold, output);
6286
}
6387

6488
protected abstract Computers.Arity1<Histogram1d<T>, T>

scijava-ops-image/src/main/java/org/scijava/ops/image/threshold/AbstractApplyThresholdIterable.java

Lines changed: 0 additions & 61 deletions
This file was deleted.

scijava-ops-image/src/test/java/org/scijava/ops/image/threshold/apply/ApplyManualThresholdTest.java renamed to scijava-ops-image/src/test/java/org/scijava/ops/image/threshold/apply/ApplyConstantThresholdTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,19 @@
3737
import net.imglib2.RandomAccessibleInterval;
3838
import org.scijava.ops.image.threshold.AbstractThresholdTest;
3939
import net.imglib2.exception.IncompatibleTypeException;
40-
import net.imglib2.img.Img;
4140
import net.imglib2.type.logic.BitType;
4241
import net.imglib2.type.numeric.integer.UnsignedShortType;
4342

4443
import org.junit.jupiter.api.Test;
45-
import org.scijava.function.Computers;
46-
import org.scijava.ops.api.OpBuilder;
4744
import org.scijava.types.Nil;
4845

4946
/**
50-
* Tests {@link ApplyManualThreshold}.
47+
* Tests {@link ApplyConstantThreshold} and its wrappers.
5148
*
5249
* @author Curtis Rueden
50+
* @author Gabriel Selzer
5351
*/
54-
public class ApplyManualThresholdTest extends AbstractThresholdTest {
52+
public class ApplyConstantThresholdTest extends AbstractThresholdTest {
5553

5654
@Test
5755
public void testApplyThreshold() throws IncompatibleTypeException {
@@ -73,7 +71,7 @@ public void testApplyThresholdRAIs() {
7371
@Test
7472
public void testApplyThresholdIterables() {
7573
List<UnsignedShortType> itr = in.stream().collect(Collectors.toList());
76-
List<UnsignedShortType> output = new ArrayList<UnsignedShortType>(itr.size());
74+
List<UnsignedShortType> output = new ArrayList<>(itr.size());
7775

7876
ops.op("threshold.mean") //
7977
.input(in) //

0 commit comments

Comments
 (0)