net.imglib2.view.IntervalView Java Examples

The following examples show how to use net.imglib2.view.IntervalView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TranslateViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalTranslate() {
	Img<DoubleType> img = ArrayImgs.doubles(10,10);

	IntervalView<DoubleType> expected = Views.translate(img, 2, 5);
	IntervalView<DoubleType> actual = ops.transform().translateView(img, 2, 5);

	for (int i = 0; i < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix().length; i++) {
		for (int j = 0; j < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i].length; j++) {
			assertEquals(((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i][j], ((MixedTransformView<DoubleType>) actual.getSource()).getTransformToSource().getMatrix()[i][j],
					1e-10);
		}
	}
	
	assertTrue(Intervals.equals(expected, actual));
}
 
Example #2
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test box counting with a hyper cube and one grid translation (should find a
 * better fit than in @see {@link #testHyperCube()})
 */
@Test
public void testHyperCubeTranslations() {
	final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log(
		i)).toArray();
	final double[] expectedCounts = DoubleStream.of(1, 1, 16).map(Math::log)
		.toArray();
	final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4);
	final IntervalView<BitType> hyperView = Views.offsetInterval(img,
		new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 });
	hyperView.forEach(BitType::setOne);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, 4L, 1L, 2.0, 1L);

	// VERIFY
	for (int i = 0; i < expectedSizes.length; i++) {
		assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12);
		assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
	}
}
 
Example #3
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testHyperCube() {
	// SETUP
	final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log(
		i)).toArray();
	final double[] expectedCounts = DoubleStream.of(1, 16, 16).map(Math::log)
		.toArray();
	final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4);
	final IntervalView<BitType> hyperView = Views.offsetInterval(img,
		new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 });
	hyperView.forEach(BitType::setOne);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
		.boxCount(img, 4L, 1L, 2.0);

	// VERIFY
	for (int i = 0; i < expectedSizes.length; i++) {
		assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12);
		assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
	}
}
 
Example #4
Source File: CopyRAITest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void copyRAIDifferentSizeTest() {

	// create a copy op
	final UnaryHybridCF<IntervalView<UnsignedByteType>, RandomAccessibleInterval<UnsignedByteType>> copy =
		(UnaryHybridCF) Hybrids.unaryCF(ops, CopyRAI.class,
			RandomAccessibleInterval.class, IntervalView.class);

	assertNotNull(copy);

	final Img<UnsignedByteType> out = ops.create().img(new FinalDimensions(
		size2), new UnsignedByteType());

	// copy view to output and assert that is equal to the mean of the view
	copy.compute(view, out);
	assertEquals(ops.stats().mean(out).getRealDouble(), 100.0, delta);

	// also try with a planar image
	final Img<UnsignedByteType> outFromPlanar = ops.create().img(
		new FinalDimensions(size2), new UnsignedByteType());

	copy.compute(viewPlanar, outFromPlanar);
	assertEquals(ops.stats().mean(outFromPlanar).getRealDouble(), 100.0, delta);

}
 
Example #5
Source File: FrangiVesselness.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void run() {
	// parse the spacing, and scales strings.
	spacing = checkDimensions(spacingString, input.numDimensions(), "Spacings");
	scales = Arrays.stream(scaleString.split(regex)).mapToInt(Integer::parseInt)
		.toArray();
	Dimensions resultDims = Views.addDimension(input, 0, scales.length - 1);
	// create output image, potentially-filtered input
	result = opService.create().img(resultDims, new FloatType());

	for (int s = 0; s < scales.length; s++) {
		// Determine whether or not the user would like to apply the gaussian
		// beforehand and do it.
		RandomAccessibleInterval<T> vesselnessInput = doGauss ? opService.filter()
			.gauss(input, scales[s]) : input;
		IntervalView<FloatType> scaleResult = Views.hyperSlice(result, result
			.numDimensions() - 1, s);
		opService.filter().frangiVesselness(scaleResult, vesselnessInput, spacing,
			scales[s]);
	}
}
 
Example #6
Source File: CropRAI.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public RandomAccessibleInterval<T> calculate(final RandomAccessibleInterval<T> input, final Interval interval) {
	boolean oneSizedDims = false;

	if (dropSingleDimensions) {
		for (int d = 0; d < interval.numDimensions(); d++) {
			if (interval.dimension(d) == 1) {
				oneSizedDims = true;
				break;
			}
		}
	}

	if (Intervals.equals(input, interval) && !oneSizedDims)
		return input;
	if (!Intervals.contains(input, interval))
		throw new RuntimeException("Intervals don't match!");
	IntervalView<T> res = Views.offsetInterval(input, interval);
	return oneSizedDims ? Views.dropSingletonDimensions(res) : res;
}
 
Example #7
Source File: CreateImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testCreateFromRaiDifferentType() {
	final IntervalView<ByteType> input =
		Views.interval(PlanarImgs.bytes(10, 10, 10), new FinalInterval(
			new long[] { 10, 10, 1 }));

	final Img<?> res = (Img<?>) ops.run(CreateImgFromDimsAndType.class, input,
		new ShortType());

	assertEquals("Image Type: ", ShortType.class, res.firstElement().getClass());

	assertArrayEquals("Image Dimensions: ", Intervals
		.dimensionsAsLongArray(input), Intervals.dimensionsAsLongArray(res));

	assertEquals("Image Factory: ", ArrayImgFactory.class, res.factory()
		.getClass());
}
 
Example #8
Source File: SliceTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testNonZeroMinimumInterval() {

	Img<ByteType> img3D = ArrayImgs.bytes(50, 50, 3);
	IntervalView<ByteType> interval2D = Views.interval(img3D,
			new FinalInterval(new long[] { 25, 25, 2 }, new long[] { 35, 35, 2 }));
	final int[] xyAxis = new int[] { 0, 1 };

	// iterate through every slice, should return a single
	// RandomAccessibleInterval<?> from 25, 25, 2 to 35, 35, 2

	final SlicesII<ByteType> hyperSlices = new SlicesII<>(interval2D, xyAxis, true);
	final Cursor<RandomAccessibleInterval<ByteType>> c = hyperSlices.cursor();
	int i = 0;
	while (c.hasNext()) {
		c.next();
		i++;
	}

	assertEquals(1, i);
}
 
Example #9
Source File: OutlineTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test the op with a 3x3x3x3 hypercube. The cube is in the middle of a
 * 5x5x5x5 img
 */
@Test
public void testHyperCube() {
	// SETUP
	final Img<BitType> img = ArrayImgs.bits(5, 5, 5, 5);
	final IntervalView<BitType> hyperCube = Views.offsetInterval(img,
		new long[] { 1, 1, 1, 1 }, new long[] { 3, 3, 3, 3 });
	hyperCube.cursor().forEachRemaining(BitType::setOne);

	// EXECUTE
	final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
		Boolean.TRUE);

	// VERIFY
	assertEquals("Wrong number of foreground elements in interval", 80,
		countForeground(result));
	final IntervalView<BitType> resultHyperCube = Views.offsetInterval(result,
		new long[] { 1, 1, 1, 1 }, new long[] { 3, 3, 3, 3 });
	assertEquals("Wrong number of foreground elements in object", 80,
		countForeground(resultHyperCube));
	assertPositionBackground(result, new long[] { 2, 2, 2, 2 });
}
 
Example #10
Source File: OutlineTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test the op with a 3x3 square starting from (0,1) in a 5x5 img without
 * excluding edges
 *
 * @see Outline#compute(RandomAccessibleInterval, Boolean,
 *      RandomAccessibleInterval)
 * @see #testEdgeSquare()
 */
@Test
public void testEdgeSquareExcludeEdgesFalse() {
	// SETUP
	final Img<BitType> img = ArrayImgs.bits(5, 5);
	final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
		0, 1 }, new long[] { 3, 3 });
	square.cursor().forEachRemaining(BitType::setOne);

	final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
		Boolean.FALSE);

	assertEquals("Wrong number of foreground elements in interval", 8,
		countForeground(result));
	final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
		new long[] { 0, 1 }, new long[] { 3, 3 });
	assertEquals("Wrong number of foreground elements in object", 8,
		countForeground(resultSquare));
	assertPositionBackground(result, new long[] { 1, 2 });
}
 
Example #11
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testUnevenBoxes() {
	// SETUP
	final int size = 10;
	final int max = size - 1;
	final long boxSize = size - 1;
	final Img<BitType> img = ArrayImgs.bits(size, size, size);
	final IntervalView<BitType> lastXYSlice = Views.interval(img,
			new long[] { 0, 0, max}, new long[] { max, max, max});
	lastXYSlice.forEach(BitType::setOne);

	// EXECUTE
	final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
			.boxCount(img, boxSize, boxSize, 3.0);

	// VERIFY
	final ValuePair<DoubleType, DoubleType> point = points.get(0);
	assertEquals(point.b.get(), Math.log(4), 1e-12);
}
 
Example #12
Source File: OutlineTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test the op with a 3x3 square starting from (0,1) in a 5x5 img
 *
 * @see Outline#compute(RandomAccessibleInterval, Boolean,
 *      RandomAccessibleInterval)
 * @see #testEdgeSquare()
 */
@Test
public void testEdgeSquare() {
	// SETUP
	final Img<BitType> img = ArrayImgs.bits(5, 5);
	final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
		0, 1 }, new long[] { 3, 3 });
	square.cursor().forEachRemaining(BitType::setOne);

	// EXECUTION
	final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
		Boolean.TRUE);

	// VERIFY
	assertEquals("Wrong number of foreground elements in interval", 7,
		countForeground(result));
	final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
		new long[] { 0, 1 }, new long[] { 3, 3 });
	assertEquals("Wrong number of foreground elements in object", 7,
		countForeground(resultSquare));
	assertPositionBackground(result, new long[] { 0, 2 });
	assertPositionBackground(result, new long[] { 1, 2 });
}
 
Example #13
Source File: OutlineTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test the op with a 3x3 square with a hole in the middle. The square is in
 * the middle of a 5x5 img
 */
@Test
public void testOutlineSquare() {
	// SETUP
	final Img<BitType> img = ArrayImgs.bits(5, 5);
	final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
		1, 1 }, new long[] { 3, 3 });
	square.cursor().forEachRemaining(BitType::setOne);
	final RandomAccess<BitType> access = square.randomAccess();
	access.setPosition(new long[] { 1, 1 });
	access.get().setZero();

	// EXECUTION
	final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
		Boolean.TRUE);

	// VERIFY
	assertEquals("Wrong number of foreground elements in interval", 8,
		countForeground(result));
	final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
		new long[] { 1, 1 }, new long[] { 3, 3 });
	assertEquals("Wrong number of foreground elements in object", 8,
		countForeground(resultSquare));
	assertPositionBackground(result, new long[] { 2, 2 });
}
 
Example #14
Source File: OutlineTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Test the op with a 2x2 square. The square is in the middle of a 4x4 img */
@Test
public void testSquare() {
	// SETUP
	final Img<BitType> img = ArrayImgs.bits(4, 4);
	final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
		1, 1 }, new long[] { 2, 2 });
	square.cursor().forEachRemaining(BitType::setOne);

	// EXECUTE
	final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
		Boolean.TRUE);

	// VERIFY
	assertEquals("Wrong number of foreground elements in interval", 4,
		countForeground(result));
	final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
		new long[] { 1, 1 }, new long[] { 2, 2 });
	assertTrue("Wrong number of foreground elements in object", allForeground(
		resultSquare));
}
 
Example #15
Source File: LocalThresholdIntegral.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Add 0s before axis minimum.
 * 
 * @param input Input RAI
 * @return An extended and cropped version of input
 */
private <T extends RealType<T>> RandomAccessibleInterval<T> addLeadingZeros(
	RandomAccessibleInterval<T> input)
{
	final long[] min = Intervals.minAsLongArray(input);
	final long[] max = Intervals.maxAsLongArray(input);

	for (int i = 0; i < max.length; i++) {
		min[i]--;
	}

	final T realZero = Util.getTypeFromInterval(input).copy();
	realZero.setZero();

	final ExtendedRandomAccessibleInterval<T, RandomAccessibleInterval<T>> extendedImg = Views.extendValue(input,
		realZero);
	final IntervalView<T> offsetInterval = Views.interval(extendedImg,
		min, max);
	
	return Views.zeroMin(offsetInterval);
}
 
Example #16
Source File: InvertAxisViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void intervalInvertAxisTest() {

	final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

	final IntervalView<DoubleType> il2 = Views.invertAxis(img, 1);
	final IntervalView<DoubleType> opr = ops.transform().invertAxisView(img, 1);

	for (int i = 0; i < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
			.getMatrix().length; i++) {
		for (int j = 0; j < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
				.getMatrix()[i].length; j++) {
			assertEquals(
					((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource().getMatrix()[i][j],
					((MixedTransformView<DoubleType>) opr.getSource()).getTransformToSource().getMatrix()[i][j],
					1e-10);
		}
	}
}
 
Example #17
Source File: RotateViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalRotateInterval() {
	final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 20, 10 }, new DoubleType());

	final IntervalView<DoubleType> il2 = Views.rotate((RandomAccessibleInterval<DoubleType>) img, 1, 0);
	final IntervalView<DoubleType> opr = ops.transform().rotateView((RandomAccessibleInterval<DoubleType>) img, 1, 0);

	assertEquals(img.min(1), il2.min(0));
	assertEquals(img.max(1), il2.max(0));
	assertEquals(img.min(0), -il2.max(1));
	assertEquals(img.max(0), -il2.min(1));

	for (int i = 0; i < il2.numDimensions(); i++) {
		assertEquals(il2.max(i), opr.max(i));
		assertEquals(il2.min(i), opr.min(i));
	}

}
 
Example #18
Source File: RotateViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalRotate() {
	final Img<DoubleType> img = ArrayImgs.doubles(20,10);

	final IntervalView<DoubleType> il2 = Views.rotate((RandomAccessibleInterval<DoubleType>) img, 1, 0);
	final IntervalView<DoubleType> opr = (IntervalView<DoubleType>) ops.transform().rotateView((RandomAccessibleInterval<DoubleType>) img, 1, 0);

	for (int i = 0; i < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
			.getMatrix().length; i++) {
		for (int j = 0; j < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
				.getMatrix()[i].length; j++) {
			assertEquals(
					((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource().getMatrix()[i][j],
					((MixedTransformView<DoubleType>) opr.getSource()).getTransformToSource().getMatrix()[i][j],
					1e-10);
		}
	}
}
 
Example #19
Source File: DefaultDoG.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final RandomAccessibleInterval<T> input,
	final RandomAccessibleInterval<T> output)
{
	// input may potentially be translated
	final long[] translation = new long[input.numDimensions()];
	input.min(translation);

	final IntervalView<T> tmpInterval = Views.interval(Views.translate(
		(RandomAccessible<T>) tmpCreator.calculate(input), translation), output);

	gauss1.compute(input, tmpInterval);
	gauss2.compute(input, output);

	// TODO: Match the Subtract Op in initialize() once we have BinaryOp
	ops().run(Ops.Math.Subtract.class, output, output, tmpInterval);
}
 
Example #20
Source File: PermuteViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalPermuteInverseDimensionCoordinates() {
	Img<DoubleType> img = ArrayImgs.doubles(2, 2);
	Cursor<DoubleType> c = img.cursor();
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	while (c.hasNext()) {
		c.next().set(r.nextDouble());
	}
	IntervalView<DoubleType> expected = Views.permuteCoordinatesInverse(img, new int[]{0, 1}, 1);
	Cursor<DoubleType> e = expected.cursor();
	RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}, 1);
	RandomAccess<DoubleType> actualRA = actual.randomAccess();
	
	while (e.hasNext()) {
		e.next();
		actualRA.setPosition(e);
		assertEquals(e.get().get(), actualRA.get().get(), 1e-10);
	}
	
	assertTrue(Intervals.equals(expected, actual));
	
}
 
Example #21
Source File: PermuteViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalPermuteInverseCoordinates() {
	Img<DoubleType> img = ArrayImgs.doubles(2, 2);
	Cursor<DoubleType> c = img.cursor();
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	while (c.hasNext()) {
		c.next().set(r.nextDouble());
	}
	IntervalView<DoubleType> expected = Views.permuteCoordinatesInverse(img, new int[]{0, 1});
	Cursor<DoubleType> e = expected.cursor();
	RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1});
	RandomAccess<DoubleType> actualRA = actual.randomAccess();
	
	while (e.hasNext()) {
		e.next();
		actualRA.setPosition(e);
		assertEquals(e.get().get(), actualRA.get().get(), 1e-10);
	}
	
	assertTrue(Intervals.equals(expected, actual));
	
}
 
Example #22
Source File: PermuteViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalPermuteDimensionCoordinates() {
	Img<DoubleType> img = ArrayImgs.doubles(2, 2);
	Cursor<DoubleType> c = img.cursor();
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	while (c.hasNext()) {
		c.next().set(r.nextDouble());
	}
	IntervalView<DoubleType> expected = Views.permuteCoordinates(img, new int[]{0, 1}, 1);
	Cursor<DoubleType> e = expected.cursor();
	RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}, 1);
	RandomAccess<DoubleType> actualRA = actual.randomAccess();
	
	while (e.hasNext()) {
		e.next();
		actualRA.setPosition(e);
		assertEquals(e.get().get(), actualRA.get().get(), 1e-10);
	}
	
	assertTrue(Intervals.equals(expected, actual));
	
}
 
Example #23
Source File: PermuteViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalPermuteCoordinates() {
	Img<DoubleType> img = ArrayImgs.doubles(2, 2);
	Cursor<DoubleType> c = img.cursor();
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	while (c.hasNext()) {
		c.next().set(r.nextDouble());
	}
	IntervalView<DoubleType> expected = Views.permuteCoordinates(img, new int[]{0, 1});
	Cursor<DoubleType> e = expected.cursor();
	RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesView(img, new int[]{0, 1});
	RandomAccess<DoubleType> actualRA = actual.randomAccess();
	
	while (e.hasNext()) {
		e.next();
		actualRA.setPosition(e);
		assertEquals(e.get().get(), actualRA.get().get(), 1e-10);
	}
	
	assertTrue(Intervals.equals(expected, actual));
	
}
 
Example #24
Source File: PermuteViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void permuteCoordinatesInverseOfDimensionTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType());
	Cursor<DoubleType> c = img.cursor();
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	while (c.hasNext()) {
		c.next().set(r.nextDouble());
	}
	
	IntervalView<DoubleType> out = Views.permuteCoordinatesInverse(img, new int[]{0, 1}, 1);
	
	Cursor<DoubleType> il2 = out.cursor();
	RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}, 1).randomAccess();
	
	while (il2.hasNext()) {
		il2.next();
		opr.setPosition(il2);
		assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	}
}
 
Example #25
Source File: HyperSliceViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void IntervalHyperSliceTest() {

	final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10, 10 },
			new DoubleType());

	final IntervalView<DoubleType> il2 = Views.hyperSlice((RandomAccessibleInterval<DoubleType>) img, 1, 8);
	final IntervalView<DoubleType> opr = ops.transform().hyperSliceView(img, 1, 8);

	for (int i = 0; i < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
			.getMatrix().length; i++) {
		for (int j = 0; j < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource()
				.getMatrix()[i].length; j++) {
			assertEquals(
					((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource().getMatrix()[i][j],
					((MixedTransformView<DoubleType>) opr.getSource()).getTransformToSource().getMatrix()[i][j],
					1e-10);
		}
	}

	assertEquals(img.numDimensions() - 1, opr.numDimensions());
}
 
Example #26
Source File: CommitCanvasN5.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static void writeBlocksLabelMultisetType(
		final RandomAccessibleInterval<UnsignedLongType> canvas,
		final long[] blocks,
		final DatasetSpec datasetSpec,
		final BlockSpec blockSpec,
		final TLongObjectHashMap<BlockDiff> blockDiff) throws IOException {
	final RandomAccessibleInterval<LabelMultisetType> highestResolutionData = N5LabelMultisets.openLabelMultiset(datasetSpec.container, datasetSpec.dataset);
	for (final long blockId : blocks) {
		blockSpec.fromLinearIndex(blockId);
		final IntervalView<Pair<LabelMultisetType, UnsignedLongType>> backgroundWithCanvas = Views.interval(Views.pair(highestResolutionData, canvas), blockSpec.asInterval());
		final int numElements = (int) Intervals.numElements(backgroundWithCanvas);
		final byte[] byteData = LabelUtils.serializeLabelMultisetTypes(new BackgroundCanvasIterable(Views.flatIterable(backgroundWithCanvas)), numElements);
		final ByteArrayDataBlock dataBlock = new ByteArrayDataBlock(Intervals.dimensionsAsIntArray(backgroundWithCanvas), blockSpec.pos, byteData);
		datasetSpec.container.writeBlock(datasetSpec.dataset, datasetSpec.attributes, dataBlock);
		blockDiff.put(blockId, createBlockDiffFromCanvas(backgroundWithCanvas));
	}
}
 
Example #27
Source File: LabelIntersectionCellLoader.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void load(final SingleCellArrayImg<UnsignedByteType, ?> cell) throws Exception
{
	LOG.debug(
			"Populating cell {} {} {}",
			Intervals.minAsLongArray(cell),
			Intervals.maxAsLongArray(cell),
			cell.size()
	         );
	final IntervalView<U> label2Interval        = Views.interval(data2, cell);
	final Cursor<T> label1Cursor                = Views.flatIterable(Views.interval(data1, cell)).cursor();
	final Cursor<U> label2Cursor                = Views.flatIterable(label2Interval).cursor();
	final Cursor<UnsignedByteType> targetCursor = cell.localizingCursor();

	//		cell.forEach( UnsignedByteType::setZero );
	while (targetCursor.hasNext())
	{
		final UnsignedByteType targetType = targetCursor.next();
		final T                label1Type = label1Cursor.next();
		final U                label2Type = label2Cursor.next();
		if (targetType.get() == 0)
		{
			if (check1.test(label1Type) && check2.test(label2Type))
			{
				FloodFill.fill(
						Views.extend(label2Interval, new OutOfBoundsConstantValueFactory<>(extension)),
						Views.extendValue(cell, new UnsignedByteType(1)),
						targetCursor,
						new UnsignedByteType(1),
						new DiamondShape(1),
						(s, t) -> check2.test(s) && t.get() == 0
				              );
			}
		}
	}
}
 
Example #28
Source File: SlicesII.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public RandomAccessibleInterval<T> get() {
	localize(tmpPosition);

	final long[] offset = tmpPosition.clone();
	for (int d = 0; d < max.length; d++) {
		offset[d] += sliceOffset[d];
	}

	final IntervalView<T> res = Views.offsetInterval(src, offset, sliceDims);

	return dropSingltonDimensions ? Views.dropSingletonDimensions(res) : res;
}
 
Example #29
Source File: ZeroMinViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void defaultZeroMinTest() {
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

	IntervalView<DoubleType> imgTranslated = Views.interval(
			Views.translate((RandomAccessible<DoubleType>) img, 2, 5), new long[] { 2, 5 }, new long[] { 12, 15 });

	IntervalView<DoubleType> il2 = Views.zeroMin(imgTranslated);
	IntervalView<DoubleType> opr = ops.transform().zeroMinView(imgTranslated);

	assertTrue(Views.isZeroMin(il2) == Views.isZeroMin(opr));
}
 
Example #30
Source File: RichardsonLucyC.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public void initialize() {
	super.initialize();

	if (updateOp == null) {
		updateOp = (UnaryComputerOp) Computers.unary(ops(),
			RichardsonLucyUpdate.class, RandomAccessibleInterval.class,
			RandomAccessibleInterval.class);
	}

	rlCorrectionOp = (BinaryComputerOp) Computers.binary(ops(),
		RichardsonLucyCorrection.class, RandomAccessibleInterval.class,
		RandomAccessibleInterval.class, RandomAccessibleInterval.class,
		getFFTInput(), getFFTKernel());

	fftKernelOp = (UnaryComputerOp) Computers.unary(ops(), FFTMethodsOpC.class,
		getFFTKernel(), RandomAccessibleInterval.class);

	copyOp = (UnaryHybridCF) Hybrids.unaryCF(ops(), Ops.Copy.RAI.class,
		RandomAccessibleInterval.class, IntervalView.class);

	copy2Op = (UnaryHybridCF) Hybrids.unaryCF(ops(), Ops.Copy.RAI.class,
		RandomAccessibleInterval.class, IntervalView.class);

	createOp = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class,
		Img.class, Dimensions.class, Util.getTypeFromInterval(out()));

	convolverOp = (BinaryComputerOp) Computers.binary(ops(), ConvolveFFTC.class,
		RandomAccessibleInterval.class, RandomAccessibleInterval.class,
		RandomAccessibleInterval.class, this.getFFTInput(), this.getFFTKernel(),
		true, false);

}