|
| 1 | + |
| 2 | +package net.imagej.ops.transform.realTransform; |
| 3 | + |
| 4 | +import static org.junit.Assert.assertEquals; |
| 5 | + |
| 6 | +import net.imagej.ops.AbstractOpTest; |
| 7 | +import net.imglib2.Cursor; |
| 8 | +import net.imglib2.RandomAccess; |
| 9 | +import net.imglib2.RandomAccessibleInterval; |
| 10 | +import net.imglib2.img.Img; |
| 11 | +import net.imglib2.interpolation.randomaccess.LanczosInterpolatorFactory; |
| 12 | +import net.imglib2.realtransform.AffineTransform2D; |
| 13 | +import net.imglib2.type.numeric.integer.UnsignedByteType; |
| 14 | +import net.imglib2.view.Views; |
| 15 | + |
| 16 | +import org.junit.Test; |
| 17 | + |
| 18 | +public class RealTransformTest extends AbstractOpTest { |
| 19 | + |
| 20 | + @Test |
| 21 | + public void regressionTest() throws Exception { |
| 22 | + |
| 23 | + Img<UnsignedByteType> image = (Img<UnsignedByteType>) this |
| 24 | + .openUnsignedByteType(getClass(), "lowresbridge.tif"); |
| 25 | + Img<UnsignedByteType> expectedOutput = (Img<UnsignedByteType>) this |
| 26 | + .openUnsignedByteType(getClass(), "rotatedscaledcenter.tif"); |
| 27 | + |
| 28 | + AffineTransform2D transform = new AffineTransform2D(); |
| 29 | + |
| 30 | + transform.translate(-image.dimension(0)/2,-image.dimension(0)/2); |
| 31 | + transform.rotate(1); |
| 32 | + transform.scale(0.5); |
| 33 | + transform.translate(image.dimension(0)/2,image.dimension(0)/2); |
| 34 | + |
| 35 | + RandomAccessibleInterval<UnsignedByteType> actualOutput=ops.transform().realTransform(image, transform); |
| 36 | + |
| 37 | + // compare the output image data to that stored in the file. |
| 38 | + Cursor<UnsignedByteType> cursor = Views.iterable(actualOutput) |
| 39 | + .localizingCursor(); |
| 40 | + RandomAccess<UnsignedByteType> actualRA = actualOutput.randomAccess(); |
| 41 | + RandomAccess<UnsignedByteType> expectedRA = expectedOutput.randomAccess(); |
| 42 | + |
| 43 | + while (cursor.hasNext()) { |
| 44 | + cursor.fwd(); |
| 45 | + actualRA.setPosition(cursor); |
| 46 | + expectedRA.setPosition(cursor); |
| 47 | + assertEquals(expectedRA.get().get(), actualRA.get().get(), 0); |
| 48 | + } |
| 49 | + |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments