use of net.imglib2.Cursor in project imagej-ops by imagej.
the class SubsampleViewTest method defaultSubsampleStepsTest.
@Test
public void defaultSubsampleStepsTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
Random r = new Random();
for (DoubleType d : img) {
d.set(r.nextDouble());
}
SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2, 1);
SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2, 1);
Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor();
RandomAccess<DoubleType> oprRA = opr.randomAccess();
while (il2C.hasNext()) {
il2C.next();
oprRA.setPosition(il2C);
assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
}
}
use of net.imglib2.Cursor in project imagej-ops by imagej.
the class UnshearViewTest method defaultUnshearTest.
@Test
public void defaultUnshearTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
Cursor<DoubleType> imgC = img.cursor();
while (imgC.hasNext()) {
imgC.next().set(1);
}
TransformView<DoubleType> il2 = Views.unshear(Views.shear(Views.extendZero(img), 0, 1), 0, 1);
TransformView<DoubleType> opr = ops.transform().unshearView(Views.shear(Views.extendZero(img), 0, 1), 0, 1);
Cursor<DoubleType> il2C = Views.interval(il2, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })).cursor();
RandomAccess<DoubleType> oprRA = Views.interval(opr, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })).randomAccess();
while (il2C.hasNext()) {
il2C.next();
oprRA.setPosition(il2C);
assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
}
}
use of net.imglib2.Cursor in project imagej-ops by imagej.
the class UnshearViewTest method UnshearIntervalTest.
@Test
public void UnshearIntervalTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
Cursor<DoubleType> imgC = img.cursor();
while (imgC.hasNext()) {
imgC.next().set(1);
}
Cursor<DoubleType> il2 = Views.unshear(Views.shear(Views.extendZero(img), 0, 1), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1).cursor();
RandomAccess<DoubleType> opr = ops.transform().unshearView(Views.shear(Views.extendZero(img), 0, 1), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1).randomAccess();
while (il2.hasNext()) {
il2.next();
opr.setPosition(il2);
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
}
use of net.imglib2.Cursor in project imagej-ops by imagej.
the class PartialDerivativeFilterTest method testAllDerivatives.
@Test
public void testAllDerivatives() {
Img<FloatType> img = generateFloatArrayTestImg(false, new long[] { 20, 20, 3 });
Cursor<FloatType> cursorImg = img.cursor();
int counterX = 0;
int counterY = 0;
while (cursorImg.hasNext()) {
if (counterX > 8 && counterX < 12 || counterY > 8 && counterY < 12) {
cursorImg.next().setOne();
} else {
cursorImg.next().setZero();
}
counterX++;
if (counterX % 20 == 0) {
counterY++;
}
if (counterX == 20) {
counterX = 0;
}
if (counterY == 20) {
counterY = 0;
}
}
CompositeIntervalView<FloatType, RealComposite<FloatType>> out = ops.filter().allPartialDerivatives(img);
CompositeView<FloatType, RealComposite<FloatType>>.CompositeRandomAccess outRA = out.randomAccess();
FloatType type = Util.getTypeFromInterval(img).createVariable();
// position 9,8 in all dimensions
outRA.setPosition(new int[] { 9, 8, 0 });
RealComposite<FloatType> outvalue = outRA.get();
Float[] correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
int i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 8, 1 });
outvalue = outRA.get();
correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 8, 2 });
outvalue = outRA.get();
correctValues = new Float[] { 12.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
// position 9,9 in all dimensions
outRA.setPosition(new int[] { 9, 9, 0 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 9, 1 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 9, 2 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, 4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
// position 9,10 in all dimensions
outRA.setPosition(new int[] { 9, 10, 0 });
outvalue = outRA.get();
correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 10, 1 });
outvalue = outRA.get();
correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 10, 2 });
outvalue = outRA.get();
correctValues = new Float[] { 0.0f, 0.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
// position 9,11 in all dimensions
outRA.setPosition(new int[] { 9, 11, 0 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 11, 1 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
outRA.setPosition(new int[] { 9, 11, 2 });
outvalue = outRA.get();
correctValues = new Float[] { 4.0f, -4.0f, 0.0f };
i = 0;
for (FloatType value : outvalue) {
type.set(correctValues[i]);
assertEquals(type, value);
i++;
}
}
use of net.imglib2.Cursor in project imagej-ops by imagej.
the class ColocalisationTest method loadTiffFromJar.
/**
* Loads a Tiff file from within the jar to use as a mask Cursor.
* So we use Img<T> which has a cursor() method.
* The given path is treated
* as relative to this tests-package (i.e. "Data/test.tiff" refers
* to the test.tiff in sub-folder Data).
*
* @param <T> The wanted output type.
* @param relPath The relative path to the Tiff file.
* @return The file as ImgLib image.
*/
private <T extends RealType<T> & NativeType<T>> Img<T> loadTiffFromJar(final String relPath) {
// InputStream is = TestImageAccessor.class.getResourceAsStream(relPath);
// BufferedInputStream bis = new BufferedInputStream(is);
final ImgOpener opener = new ImgOpener(context);
// HACK: Read data from file system for now.
// Until this is fixed, the test will not pass when run from a JAR file.
String source = "src/test/resources/net/imagej/ops/coloc/" + relPath;
try {
return (Img) opener.openImgs(source).get(0);
} catch (final ImgIOException exc) {
throw new IllegalStateException("File " + relPath + " is unexpectedly inaccessible?");
}
}
Aggregations