|
41 | 41 | import org.scijava.ops.spi.OpDependency; |
42 | 42 |
|
43 | 43 | /** |
| 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 | + * |
44 | 52 | * @author Curtis Rueden |
45 | 53 | * @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 |
46 | 58 | */ |
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> { |
50 | 64 |
|
51 | 65 | @OpDependency(name = "image.histogram") |
52 | 66 | private Function<I, Histogram1d<T>> createHistogramOp; |
53 | 67 |
|
| 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 | + */ |
54 | 77 | @Override |
55 | | - protected T computeThreshold(final I input) { |
| 78 | + public void compute(final I input, final J output) { |
| 79 | + // Compute the histogram |
56 | 80 | final var inputHistogram = createHistogramOp.apply(input); |
| 81 | + // Compute the threshold value from the histogram |
57 | 82 | 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); |
62 | 86 | } |
63 | 87 |
|
64 | 88 | protected abstract Computers.Arity1<Histogram1d<T>, T> |
|
0 commit comments