net.imglib2.RandomAccess Java Examples

The following examples show how to use net.imglib2.RandomAccess. 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: EulerCharacteristic26NFloatingTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Test with a cube that has a "handle"
 * <p>
 * Here χ = β_0 - β_1 + β_2 = 1 - 1 + 0 = 0
 * </p>
 */
@Test
public void testHandleCube() throws Exception {
    final Img<BitType> cube = drawCube(9, 9, 9, 5);
    final RandomAccess<BitType> access = cube.randomAccess();

    // Draw a handle on the front xy-face of the cuboid
    access.setPosition(9, 0);
    access.setPosition(6, 1);
    access.setPosition(4, 2);
    access.get().setOne();
    access.setPosition(3, 2);
    access.get().setOne();
    access.setPosition(7, 1);
    access.get().setOne();
    access.setPosition(8, 1);
    access.get().setOne();
    access.setPosition(4, 2);
    access.get().setOne();

    final double result = ops.topology().eulerCharacteristic26NFloating(cube).get();

    assertEquals("Euler characteristic (χ) is incorrect", 0.0, result, 1e-12);
}
 
Example #2
Source File: FloodFillTransformedPlane.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public static void fill(
		final AffineTransform3D localToWorld,
		final double[] min,
		final double[] max,
		final double zRangePos,
		final double zRangeNeg,
		final RandomAccess<? extends BooleanType<?>> relevantBackgroundAccess,
		final RandomAccess<? extends IntegerType<?>> localAccess,
		final RealLocalizable seedWorld,
		final long fillLabel)
{
	new FloodFillTransformedPlane(localToWorld, min[0], min[1], max[0], max[1], zRangePos, zRangeNeg).fill(
			relevantBackgroundAccess,
			localAccess,
			seedWorld,
			fillLabel
	                                                                                                      );
}
 
Example #3
Source File: IntervalViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultIntervalTest() {
	
	Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType());
	
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}
	
	Cursor<DoubleType> il2 = Views.interval(img, img).localizingCursor();
	RandomAccess<DoubleType> opr = ops.transform().intervalView(img, img).randomAccess();

	
	while (il2.hasNext()) {
		DoubleType e = il2.next();
		opr.setPosition(il2);
		
		assertEquals(e.get(), opr.get().get(), 1e-10);
	}
}
 
Example #4
Source File: FloodFillTransformedCylinder3D.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public static void fill(
		final AffineTransform3D localToWorld,
		final double radiusX,
		final double radiusY,
		final double zRangePos,
		final double zRangeNeg,
		final RandomAccess<? extends IntegerType<?>> localAccess,
		final RealLocalizable seedWorld,
		final long fillLabel)
{
	new FloodFillTransformedCylinder3D(localToWorld, radiusX, radiusY, zRangePos, zRangeNeg).fill(
			localAccess,
			seedWorld,
			fillLabel
	                                                                                             );
}
 
Example #5
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <I1, I2, O> void map(final RandomAccessibleInterval<I1> a,
	final IterableInterval<I2> b, final RandomAccessibleInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op, final long startIndex,
	final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final RandomAccess<I1> aAccess = a.randomAccess();
	final Cursor<I2> bCursor = b.localizingCursor();
	final RandomAccess<O> cAccess = c.randomAccess();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		bCursor.jumpFwd(ctr == 0 ? startIndex + 1 : stepSize);
		aAccess.setPosition(bCursor);
		cAccess.setPosition(bCursor);
		op.compute(aAccess.get(), bCursor.get(), cAccess.get());
	}
}
 
Example #6
Source File: UnshearViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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);
	}
}
 
Example #7
Source File: SubsampleViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalSubsample() {
	Img<DoubleType> img = ArrayImgs.doubles(10, 10);
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}

	SubsampleIntervalView<DoubleType> expected = Views.subsample((RandomAccessibleInterval<DoubleType>) img, 2);
	SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2);

	Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 4 }).localizingCursor();
	RandomAccess<DoubleType> oprRA = actual.randomAccess();

	while (il2C.hasNext()) {
		il2C.next();
		oprRA.setPosition(il2C);
		assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
	}
	
	assertTrue(Intervals.equals(expected, actual));
}
 
Example #8
Source File: CopyRAITest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void copyRAINoOutputTest() {
	@SuppressWarnings("unchecked")
	final RandomAccessibleInterval<UnsignedByteType> output =
		(RandomAccessibleInterval<UnsignedByteType>) ops.run(CopyRAI.class,
			input);

	final Cursor<UnsignedByteType> inc = input.localizingCursor();
	final RandomAccess<UnsignedByteType> outRA = output.randomAccess();

	while (inc.hasNext()) {
		inc.fwd();
		outRA.setPosition(inc);
		assertEquals(inc.get().get(), outRA.get().get());
	}
}
 
Example #9
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <I1, I2, O> void map(final IterableInterval<I1> a,
	final RandomAccessibleInterval<I2> b, final IterableInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op, final long startIndex,
	final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<I1> aCursor = a.localizingCursor();
	final RandomAccess<I2> bAccess = b.randomAccess();
	final Cursor<O> cCursor = c.cursor();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		final long m = ctr == 0 ? startIndex + 1 : stepSize;
		aCursor.jumpFwd(m);
		cCursor.jumpFwd(m);
		bAccess.setPosition(aCursor);
		op.compute(aCursor.get(), bAccess.get(), cCursor.get());
	}
}
 
Example #10
Source File: Outline.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Creates a task that finds and copies outline pixels to the output.
 *
 * @param inputCursor Cursor to the input image
 * @param inputAccess Random access to the extended input image
 * @param output Access to the output image
 * @param start Which pixel thread should start from
 * @param elements Number of pixels thread processes
 * @param <B> Type of elements in the input image
 * @return a task for parallel processing.
 */
// region -- Helper methods --
private static <B extends BooleanType<B>> Runnable createTask(
		final Cursor<B> inputCursor, final OutOfBounds<B> inputAccess,
		final RandomAccess<BitType> output, final long start,
		final long elements) {
	return () -> {
		final long[] coordinates = new long[inputAccess.numDimensions()];
		inputCursor.jumpFwd(start);
		for (long j = 0; j < elements; j++) {
			inputCursor.localize(coordinates);
			inputAccess.setPosition(coordinates);
			if (isOutline(inputAccess, coordinates)) {
				output.setPosition(coordinates);
				output.get().set(inputCursor.get().get());
			}
			inputCursor.fwd();
		}
	};
}
 
Example #11
Source File: N5.java    From sciview with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static List<RealLocalizable> openPoints(N5Reader n5, String pointDataset) throws IOException {
    List<RealLocalizable> points = new ArrayList<>();

    // Now load vertices
    RandomAccessibleInterval<DoubleType> vRai = N5Utils.open(n5, pointDataset);
    RandomAccess<DoubleType> vAccess = vRai.randomAccess();
    long[] pos = new long[2];
    for( pos[0] = 0; pos[0] < vRai.dimension(0); pos[0]++ ) {
        double[] vert = new double[(int) vRai.dimension(1)];
        for( pos[1] = 0; pos[1] < (int) vRai.dimension(1); pos[1]++ ) {
            vAccess.setPosition(pos);
            vert[(int) pos[1]] = vAccess.get().get();
        }
        points.add(new RealPoint(vert));
    }

    return points;
}
 
Example #12
Source File: AbstractThresholdTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Before
public void initialize() {
	final long[] dimensions = new long[] { xSize, ySize };

	final Random r = new Random(0xdeadbeef);

	// create image and output
	in = ArrayImgs.unsignedShorts(dimensions);

	final RandomAccess<UnsignedShortType> ra = in.randomAccess();

	// populate pixel values with a ramp function + a constant
	for (int x = 0; x < xSize; x++) {
		for (int y = 0; y < ySize; y++) {
			ra.setPosition(new int[] { x, y });
			ra.get().setReal(r.nextInt(65535));
		}
	}
}
 
Example #13
Source File: MorphologyOpsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testFillHoles1() {
	Img<BitType> result = ops.create().img(invertedImgWithFilledHoles);
	Img<BitType> inverted = ops.create().img(invertedImgWithFilledHoles);
	ops.image().invert(inverted, imgWithHoles);
	ops.morphology().fillHoles(result, inverted, new DiamondShape(1));

	Cursor<BitType> resultC = result.localizingCursor();
	RandomAccess<BitType> groundTruthRA = invertedImgWithFilledHoles.randomAccess();

	while (resultC.hasNext()) {
		boolean r = resultC.next().get();
		groundTruthRA.setPosition(resultC);
		assertEquals(groundTruthRA.get().get(), r);
	}
}
 
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 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 #15
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 #16
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 #17
Source File: SubsampleViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testIntervalSubsampleSteps() {
	Img<DoubleType> img = ArrayImgs.doubles(10,10);
	MersenneTwisterFast r = new MersenneTwisterFast(SEED);
	for (DoubleType d : img) {
		d.set(r.nextDouble());
	}

	SubsampleIntervalView<DoubleType> expected = Views.subsample((RandomAccessibleInterval<DoubleType>) img, 2, 1);
	SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2, 1);

	Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor();
	RandomAccess<DoubleType> oprRA = actual.randomAccess();

	while (il2C.hasNext()) {
		il2C.next();
		oprRA.setPosition(il2C);
		assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
	}
	
	assertTrue(Intervals.equals(expected, actual));
}
 
Example #18
Source File: BoxCountTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testOneVoxel() {
	// SETUP
	final PrimitiveIterator.OfDouble sizes = DoubleStream.of(9, 3, 1).map(
		i -> -Math.log(i)).iterator();
	final PrimitiveIterator.OfDouble counts = DoubleStream.of(1, 1, 1).map(
		Math::log).iterator();
	final Img<BitType> img = ArrayImgs.bits(9, 9, 9);
	final RandomAccess<BitType> access = img.randomAccess();
	access.setPosition(new long[] { 4, 4, 4 });
	access.get().setOne();

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

	// VERIFY
	points.forEach(p -> {
		assertEquals(p.a.get(), sizes.next(), 1e-12);
		assertEquals(p.b.get(), counts.next(), 1e-12);
	});
}
 
Example #19
Source File: TestImageAccessor.java    From Colocalisation_Analysis with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Inverts an image.
 *
 * @param <T> The images data type.
 * @param image The image to convert.
 * @return The inverted image.
 */
public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> invertImage(
		RandomAccessibleInterval<T> image) {
	Cursor<T> imgCursor = Views.iterable(image).localizingCursor();
	// invert the image
	long[] dim = new long[ image.numDimensions() ];
	image.dimensions(dim);
	ArrayImgFactory<T> imgFactory = new ArrayImgFactory<T>();
	RandomAccessibleInterval<T> invImg = imgFactory.create(
			dim, image.randomAccess().get().createVariable() ); // "Inverted " + image.getName());
	RandomAccess<T> invCursor = invImg.randomAccess();

	while (imgCursor.hasNext()) {
		imgCursor.fwd();
		invCursor.setPosition(imgCursor);
		invCursor.get().setReal( imgCursor.get().getMaxValue() - imgCursor.get().getRealDouble() );
	}

	return invImg;
}
 
Example #20
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <I1, I2, O> void map(final IterableInterval<I1> a,
	final RandomAccessibleInterval<I2> b, final RandomAccessibleInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op, final long startIndex,
	final long stepSize, final long numSteps)
{
	if (numSteps <= 0) return;
	final Cursor<I1> aCursor = a.localizingCursor();
	final RandomAccess<I2> bAccess = b.randomAccess();
	final RandomAccess<O> cAccess = c.randomAccess();

	for (long ctr = 0; ctr < numSteps; ctr++) {
		aCursor.jumpFwd(ctr == 0 ? startIndex + 1 : stepSize);
		bAccess.setPosition(aCursor);
		cAccess.setPosition(aCursor);
		op.compute(aCursor.get(), bAccess.get(), cAccess.get());
	}
}
 
Example #21
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <I, O> void map(final RandomAccessibleInterval<I> a,
	final IterableInterval<O> b, final UnaryComputerOp<I, O> op)
{
	final RandomAccess<I> aAccess = a.randomAccess();
	final Cursor<O> bCursor = b.localizingCursor();
	while (bCursor.hasNext()) {
		bCursor.fwd();
		aAccess.setPosition(bCursor);
		op.compute(aAccess.get(), bCursor.get());
	}
}
 
Example #22
Source File: Maps.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <I1, I2, O> void map(final IterableInterval<I1> a,
	final RandomAccessibleInterval<I2> b, final IterableInterval<O> c,
	final BinaryComputerOp<I1, I2, O> op)
{
	final Cursor<I1> aCursor = a.localizingCursor();
	final RandomAccess<I2> bAccess = b.randomAccess();
	final Cursor<O> cCursor = c.cursor();
	while (aCursor.hasNext()) {
		aCursor.fwd();
		bAccess.setPosition(aCursor);
		op.compute(aCursor.get(), bAccess.get(), cCursor.next());
	}
}
 
Example #23
Source File: DistanceTransform2DTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void generate2DImg(final RandomAccessibleInterval<BitType> in) {
	final RandomAccess<BitType> raIn = in.randomAccess();
	final MersenneTwisterFast random = new MersenneTwisterFast(SEED);

	for (int x = 0; x < in.dimension(0); x++) {
		for (int y = 0; y < in.dimension(1); y++) {
			raIn.setPosition(new int[] { x, y });
			raIn.get().set(random.nextBoolean());
		}
	}
}
 
Example #24
Source File: FloodFillTransformedCylinder3D.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public static void fill(
		final AffineTransform3D localToWorld,
		final double radiusX,
		final double radiusY,
		final double zRange,
		final RandomAccess<? extends IntegerType<?>> localAccess,
		final RealLocalizable seedWorld,
		final long fillLabel)
{
	new FloodFillTransformedCylinder3D(localToWorld, radiusX, radiusY, zRange).fill(
			localAccess,
			seedWorld,
			fillLabel
	                                                                               );
}
 
Example #25
Source File: Block.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private static final void paste( final long start, final long loopSize, final RandomAccessibleInterval< FloatType > target, final RandomAccessibleInterval< FloatType > block, 
		final long[] effectiveOffset, final long[] effectiveSize, final long[] effectiveLocalOffset )
{
	final int numDimensions = target.numDimensions();
	
	// iterate over effective size
	final LocalizingZeroMinIntervalIterator cursor = new LocalizingZeroMinIntervalIterator( effectiveSize );
	
	// read from block
	final RandomAccess<FloatType> blockRandomAccess  = block.randomAccess();
	
	// write to target		
	final RandomAccess<FloatType> targetRandomAccess  = target.randomAccess();
	
	cursor.jumpFwd( start );
	
	final long[] tmp = new long[ numDimensions ];
	
	for ( long l = 0; l < loopSize; ++l )
	{
		cursor.fwd();
		cursor.localize( tmp );
		
		// move to the relative local offset where the real data starts
		for ( int d = 0; d < numDimensions; ++d )
			tmp[ d ] += effectiveLocalOffset[ d ];
		
		blockRandomAccess.setPosition( tmp );
		
		// move to the right position in the image
		for ( int d = 0; d < numDimensions; ++d )
			tmp[ d ] += effectiveOffset[ d ] - effectiveLocalOffset[ d ];

		targetRandomAccess.setPosition( tmp );

		// write the pixel
		targetRandomAccess.get().set( blockRandomAccess.get() );
	}
}
 
Example #26
Source File: MorphologicalThinningStrategy.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean removePixel(final long[] position,
	final RandomAccessible<BitType> accessible, final int iteration)
{

	// Setup
	final RandomAccess<BitType> access = randomAccess(accessible);
	access.setPosition(position);

	final boolean[] vals = getNeighbourhood(access);

	// Depending on the current step of the cycle, we rotate the two Filters by
	// 0, 90, 180 or 270 Degrees.
	if (iteration % 4 == 0) {
		return top(vals);
	}

	if (iteration % 4 == 1) {
		return right(vals);
	}

	if (iteration % 4 == 2) {
		return bottom(vals);
	}

	if (iteration % 4 == 3) {
		return left(vals);
	}

	return false;

}
 
Example #27
Source File: Block.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private static final void copy( final long start, final long loopSize, final RandomAccessible< FloatType > source, final RandomAccessibleInterval< FloatType > block, final long[] offset )
{
	final int numDimensions = source.numDimensions();
	final Cursor< FloatType > cursor = Views.iterable( block ).localizingCursor();

	// define where we will query the RandomAccess on the source
	// (we say it is the entire block, although it is just a part of it,
	// but which part depends on the underlying container)
	final long[] min = new long[ numDimensions ];
	final long[] max = new long[ numDimensions ];
	
	for ( int d = 0; d < numDimensions; ++d )
	{
		min[ d ] = offset[ d ];
		max[ d ] = offset[ d ] + block.dimension( d ) - 1;
	}

	final RandomAccess< FloatType > randomAccess = source.randomAccess( new FinalInterval( min, max ) );

	cursor.jumpFwd( start );

	final long[] tmp = new long[ numDimensions ];

	for ( long l = 0; l < loopSize; ++l )
	{
		cursor.fwd();
		cursor.localize( tmp );
		
		for ( int d = 0; d < numDimensions; ++d )
			tmp[ d ] += offset[ d ];
		
		randomAccess.setPosition( tmp );
		cursor.get().set( randomAccess.get() );
	}
}
 
Example #28
Source File: HistogramOfOrientedGradients2D.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ComputeDescriptor(final RandomAccessibleInterval<FloatType> in, final long i,
		final RandomAccess<FloatType> raAngles, final RandomAccess<FloatType> raMagnitudes,
		final RandomAccess<FloatType> raOut, final RandomAccess<Neighborhood<FloatType>> raNeighbor) {
	this.in = in;
	this.i = i;
	this.raAngles = raAngles;
	this.raMagnitudes = raMagnitudes;
	this.raOut = raOut;
	this.raNeighbor = raNeighbor;
}
 
Example #29
Source File: ContentBased.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
protected Img< FloatType > approximateEntropy(
		final RandomAccessibleInterval< FloatType > input,
		final ImgFactory< ComplexFloatType > imgFactory,
		final double[] sigma1,
		final double[] sigma2 )

{
	// the result
	ImgFactory<FloatType> f;
	try { f = imgFactory.imgFactory( new FloatType() ); } catch (IncompatibleTypeException e) { f = new ArrayImgFactory< FloatType >(); }
	
	final Img< FloatType > conv = f.create( input, new FloatType() );
	
	// compute I*sigma1
	FFTConvolution< FloatType > fftConv = new FFTConvolution<FloatType>( input, createGaussianKernel( sigma1 ), conv, imgFactory );
	fftConv.convolve();
	
	// compute ( I - I*sigma1 )^2
	final Cursor< FloatType > c = conv.cursor();
	final RandomAccess< FloatType > r = input.randomAccess();
	
	while ( c.hasNext() )
	{
		c.fwd();
		r.setPosition( c );
		
		final float diff = c.get().get() - r.get().get();
		c.get().set( diff * diff );
	}
	
	// compute ( ( I - I*sigma1 )^2 ) * sigma2
	fftConv = new FFTConvolution<FloatType>( conv, createGaussianKernel( sigma2 ), imgFactory );
	fftConv.convolve();

	// normalize to [0...1]
	FusionHelper.normalizeImage( conv );

	return conv;
}
 
Example #30
Source File: ConvertIIsTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void testScale() {
	ops.run(ConvertIIs.class, out, in,
		new ScaleRealTypes<ShortType, ByteType>());

	final Cursor<ShortType> c = in.localizingCursor();
	final RandomAccess<ByteType> ra = out.randomAccess();
	while (c.hasNext()) {
		final short value = c.next().get();
		ra.setPosition(c);
		assertEquals(scale(value), ra.get().get());
	}
}