Skip to content

Commit ad83c3a

Browse files
committed
Further cleanup
1 parent d061c4d commit ad83c3a

3 files changed

Lines changed: 48 additions & 78 deletions

File tree

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: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@
3535
import java.util.stream.Collectors;
3636

3737
import net.imglib2.RandomAccessibleInterval;
38+
import org.junit.jupiter.api.Assertions;
39+
import org.scijava.ops.api.OpMatchingException;
3840
import org.scijava.ops.image.threshold.AbstractThresholdTest;
3941
import net.imglib2.exception.IncompatibleTypeException;
40-
import net.imglib2.img.Img;
4142
import net.imglib2.type.logic.BitType;
4243
import net.imglib2.type.numeric.integer.UnsignedShortType;
4344

4445
import org.junit.jupiter.api.Test;
45-
import org.scijava.function.Computers;
46-
import org.scijava.ops.api.OpBuilder;
4746
import org.scijava.types.Nil;
4847

4948
/**
50-
* Tests {@link ApplyManualThreshold}.
49+
* Tests {@link ApplyConstantThreshold} and its wrappers.
5150
*
5251
* @author Curtis Rueden
52+
* @author Gabriel Selzer
5353
*/
54-
public class ApplyManualThresholdTest extends AbstractThresholdTest {
54+
public class ApplyConstantThresholdTest extends AbstractThresholdTest {
5555

5656
@Test
5757
public void testApplyThreshold() throws IncompatibleTypeException {
@@ -65,15 +65,22 @@ public void testApplyThreshold() throws IncompatibleTypeException {
6565

6666
@Test
6767
public void testApplyThresholdRAIs() {
68-
ops.op("threshold.mean") //
68+
// Test as Computer
69+
final var buffer = bitmap();
70+
Assertions.assertDoesNotThrow(() -> ops.op("threshold.mean") //
71+
.input(in) //
72+
.output(buffer) //
73+
.compute());
74+
// Test as Function
75+
Assertions.assertDoesNotThrow(() -> ops.op("threshold.mean") //
6976
.input(in) //
70-
.outType(new Nil<RandomAccessibleInterval<BitType>>() {}) //
71-
.apply();
77+
.apply());
7278
}
79+
7380
@Test
7481
public void testApplyThresholdIterables() {
7582
List<UnsignedShortType> itr = in.stream().collect(Collectors.toList());
76-
List<UnsignedShortType> output = new ArrayList<UnsignedShortType>(itr.size());
83+
List<UnsignedShortType> output = new ArrayList<>(itr.size());
7784

7885
ops.op("threshold.mean") //
7986
.input(in) //

0 commit comments

Comments
 (0)