Skip to content

Commit bf87bdf

Browse files
committed
Preserve differentiation in summation from plugin
1 parent cbebe43 commit bf87bdf

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/main/java/net/imagej/ops/filter/sharpen/DefaultSharpen.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.imglib2.algorithm.neighborhood.RectangleNeighborhood;
1515
import net.imglib2.algorithm.neighborhood.RectangleNeighborhoodFactory;
1616
import net.imglib2.algorithm.neighborhood.RectangleShape.NeighborhoodsAccessible;
17+
import net.imglib2.type.numeric.IntegerType;
1718
import net.imglib2.type.numeric.RealType;
1819
import net.imglib2.util.Util;
1920
import net.imglib2.view.Views;
@@ -119,8 +120,15 @@ private void computePlanar(final Position planePos,
119120
for (int i = 0; i < kernel.length; i++) {
120121
sum += kernel[i] * n[i];
121122
}
122-
123-
double value = sum / scale;
123+
124+
//find the value for the output
125+
double value;
126+
if(type instanceof IntegerType) {
127+
value = (sum + scale / 2) / scale;
128+
}
129+
else {
130+
value = sum / scale;
131+
}
124132

125133
outputRA.setPosition(cursor.getLongPosition(0), 0);
126134
outputRA.setPosition(cursor.getLongPosition(1), 1);

src/main/java/net/imagej/ops/filter/smooth/DefaultSmooth.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.imglib2.algorithm.neighborhood.RectangleNeighborhood;
1515
import net.imglib2.algorithm.neighborhood.RectangleNeighborhoodFactory;
1616
import net.imglib2.algorithm.neighborhood.RectangleShape.NeighborhoodsAccessible;
17+
import net.imglib2.type.numeric.IntegerType;
1718
import net.imglib2.type.numeric.RealType;
1819
import net.imglib2.util.Util;
1920
import net.imglib2.view.Views;
@@ -119,7 +120,14 @@ private void computePlanar(final Position planePos,
119120
sum += kernel[i] * n[i];
120121
}
121122

122-
double value = sum / scale;
123+
//find the value for the output
124+
double value;
125+
if(type instanceof IntegerType) {
126+
value = (sum + scale / 2) / scale;
127+
}
128+
else {
129+
value = sum / scale;
130+
}
123131

124132
outputRA.setPosition(cursor.getLongPosition(0), 0);
125133
outputRA.setPosition(cursor.getLongPosition(1), 1);

0 commit comments

Comments
 (0)