Java Code Examples for net.imglib2.Cursor#getLongPosition()

The following examples show how to use net.imglib2.Cursor#getLongPosition() . 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: RidgeDetectionUtils.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
protected static long[] getMaxCoords(
	RandomAccessibleInterval<DoubleType> input, boolean useAbsoluteValue)
{
	long[] dims = new long[input.numDimensions()];
	double max = Double.MIN_VALUE;
	Cursor<DoubleType> cursor = Views.iterable(input).localizingCursor();
	while (cursor.hasNext()) {
		cursor.fwd();
		double current = useAbsoluteValue ? Math.abs(cursor.get().get()) : cursor
			.get().get();
		if (current > max) {
			max = current;
			for (int d = 0; d < input.numDimensions(); d++) {
				dims[d] = cursor.getLongPosition(d);
			}
		}
	}
	return dims;
}
 
Example 2
Source File: DefaultFillHoles.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final RandomAccessibleInterval<T> op,
	final RandomAccessibleInterval<T> r)
{
	final IterableInterval<T> iterOp = Views.flatIterable(op);
	final IterableInterval<T> iterR = Views.flatIterable(r);

	long[] dim = new long[r.numDimensions()];
	r.dimensions(dim);
	Cursor<T> rc = iterR.cursor();
	Cursor<T> opc = iterOp.localizingCursor();
	// Fill with non background marker
	while (rc.hasNext()) {
		rc.next().setOne();
	}

	rc.reset();
	boolean border;
	// Flood fill from every background border voxel
	while (rc.hasNext()) {
		rc.next();
		opc.next();
		if (rc.get().get() && !opc.get().get()) {
			border = false;
			for (int i = 0; i < r.numDimensions(); i++) {
				if (rc.getLongPosition(i) == 0 || rc.getLongPosition(i) == dim[i] -
					1)
				{
					border = true;
					break;
				}
			}
			if (border) {
				floodFillComp.compute(op, rc, r);
			}
		}
	}
}
 
Example 3
Source File: DefaultDerivativeGauss.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Convolves the rows of the image
 *
 * @param input - The input image.
 * @param output - The output image.
 * @param mask - The mask needed for the convolution, determined beforehand.
 */
private <T extends RealType<T>> void convolve_n(
	final RandomAccessibleInterval<T> input,
	final RandomAccessibleInterval<DoubleType> output, final double[] mask,
	final int n)
{
	double sum;
	final Cursor<T> cursor = Views.iterable(input).localizingCursor();
	final OutOfBoundsMirrorFactory<T, RandomAccessibleInterval<T>> osmf =
		new OutOfBoundsMirrorFactory<>(Boundary.SINGLE);
	final RandomAccess<T> inputRA = osmf.create(input);
	final RandomAccess<DoubleType> outputRA = output.randomAccess();

	while (cursor.hasNext()) {
		cursor.fwd();
		inputRA.setPosition(cursor);
		outputRA.setPosition(cursor);
		sum = 0;
		// loop from the bottom of the image to the top
		final int halfWidth = mask.length / 2;
		for (int i = -halfWidth; i <= halfWidth; i++) {
			for (int dim = 0; dim < input.numDimensions(); dim++) {
				long position = cursor.getLongPosition(dim);
				if (dim == n) position += i;
				inputRA.setPosition(position, dim);
			}
			sum += inputRA.get().getRealDouble() * mask[i + halfWidth];
		}
		outputRA.get().setReal(sum);
	}
}
 
Example 4
Source File: Coloc_2.java    From Colocalisation_Analysis with GNU General Public License v3.0 5 votes vote down vote up
private RandomAccessibleInterval<T> project(
	final RandomAccessibleInterval<T> image)
{
	if (image.numDimensions() < 2) {
		throw new IllegalArgumentException("Dimensionality too small: " + //
			image.numDimensions());
	}

	final IterableInterval<T> input = Views.iterable(image);
	final T type = input.firstElement(); // e.g. unsigned 8-bit
	final long xLen = image.dimension(0);
	final long yLen = image.dimension(1);

	// initialize output image with minimum value of the pixel type
	final long[] outputDims = { xLen, yLen };
	final Img<T> output = new ArrayImgFactory<T>().create(outputDims, type);
	for (final T sample : output) {
		sample.setReal(type.getMinValue());
	}

	// loop over the input image, performing the max projection
	final Cursor<T> inPos = input.localizingCursor();
	final RandomAccess<T> outPos = output.randomAccess();
	while (inPos.hasNext()) {
		final T inPix = inPos.next();
		final long xPos = inPos.getLongPosition(0);
		final long yPos = inPos.getLongPosition(1);
		outPos.setPosition(xPos, 0);
		outPos.setPosition(yPos, 1);
		final T outPix = outPos.get();
		if (outPix.compareTo(inPix) < 0) {
			outPix.set(inPix);
		}
	}
	return output;
}