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

The following examples show how to use net.imglib2.Cursor#getDoublePosition() . 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: DefaultMoment11.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {

	double moment11 = 0;

	final Cursor<I> cur = input.localizingCursor();
	while (cur.hasNext()) {
		cur.fwd();
		double x = cur.getDoublePosition(0);
		double y = cur.getDoublePosition(1);
		double val = cur.get().getRealDouble();
		moment11 += x * y * val;
	}

	output.setReal(moment11);
}
 
Example 2
Source File: DefaultCentralMoment30.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {
	final double moment00 = moment00Func.calculate(input).getRealDouble();
	final double moment10 = moment10Func.calculate(input).getRealDouble();

	final double centerX = moment10 / moment00;

	double centralmoment30 = 0;

	final Cursor<I> it = input.localizingCursor();
	while (it.hasNext()) {
		it.fwd();
		final double x = it.getDoublePosition(0) - centerX;
		final double val = it.get().getRealDouble();

		centralmoment30 += val * x * x * x;
	}

	output.setReal(centralmoment30);
}
 
Example 3
Source File: DefaultCentralMoment21.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {
	final double moment00 = moment00Func.calculate(input).getRealDouble();
	final double moment01 = moment01Func.calculate(input).getRealDouble();
	final double moment10 = moment10Func.calculate(input).getRealDouble();

	final double centerX = moment10 / moment00;
	final double centerY = moment01 / moment00;

	double centralmoment21 = 0;

	final Cursor<I> it = input.localizingCursor();
	while (it.hasNext()) {
		it.fwd();
		final double x = it.getDoublePosition(0) - centerX;
		final double y = it.getDoublePosition(1) - centerY;
		final double val = it.get().getRealDouble();

		centralmoment21 += val * x * x * y;
	}

	output.setReal(centralmoment21);
}
 
Example 4
Source File: DefaultCentralMoment02.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {
	
	final double moment00 = moment00Func.calculate(input).getRealDouble();
	final double moment01 = moment01Func.calculate(input).getRealDouble();
	
	final double centerY = moment01 / moment00;

	double centralmoment02 = 0;

	final Cursor<I> it = input.localizingCursor();
	while (it.hasNext()) {
		it.fwd();
		final double y = it.getDoublePosition(1) - centerY;
		final double val = it.get().getRealDouble();

		centralmoment02 += val * y * y;
	}

	output.setReal(centralmoment02);
}
 
Example 5
Source File: DefaultCentralMoment03.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {
	final double moment00 = moment00Func.calculate(input).getRealDouble();
	final double moment01 = moment01Func.calculate(input).getRealDouble();
	
	final double centerY = moment01 / moment00;

	double centralmoment03 = 0;

	final Cursor<I> it = input.localizingCursor();
	while (it.hasNext()) {
		it.fwd();
		final double y = it.getDoublePosition(1) - centerY;
		final double val = it.get().getRealDouble();

		centralmoment03 += val * y * y * y;
	}

	output.setReal(centralmoment03);
}
 
Example 6
Source File: DefaultCentralMoment20.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {
	final double moment00 = moment00Func.calculate(input).getRealDouble();
	final double moment10 = moment10Func.calculate(input).getRealDouble();

	final double centerX = moment10 / moment00;

	double centralmoment20 = 0;

	final Cursor<I> it = input.localizingCursor();
	while (it.hasNext()) {
		it.fwd();
		final double x = it.getDoublePosition(0) - centerX;
		final double val = it.get().getRealDouble();

		centralmoment20 += val * x * x;
	}

	output.setReal(centralmoment20);
}
 
Example 7
Source File: IterableCentralMoment11.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {
	double moment00 = 0d;
	double moment01 = 0d;
	double moment10 = 0d;
	double moment11 = 0d;

	final Cursor<I> cursor = input.localizingCursor();
	while (cursor.hasNext()) {
		cursor.fwd();
		final double x = cursor.getDoublePosition(0);
		final double y = cursor.getDoublePosition(1);
		final double val = cursor.get().getRealDouble();

		moment00 += val;
		moment01 += y * val;
		moment10 += x * val;
		moment11 += x * y * val;
	}

	double centerx = moment10 / moment00;
	output.setReal(moment11 - (centerx * moment01));
}
 
Example 8
Source File: DefaultCentralMoment12.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {
	final double moment00 = moment00Func.calculate(input).getRealDouble();
	final double moment01 = moment01Func.calculate(input).getRealDouble();
	final double moment10 = moment10Func.calculate(input).getRealDouble();
	final double centerX = moment10 / moment00;
	final double centerY = moment01 / moment00;

	double centralmoment12 = 0;

	final Cursor<I> it = input.localizingCursor();
	while (it.hasNext()) {
		it.fwd();
		final double x = it.getDoublePosition(0) - centerX;
		final double y = it.getDoublePosition(1) - centerY;
		final double val = it.get().getRealDouble();

		centralmoment12 += val * x * y * y;
	}

	output.setReal(centralmoment12);
}
 
Example 9
Source File: DefaultCenterOfGravity.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public RealLocalizable calculate(final IterableInterval<T> input) {
	final int numDimensions = input.numDimensions();

	final double[] output = new double[numDimensions];
	final double[] intensityValues = new double[numDimensions];

	final Cursor<T> c = input.localizingCursor();
	while (c.hasNext()) {
		c.fwd();
		for (int i = 0; i < output.length; i++) {
			output[i] += c.getDoublePosition(i) * c.get().getRealDouble();
			intensityValues[i] += c.get().getRealDouble();
		}
	}

	for (int i = 0; i < output.length; i++) {
		output[i] = output[i] / intensityValues[i];
	}

	return new RealPoint(output);
}
 
Example 10
Source File: DefaultMoment10.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {

	double moment10 = 0;

	final Cursor<I> cur = input.localizingCursor();
	while (cur.hasNext()) {
		cur.fwd();
		double x = cur.getDoublePosition(0);
		double val = cur.get().getRealDouble();
		moment10 += x * val;
	}

	output.setReal(moment10);
}
 
Example 11
Source File: DefaultMoment01.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final IterableInterval<I> input, final O output) {

	double moment01 = 0;

	final Cursor<I> cur = input.localizingCursor();
	while (cur.hasNext()) {
		cur.fwd();
		double y = cur.getDoublePosition(1);
		double val = cur.get().getRealDouble();
		moment01 += y * val;
	}

	output.setReal(moment01);
}
 
Example 12
Source File: TestImageAccessor.java    From Colocalisation_Analysis with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Generates a Perlin noise image. It is based on Ken Perlin's
 * reference implementation (ImprovedNoise class) and a small
 * bit of Kas Thomas' sample code (http://asserttrue.blogspot.com/).
 */
public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> producePerlinNoiseImage(T type, int width,
		int height, double z, double scale) {
	// create the new image
	ImgFactory<T> imgFactory = new ArrayImgFactory<T>();
	RandomAccessibleInterval<T> noiseImage = imgFactory.create( new int[] {width, height}, type);
	Cursor<T> noiseCursor = Views.iterable(noiseImage).localizingCursor();

	double xOffset = Math.random() * (width*width);
	double yOffset = Math.random() * (height*height);

	while (noiseCursor.hasNext()) {
		noiseCursor.fwd();
		double x = (noiseCursor.getDoublePosition(0) + xOffset) * scale;
		double y = (noiseCursor.getDoublePosition(1) + yOffset) * scale;

		float t = (float)ImprovedNoise.noise( x, y, z);

		// ImprovedNoise.noise returns a float in the range [-1..1],
		// whereas we want a float in the range [0..1], so:
                       t = (1 + t) * 0.5f;

                       noiseCursor.get().setReal(t);
	}

	//return gaussianSmooth(noiseImage, imgFactory, smoothingSigma);
	return noiseImage;
}