Skip to content

Commit d20fb73

Browse files
committed
Restrict SimpleConvolveNaiveF output to FloatType
The output type was vacuous, let's make it a FloatType.
1 parent 80c4afc commit d20fb73

1 file changed

Lines changed: 7 additions & 34 deletions

File tree

scijava-ops-image/src/main/java/org/scijava/ops/image/filter/convolve/ConvolveNaiveF.java

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,33 +61,6 @@ public class ConvolveNaiveF<I extends RealType<I>, O extends RealType<O> & Nativ
6161
@OpDependency(name = "create.img")
6262
private BiFunction<Dimensions, O, RandomAccessibleInterval<O>> createOp;
6363

64-
/**
65-
* Create the output using the outFactory and outType if they exist. If these
66-
* are null use a default factory and type
67-
*/
68-
@SuppressWarnings("unchecked")
69-
public RandomAccessibleInterval<O> createOutput(RandomAccessibleInterval<I> input,
70-
RandomAccessibleInterval<K> kernel, O outType) {
71-
72-
// TODO can we remove this null check?
73-
if (outType == null) {
74-
75-
// if the input type and kernel type are the same use this type
76-
if (Util.getTypeFromInterval(input).getClass() == Util.getTypeFromInterval(kernel).getClass()) {
77-
Object temp = Util.getTypeFromInterval(input).createVariable();
78-
outType = (O) temp;
79-
80-
}
81-
// otherwise default to float
82-
else {
83-
Object temp = new FloatType();
84-
outType = (O) temp;
85-
}
86-
}
87-
88-
return createOp.apply(input, outType.createVariable());
89-
}
90-
9164
/**
9265
* TODO
9366
*
@@ -106,7 +79,7 @@ public RandomAccessibleInterval<O> apply(final RandomAccessibleInterval<I> input
10679
if (Intervals.numElements(kernel) <= 9)
10780
throw new IllegalArgumentException("The kernel is too small to perform computation!");
10881

109-
RandomAccessibleInterval<O> out = createOutput(input, kernel, outType);
82+
RandomAccessibleInterval<O> out = createOp.apply(input, outType);
11083

11184
if (obf == null) {
11285
obf = new OutOfBoundsConstantValueFactory<>(Util.getTypeFromInterval(input).createVariable());
@@ -130,18 +103,18 @@ public RandomAccessibleInterval<O> apply(final RandomAccessibleInterval<I> input
130103
}
131104

132105
/**
106+
* A convenience Op enabling output type safety.
133107
*
134108
* @param <I>
135-
* @param <O>
136109
* @param <K>
137110
* @implNote op name='filter.convolve', priority='101.'
138111
*/
139-
class SimpleConvolveNaiveF<I extends RealType<I>, O extends RealType<O> & NativeType<O>, K extends RealType<K>>
112+
class SimpleConvolveNaiveF<I extends RealType<I>, K extends RealType<K>>
140113
implements
141-
BiFunction<RandomAccessibleInterval<I>, RandomAccessibleInterval<K>, RandomAccessibleInterval<O>> {
114+
BiFunction<RandomAccessibleInterval<I>, RandomAccessibleInterval<K>, RandomAccessibleInterval<FloatType>> {
142115

143116
@OpDependency(name = "filter.convolve")
144-
Functions.Arity4<RandomAccessibleInterval<I>, RandomAccessibleInterval<K>, OutOfBoundsFactory<I, RandomAccessibleInterval<I>>, O, RandomAccessibleInterval<O>> convolveOp;
117+
Functions.Arity3<RandomAccessibleInterval<I>, RandomAccessibleInterval<K>, FloatType, RandomAccessibleInterval<FloatType>> convolveOp;
145118

146119
/**
147120
* TODO
@@ -151,7 +124,7 @@ class SimpleConvolveNaiveF<I extends RealType<I>, O extends RealType<O> & Native
151124
* @return the output
152125
*/
153126
@Override
154-
public RandomAccessibleInterval<O> apply(RandomAccessibleInterval<I> input, RandomAccessibleInterval<K> kernel) {
155-
return convolveOp.apply(input, kernel, null, null);
127+
public RandomAccessibleInterval<FloatType> apply(RandomAccessibleInterval<I> input, RandomAccessibleInterval<K> kernel) {
128+
return convolveOp.apply(input, kernel, new FloatType());
156129
}
157130
}

0 commit comments

Comments
 (0)