net.imglib2.FinalInterval Java Examples

The following examples show how to use net.imglib2.FinalInterval. 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: DefaultDistanceTransformTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testComputer() {
	// create 4D image
	final RandomAccessibleInterval<BitType> in = ops.create().img(new FinalInterval(20, 20, 5, 3), new BitType());
	generate4DImg(in);
	
	// create output
	final RandomAccessibleInterval<FloatType> out = ops.create().img(in, new FloatType());

	/*
	 * test normal DT
	 */
	ops.run(DefaultDistanceTransform.class, out, in);
	compareResults(out, in, new double[] { 1, 1, 1, 1 });

	/*
	 * test calibrated DT
	 */
	final double[] calibration = new double[] { 3.74, 5.19, 1.21, 2.21 };
	ops.run(DefaultDistanceTransformCalibration.class, out, in,
			calibration);
	compareResults(out, in, calibration);
	
}
 
Example #2
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public ArrayImg<UnsignedVariableBitLengthType, LongArray>
	generateUnsignedVariableBitLengthTypeArrayTestImg(final boolean fill,
		final int nbits, final long... dims)
{
	final long[] array = new long[(int) Intervals.numElements(new FinalInterval(
		dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (long) (((pseudoRandom() / Integer.MAX_VALUE)) % (Math.pow(2, nbits))) ;
		}
	}

	final LongArray l = new LongArray(array);

	return ArrayImgs.unsignedVariableBitLengths(l, nbits, dims);
}
 
Example #3
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 #4
Source File: TransformTools.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
/**
 * create an integer interval from real interval, being conservatie on the size
 * (min is ceiled, max is floored)
 * @param overlap real input
 * @return interger interval, with mins ceiled and maxs floored
 */
public static FinalInterval getLocalRasterOverlap(RealInterval overlap)
{
	final int n = overlap.numDimensions();
	final long [] min = new long [n];
	final long [] max = new long [n];
	
	for (int i = 0; i< n; i++)
	{
		// round down errors when it is exactly 0.5, if we do not do this we end up with two intervals
		// of different size, e.g.:
		// if the first interval starts at 139.5 going to 199, the second one at 0.0 going to 59.5
		// then the rastered 1st would go from round(139.5)=140 + 1 = 141 -to- round(199)=199 - 1 = 198, dim=58
		// and  the rastered 2nd would go from round(0.0)=0 + 1     =   1 -to- round(59.5)=60 - 1 = 59,  dim=59
		min[i] = Math.round((overlap.realMin(i) - 0.0001 )) + 1;
		max[i] = Math.round((overlap.realMax(i) + 0.0001 )) - 1;
	}
	
	return new FinalInterval(min, max);
}
 
Example #5
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 #6
Source File: DefaultDistanceTransformTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void test() {
	// create 4D image
	final RandomAccessibleInterval<BitType> in = ops.create().img(new FinalInterval(20, 20, 5, 3), new BitType());
	generate4DImg(in);

	/*
	 * test normal DT
	 */
	RandomAccessibleInterval<FloatType> out = (RandomAccessibleInterval<FloatType>) ops
			.run(DefaultDistanceTransform.class, null, in);
	compareResults(out, in, new double[] { 1, 1, 1, 1 });

	/*
	 * test calibrated DT
	 */
	final double[] calibration = new double[] { 3.74, 5.19, 1.21, 2.21 };
	out = (RandomAccessibleInterval<FloatType>) ops.run(DefaultDistanceTransformCalibration.class, null, in,
			calibration);
	compareResults(out, in, calibration);
}
 
Example #7
Source File: PhaseCorrelation2.java    From BigStitcher with GNU General Public License v2.0 6 votes vote down vote up
public static <T extends RealType<T>, S extends RealType<S>, R extends RealType<R>, C extends ComplexType<C>> RandomAccessibleInterval<R> calculatePCM(
		RandomAccessibleInterval<T> img1, RandomAccessibleInterval<S> img2, int[] extension,
		ImgFactory<R> factory, R type, ImgFactory<C> fftFactory, C fftType, ExecutorService service){

	
	// TODO: Extension absolute per dimension in pixels, i.e. int[] extension
	// TODO: not bigger than the image dimension because the second mirroring is identical to the image
	
	Dimensions extSize = PhaseCorrelation2Util.getExtendedSize(img1, img2, extension);
	long[] paddedDimensions = new long[extSize.numDimensions()];
	long[] fftSize = new long[extSize.numDimensions()];
	FFTMethods.dimensionsRealToComplexFast(extSize, paddedDimensions, fftSize);
	
	RandomAccessibleInterval<C> fft1 = fftFactory.create(fftSize, fftType);
	RandomAccessibleInterval<C> fft2 = fftFactory.create(fftSize, fftType);
	
	FFT.realToComplex(Views.interval(PhaseCorrelation2Util.extendImageByFactor(img1, extension), 
			FFTMethods.paddingIntervalCentered(img1, new FinalInterval(paddedDimensions))), fft1, service);
	FFT.realToComplex(Views.interval(PhaseCorrelation2Util.extendImageByFactor(img2, extension), 
			FFTMethods.paddingIntervalCentered(img2, new FinalInterval(paddedDimensions))), fft2, service);
	
	RandomAccessibleInterval<R> pcm = calculatePCMInPlace(fft1, fft2, factory, type, service);
	return pcm;
	
}
 
Example #8
Source File: CreateImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void testImageMinimum() {

	final MersenneTwisterFast randomGenerator = new MersenneTwisterFast(SEED);

	for (int i = 0; i < TEST_SIZE; i++) {

		// between 2 and 5 dimensions
		final long[] max = new long[randomGenerator.nextInt(4) + 2];
		final long[] min = new long[max.length];

		// between 2 and 10 pixels per dimensions
		for (int j = 0; j < max.length; j++) {
			max[j] = randomGenerator.nextInt(9) + 2;
			min[j] = Math.max(0, max[j] - randomGenerator.nextInt(4));
		}

		// create img
		final Img<?> img = (Img<?>) ops.run(CreateImgFromInterval.class,
			new FinalInterval(min, max));

		assertArrayEquals("Image Minimum:", min, Intervals.minAsLongArray(img));
		assertArrayEquals("Image Maximum:", max, Intervals.maxAsLongArray(img));
	}
}
 
Example #9
Source File: ShearViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Tests {@link ShearViewInterval}. */
@Test
public void ShearIntervalTest() {
	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
			.shear(Views.extendZero(img), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1)
			.cursor();
	RandomAccess<DoubleType> opr = ops.transform()
			.shearView(Views.extendZero(img), 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 #10
Source File: DefaultCoarsenessFeature.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Apply mean filter with given size of reactangle shape
 * 
 * @param input
 *            Input image
 * @param i
 *            Size of rectangle shape
 * @return Filered mean image
 */
@SuppressWarnings("unchecked")
private Img<I> mean(final RandomAccessibleInterval<I> input, final int i) {

	long[] dims = new long[input.numDimensions()];
	input.dimensions(dims);

	final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(dims))];
	Img<I> meanImg = (Img<I>) ArrayImgs.unsignedBytes(array, dims);

	OutOfBoundsMirrorFactory<ByteType, Img<ByteType>> oobFactory = new OutOfBoundsMirrorFactory<>(
			Boundary.SINGLE);

	ops().run(MeanFilterOp.class, meanImg, input, new RectangleShape(i, true), oobFactory);

	return meanImg;
}
 
Example #11
Source File: LocalThresholdIntegral.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Removes leading 0s from integral image after composite creation.
 *
 * @param input Input RAI (can be a RAI of Composite)
 * @return An extended and cropped version of input
 */
private <T> RandomAccessibleInterval<T> removeLeadingZeros(
	final RandomAccessibleInterval<T> input)
{
	// Remove 0s from integralImg by shifting its interval by +1
	final long[] min = Intervals.minAsLongArray(input);
	final long[] max = Intervals.maxAsLongArray(input);

	for (int d = 0; d < input.numDimensions(); ++d) {
		int correctedSpan = getShape().getSpan() - 1;
		min[d] += (1 + correctedSpan);
		max[d] -= correctedSpan;
	}

	// Define the Interval on the infinite random accessibles
	final FinalInterval interval = new FinalInterval(min, max);

	final RandomAccessibleInterval<T> extendedImg = Views.offsetInterval(Views
		.extendBorder(input), interval);
	return extendedImg;
}
 
Example #12
Source File: PaddingIntervalOrigin.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public O calculate(final I input, final Interval centeredInterval) {

	int numDimensions = input.numDimensions();

	// compute where to place the final Interval for the input so that the
	// coordinate in the center
	// of the input is at position (0,0).
	final long[] min = new long[numDimensions];
	final long[] max = new long[numDimensions];

	for (int d = 0; d < numDimensions; ++d) {
		min[d] = input.min(d) + input.dimension(d) / 2;
		max[d] = min[d] + centeredInterval.dimension(d) - 1;
	}

	return (O) new FinalInterval(min, max);
}
 
Example #13
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 #14
Source File: CreateKernelSobel.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public RandomAccessibleInterval<T> calculate() {
	long[] dim = new long[4];

	dim[0] = 3;
	dim[1] = 1;

	for (int k = 2; k < dim.length; k++) {
		dim[k] = 1;
	}

	dim[dim.length - 1] = 2;

	RandomAccessibleInterval<T> output = createOp.calculate(new FinalInterval(dim));
	final Cursor<T> cursor = Views.iterable(output).cursor();
	int i = 0;
	while (cursor.hasNext()) {
		cursor.fwd();
		cursor.get().setReal(values[i]);
		i++;
	}

	return output;
}
 
Example #15
Source File: SlicesII.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static Interval initIntervals(final Interval src, final int[] axesOfInterest) {

		final long[] dimensionsToIterate = new long[src.numDimensions()];
		src.dimensions(dimensionsToIterate);

		// determine axis to iterate
		for (int i = 0; i < src.numDimensions(); i++) {
			for (int j = 0; j < axesOfInterest.length; j++) {

				if (axesOfInterest[j] == i) {
					dimensionsToIterate[i] = 1;
					break;
				}
			}
		}

		return new FinalInterval(dimensionsToIterate);
	}
 
Example #16
Source File: ListErode.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final RandomAccessibleInterval<T> in1,
	final List<Shape> in2, final IterableInterval<T> out)
{
	final long[][] minSize = Morphologies.computeMinSize(in1, in2);
	final Interval interval = new FinalInterval(minSize[1]);
	Img<T> upstream = imgCreator.calculate(interval);
	Img<T> downstream = imgCreator.calculate(interval);
	Img<T> tmp;

	erodeComputer.compute(in1, in2.get(0), Views.translate(downstream,
		minSize[0]));
	for (int i = 1; i < in2.size(); i++) {
		// Ping-ponging intermediate results between upstream and downstream to
		// avoid repetitively creating new Imgs.
		tmp = downstream;
		downstream = upstream;
		upstream = tmp;
		erodeComputer.compute(Views.interval(Views.extendValue(upstream, maxVal),
			interval), in2.get(i), downstream);
	}
	if (isFull) copyImg.compute(downstream, out);
	else copyImg.compute(Views.interval(Views.translate(downstream,
		minSize[0]), out), out);
}
 
Example #17
Source File: IntegralImgTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * @see DefaultIntegralImg
 * @see SquareIntegralImg
 */
@SuppressWarnings({ "unchecked" })
@Test
public void testIntegralImageSimilarity() {
	RandomAccessibleInterval<LongType> out1 =
		(RandomAccessibleInterval<LongType>) ops.run(DefaultIntegralImg.class,
			in);
	RandomAccessibleInterval<DoubleType> out2 =
		(RandomAccessibleInterval<DoubleType>) ops.run(WrappedIntegralImg.class,
			in);

	// Remove 0s from integralImg by shifting its interval by +1
	final long[] min = new long[out2.numDimensions()];
	final long[] max = new long[out2.numDimensions()];

	for (int d = 0; d < out2.numDimensions(); ++d) {
		min[d] = out2.min(d) + 1;
		max[d] = out2.max(d);
	}

	// Define the Interval on the infinite random accessibles
	final FinalInterval interval = new FinalInterval(min, max);

	LocalThresholdTest.testIterableIntervalSimilarity(Views.iterable(out1),
		Views.iterable(Views.offsetInterval(out2, interval)));
}
 
Example #18
Source File: HistogramOfOrientedGradients2D.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Void call() throws Exception {

	final FinalInterval interval = new FinalInterval(in.dimension(0), in.dimension(1));
	for (int j = 0; j < in.dimension(1); j++) {
		// sum up the magnitudes of all bins in a neighborhood
		raNeighbor.setPosition(new long[] { i, j });
		final Cursor<FloatType> cursorNeighborHood = raNeighbor.get().cursor();
		while (cursorNeighborHood.hasNext()) {
			cursorNeighborHood.next();
			if (Intervals.contains(interval, cursorNeighborHood)) {
				raAngles.setPosition(cursorNeighborHood);
				raMagnitudes.setPosition(cursorNeighborHood);
				raOut.setPosition(new long[] { i, j,
						(int) (raAngles.get().getRealFloat() / (360 / numOrientations) - 0.5) });
				raOut.get().add(raMagnitudes.get());
			}
		}
	}
	return null;
}
 
Example #19
Source File: DefaultCreateKernelGauss.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public RandomAccessibleInterval<T> calculate(double[] input) {
	final double[] sigmaPixels = new double[input.length];

	final long[] dims = new long[input.length];
	final double[][] kernelArrays = new double[input.length][];

	for (int d = 0; d < input.length; d++) {
		sigmaPixels[d] = input[d];

		dims[d] = Math.max(3, (2 * (int) (3 * sigmaPixels[d] + 0.5) + 1));
		kernelArrays[d] = Util.createGaussianKernel1DDouble(sigmaPixels[d], true);
	}

	final RandomAccessibleInterval<T> out = createOp.calculate(new FinalInterval(
		dims));

	final Cursor<T> cursor = Views.iterable(out).cursor();
	while (cursor.hasNext()) {
		cursor.fwd();
		double result = 1.0f;
		for (int d = 0; d < input.length; d++) {
			result *= kernelArrays[d][cursor.getIntPosition(d)];
		}

		cursor.get().setReal(result);
	}

	return out;
}
 
Example #20
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<LongType, LongArray> generateLongArrayTestImg(
	final boolean fill, final long... dims)
{
	final long[] array = new long[(int) Intervals.numElements(new FinalInterval(
		dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (long) (pseudoRandom() / Integer.MAX_VALUE);
		}
	}

	return ArrayImgs.longs(array, dims);
}
 
Example #21
Source File: VolatileHierarchyProjectorPreMultiply.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public VolatileHierarchyProjectorPreMultiply(
		final List<? extends RandomAccessible<A>> sources,
		final Converter<? super A, ARGBType> converter,
		final RandomAccessibleInterval<ARGBType> target,
		final RandomAccessibleInterval<ByteType> mask,
		final int numThreads,
		final ExecutorService executorService)
{
	super(Math.max(2, sources.get(0).numDimensions()), converter, target);

	this.sources.addAll(sources);
	numInvalidLevels = sources.size();

	this.mask = mask;

	iterableTarget = Views.iterable(target);

	target.min(min);
	target.max(max);
	sourceInterval = new FinalInterval(min, max);

	width = (int) target.dimension(0);
	height = (int) target.dimension(1);
	cr = -width;

	this.numThreads = numThreads;
	this.executorService = executorService;

	lastFrameRenderNanoTime = -1;
	clearMask();
}
 
Example #22
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<UnsignedShortType, ShortArray>
	generateUnsignedShortArrayTestImg(final boolean fill, final long... dims)
{
	final short[] array = new short[(int) Intervals.numElements(
		new FinalInterval(dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (short) (pseudoRandom() / Integer.MAX_VALUE);
		}
	}

	return ArrayImgs.unsignedShorts(array, dims);
}
 
Example #23
Source File: MultiResolutionRendererGeneric.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
private static Interval padInterval(final Interval interval, final int[] padding, final int[] imageSize)
{
	final long[] paddedIntervalMin = new long[2], paddedIntervalMax = new long[2];
	Arrays.setAll(paddedIntervalMin, d -> Math.max(interval.min(d) - padding[d], 0));
	Arrays.setAll(paddedIntervalMax, d -> Math.min(interval.max(d) + padding[d], imageSize[d] - 1));
	return new FinalInterval(paddedIntervalMin, paddedIntervalMax);
}
 
Example #24
Source File: ListErode.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public IterableInterval<T> createOutput(final RandomAccessibleInterval<T> in1,
	final List<Shape> in2)
{
	if (isFull) {
		final long[][] maxSize = Morphologies.computeMinSize(in1, in2);
		return imgCreator.calculate(new FinalInterval(maxSize[1]));
	}
	return imgCreator.calculate(in1);
}
 
Example #25
Source File: ListDilate.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public IterableInterval<T> createOutput(final RandomAccessibleInterval<T> in1,
	final List<Shape> in2)
{
	if (isFull) {
		final long[][] minSize = Morphologies.computeMinSize(in1, in2);
		return imgCreator.calculate(new FinalInterval(minSize[1]));
	}
	return imgCreator.calculate(in1);
}
 
Example #26
Source File: Blending.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
/**
 * RealRandomAccess that computes a blending function for a certain {@link Interval}
 * 
 * @param interval - the interval it is defined on (return zero outside of it)
 * @param border - how many pixels to skip before starting blending (on each side of each dimension)
 * @param blending - how many pixels to compute the blending function on (on each side of each dimension)
 */
public Blending( final Interval interval, final float[] border, final float[] blending )
{
	// in case the interval is actually image data re-instantiate just a simple FinalInterval
	this.interval = new FinalInterval( interval );
	this.border = border;
	this.blending = blending;
}
 
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: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<ByteType, ByteArray> generateByteArrayTestImg(
	final boolean fill, final long... dims)
{
	final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(
		dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (byte) pseudoRandom();
		}
	}

	return ArrayImgs.bytes(array, dims);
}
 
Example #29
Source File: AbstractOpTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public ArrayImg<UnsignedByteType, ByteArray> generateUnsignedByteArrayTestImg(
	final boolean fill, final long... dims)
{
	final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(
		dims))];

	if (fill) {
		seed = 17;
		for (int i = 0; i < array.length; i++) {
			array[i] = (byte) pseudoRandom();
		}
	}

	return ArrayImgs.unsignedBytes(array, dims);
}
 
Example #30
Source File: Block.java    From SPIM_Registration with GNU General Public License v2.0 5 votes vote down vote up
private static final void copy3dArray( final int threadIdx, final int numThreads, final RandomAccessible< FloatType > source, final ArrayImg< FloatType, ? > block, final long[] offset )
{
	final int w = (int)block.dimension( 0 );
	final int h = (int)block.dimension( 1 );
	final int d = (int)block.dimension( 2 );

	final long offsetX = offset[ 0 ];
	final long offsetY = offset[ 1 ];
	final long offsetZ = offset[ 2 ];
	final float[] blockArray = ((FloatArray)block.update( null ) ).getCurrentStorageArray();

	// define where we will query the RandomAccess on the source
	final FinalInterval interval = new FinalInterval( new long[] { offsetX, offsetY, offsetZ }, new long[] { offsetX + w - 1, offsetY + h - 1, offsetZ + d - 1 } );
	final RandomAccess< FloatType > randomAccess = source.randomAccess( interval );

	final long[] tmp = new long[]{ offsetX, offsetY, 0 };

	for ( int z = threadIdx; z < d; z += numThreads )
	{
		tmp[ 2 ] = z + offsetZ;
		randomAccess.setPosition( tmp );

		int i = z * h * w;

		for ( int y = 0; y < h; ++y )
		{
			randomAccess.setPosition( offsetX, 0 );

			for ( int x = 0; x < w; ++x )
			{
				blockArray[ i++ ] = randomAccess.get().get();
				randomAccess.fwd( 0 );
			}

			randomAccess.move( -w, 0 );
			randomAccess.fwd( 1 );
		}
	}
}