Java Code Examples for net.imglib2.type.numeric.real.DoubleType#set()

The following examples show how to use net.imglib2.type.numeric.real.DoubleType#set() . 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: DefaultSumVariance.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<T> input,
	final DoubleType output)
{
	final double[][] matrix = getCooccurrenceMatrix(input);

	final double[] pxplusy = coocPXPlusYFunc.calculate(matrix);
	final int nrGrayLevels = matrix.length;
	final double sumEntropy = sumEntropyFunc.calculate(input).getRealDouble();

	double res = 0;
	for (int i = 2; i <= 2 * nrGrayLevels; i++) {
		res += (i - sumEntropy) * (i - sumEntropy) * pxplusy[i];
	}

	output.set(res);
}
 
Example 2
Source File: InterpolateViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultInterpolateTest() {
	
	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());
	}
	
	RealRandomAccess<DoubleType> il2 = Views.interpolate(img, new FloorInterpolatorFactory<DoubleType>()).realRandomAccess();
	RealRandomAccess<DoubleType> opr = ops.transform().interpolateView(img, new FloorInterpolatorFactory<DoubleType>()).realRandomAccess();
	
	il2.setPosition(new double[]{1.75, 5.34});
	opr.setPosition(new double[]{1.75, 5.34});
	assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	
	il2.setPosition(new double[]{3, 7});
	opr.setPosition(new double[]{3, 7});
	assertEquals(il2.get().get(), opr.get().get(), 1e-10);
	
	il2.setPosition(new double[]{8.37, 3.97});
	opr.setPosition(new double[]{8.37, 3.97});
	assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
 
Example 3
Source File: OpServiceTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/** Tests {@link OpService#run(String, Object...)} with op aliases. */
@Test
public void testAliases() {
	final DoubleType value = new DoubleType(123.456);

	assertFalse(Double.isInfinite(value.get()));
	final Object result = ops.run("infin", value);
	assertSame(value, result);
	assertTrue(Double.isInfinite(value.get()));

	value.set(0.0);
	assertFalse(Double.isInfinite(value.get()));
	final Object result2 = ops.run("inf", value);
	assertSame(value, result2);
	assertTrue(Double.isInfinite(value.get()));

	value.set(0.0);
	boolean noSuchAlias = false;
	try {
		ops.run("infini", value);
	}
	catch (final IllegalArgumentException exc) {
		noSuchAlias = true;
	}
	assertTrue(noSuchAlias);
}
 
Example 4
Source File: EulerCharacteristic26N.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(RandomAccessibleInterval<B> interval, DoubleType output) {
    final RandomAccess<B> access = interval.randomAccess();
    long sumDeltaEuler = 0;

    for (long z = 0; z < interval.dimension(2) - 1; z++) {
        for (long y = 0; y < interval.dimension(1) - 1; y++) {
            for (long x = 0; x < interval.dimension(0) - 1; x++) {
                int index = neighborhoodEulerIndex(access, x, y, z);
                sumDeltaEuler += EULER_LUT[index];
            }
        }
    }

    output.set(sumDeltaEuler / 8.0);
}
 
Example 5
Source File: SubsampleViewTest.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Test
public void defaultSubsampleTest() {
	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());
	}

	SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2);
	SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2);

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

	while (il2C.hasNext()) {
		il2C.next();
		oprRA.setPosition(il2C);
		assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
	}
}
 
Example 6
Source File: DefaultICM2.java    From imagej-ops with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void compute(final IterableInterval<T> input,
	final DoubleType output)
{
	final double[][] matrix = getCooccurrenceMatrix(input);

	double res = 0;
	final double[] coochxy = coocHXYFunc.calculate(matrix);
	res = Math.sqrt(1 - Math.exp(-2 * (coochxy[3] - entropy.calculate(input)
		.get())));

	// if NaN
	if (Double.isNaN(res)) {
		output.set(0);
	}
	else {
		output.set(res);
	}
}
 
Example 7
Source File: DefaultCompactness.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Mesh input, final DoubleType output) {
	final double s3 = Math.pow(surfaceArea.calculate(input).get(), 3);
	final double v2 = Math.pow(volume.calculate(input).get(), 2);
	final double c = s3 / v2;
	output.set((36.0 * Math.PI) / c);
}
 
Example 8
Source File: DefaultSurfaceArea.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Mesh input, final DoubleType output) {
	double total = 0;
	for (final Triangle tri : input.triangles()) {
		final Vector3D v0 = new Vector3D(tri.v0x(), tri.v0y(), tri.v0z());
		final Vector3D v1 = new Vector3D(tri.v1x(), tri.v1y(), tri.v1z());
		final Vector3D v2 = new Vector3D(tri.v2x(), tri.v2y(), tri.v2z());

		final Vector3D cross = v0.subtract(v1).crossProduct(v2.subtract(v0));
		final double norm = cross.getNorm();
		if (norm > 0) total += norm * 0.5;
	}
	output.set(total);
}
 
Example 9
Source File: DefaultEntropy.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final IterableInterval<T> input, final DoubleType output) {
	final double[][] matrix = getCooccurrenceMatrix(input);
	double res = 0;

	final int nrGrayLevels = matrix.length;

	for (int i = 0; i < nrGrayLevels; i++) {
		for (int j = 0; j < nrGrayLevels; j++) {
			res += matrix[i][j] * Math.log(matrix[i][j] + EPSILON);
		}
	}

	output.set(-res);
}
 
Example 10
Source File: DefaultICM1.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final IterableInterval<T> input,
	final DoubleType output)
{
	final double[][] matrix = getCooccurrenceMatrix(input);

	final double[] coochxy = coocHXYFunc.calculate(matrix);

	final double res = (entropy.calculate(input).get() - coochxy[2]) / (coochxy[0] > coochxy[1]
		? coochxy[0] : coochxy[1]);

	output.set(res);
}
 
Example 11
Source File: DefaultFeretsDiameter.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Pair<RealLocalizable, RealLocalizable> input, final DoubleType output) {

	final RealLocalizable p1 = input.getA();
	final RealLocalizable p2 = input.getB();

	output.set(Math.hypot(p1.getDoublePosition(0) - p2.getDoublePosition(0),
			p1.getDoublePosition(1) - p2.getDoublePosition(1)));
}
 
Example 12
Source File: DefaultSumAverage.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final IterableInterval<T> input,
	final DoubleType output)
{
	final double[][] matrix = getCooccurrenceMatrix(input);
	final double[] pxplusy = coocPXPlusFunc.calculate(matrix);

	final int nrGrayLevels = matrix.length;

	double res = 0;
	for (int i = 2; i <= 2 * nrGrayLevels; i++) {
		res += i * pxplusy[i];
	}
	output.set(res);
}
 
Example 13
Source File: DefaultTubeness.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final Iterable<DoubleType> input,
	final DoubleType output)
{
	// Use the two largest ones.
	final Iterator<DoubleType> it = input.iterator();
	it.next();
	final double val1 = it.next().get();
	final double val2 = it.next().get();
	if (val1 >= 0. || val2 >= 0.) output.setZero();
	else output.set(sigma * sigma * Math.sqrt(val1 * val2));

}
 
Example 14
Source File: DefaultSumEntropy.java    From imagej-ops with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void compute(final IterableInterval<T> input, final DoubleType output) {
	final double[][] matrix = getCooccurrenceMatrix(input);
	final double[] pxplusy = coocPXPlusFunc.calculate(matrix);
	final int nrGrayLevels = matrix.length;

	double res = 0;
	for (int i = 2; i <= 2 * nrGrayLevels; i++) {
		res += pxplusy[i] * Math.log(pxplusy[i] + EPSILON);
	}

	output.set(-res);
}
 
Example 15
Source File: DefaultVerticesCountMesh.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final Mesh input, final DoubleType output) {
	output.set(input.vertices().size());
}
 
Example 16
Source File: DefaultMaximumFeretDiameter.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(Polygon2D input, DoubleType output) {
	output.set(feretDiameter.calculate(maxFeret.calculate(input)).get());
}
 
Example 17
Source File: AbstractSizeConvexHull.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final I input, final DoubleType output) {
	output.set(sizeFunc.calculate(convexHullFunc.calculate(input)));
}
 
Example 18
Source File: AbstractSolidity.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final I input, final DoubleType output) {
	output.set(volume.calculate(input).get() / convexHullVolume.calculate(input).get());
}
 
Example 19
Source File: DefaultSphericity.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(final Mesh input, final DoubleType output) {
	final double sphereArea = Math.pow(Math.PI, 1 / 3d) * Math.pow(6 * volumeFunc.calculate(input).get(), 2 / 3d);
	output.set(sphereArea / areaFunc.calculate(input).get());
}
 
Example 20
Source File: AbstractBoundarySizeConvexHull.java    From imagej-ops with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void compute(I input, DoubleType output) {
	output.set(perimeterFunc.calculate(convexHullFunc.calculate(input)));
}