|
| 1 | +package net.imglib2.algorithm.convolution.kernel; |
| 2 | + |
| 3 | +import static org.junit.Assert.assertArrayEquals; |
| 4 | + |
| 5 | +import net.imglib2.img.array.ArrayImgs; |
| 6 | +import net.imglib2.type.numeric.real.DoubleType; |
| 7 | + |
| 8 | +import org.junit.Test; |
| 9 | + |
| 10 | +/** |
| 11 | + * @author Tobias Pietzsch |
| 12 | + */ |
| 13 | +public class ConvolverTest |
| 14 | +{ |
| 15 | + private final double[] kernel = { 1.0, 2.0, 3.0, 4.0 }; |
| 16 | + private final int center = 2; |
| 17 | + |
| 18 | + private final double[] in = { 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0 }; |
| 19 | + |
| 20 | + @Test |
| 21 | + public void testConvolverNativeType() |
| 22 | + { |
| 23 | + final double[] out = new double[ kernel.length ]; |
| 24 | + final ConvolverNativeType< DoubleType > convolver = new ConvolverNativeType<>( |
| 25 | + Kernel1D.asymmetric( kernel, center ), |
| 26 | + ArrayImgs.doubles( in, in.length ).randomAccess(), |
| 27 | + ArrayImgs.doubles( out, out.length ).randomAccess(), |
| 28 | + 0, |
| 29 | + out.length ); |
| 30 | + convolver.run(); |
| 31 | + assertArrayEquals( kernel, out, 0 ); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + public void testConvolverNumericType() |
| 36 | + { |
| 37 | + final double[] out = new double[ kernel.length ]; |
| 38 | + final ConvolverNumericType< DoubleType > convolver = new ConvolverNumericType<>( |
| 39 | + Kernel1D.asymmetric( kernel, center ), |
| 40 | + ArrayImgs.doubles( in, in.length ).randomAccess(), |
| 41 | + ArrayImgs.doubles( out, out.length ).randomAccess(), |
| 42 | + 0, |
| 43 | + out.length ); |
| 44 | + convolver.run(); |
| 45 | + assertArrayEquals( kernel, out, 0 ); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testDoubleConvolverRealType() |
| 50 | + { |
| 51 | + final double[] out = new double[ kernel.length ]; |
| 52 | + final DoubleConvolverRealType convolver = new DoubleConvolverRealType( |
| 53 | + Kernel1D.asymmetric( kernel, center ), |
| 54 | + ArrayImgs.doubles( in, in.length ).randomAccess(), |
| 55 | + ArrayImgs.doubles( out, out.length ).randomAccess(), |
| 56 | + 0, |
| 57 | + out.length ); |
| 58 | + convolver.run(); |
| 59 | + assertArrayEquals( kernel, out, 0 ); |
| 60 | + } |
| 61 | + |
| 62 | + @Test |
| 63 | + public void testFloatConvolverRealType() |
| 64 | + { |
| 65 | + final double[] out = new double[ kernel.length ]; |
| 66 | + final FloatConvolverRealType convolver = new FloatConvolverRealType( |
| 67 | + Kernel1D.asymmetric( kernel, center ), |
| 68 | + ArrayImgs.doubles( in, in.length ).randomAccess(), |
| 69 | + ArrayImgs.doubles( out, out.length ).randomAccess(), |
| 70 | + 0, |
| 71 | + out.length ); |
| 72 | + convolver.run(); |
| 73 | + assertArrayEquals( kernel, out, 0 ); |
| 74 | + } |
| 75 | +} |
0 commit comments