net.imglib2.type.numeric.real.DoubleType Java Examples
The following examples show how to use
net.imglib2.type.numeric.real.DoubleType.
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: LocalMeanThresholdIntegral.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final I center, final RectangleNeighborhood<Composite<DoubleType>> neighborhood, final BitType output) { final DoubleType sum = new DoubleType(); integralMean.compute(neighborhood, sum); // Subtract the contrast sum.sub(new DoubleType(c)); // Set value final Converter<I, DoubleType> conv = new RealDoubleConverter<>(); final DoubleType centerPixelAsDoubleType = new DoubleType(); conv.convert(center, centerPixelAsDoubleType); output.set(centerPixelAsDoubleType.compareTo(sum) > 0); }
Example #2
Source File: PermuteViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@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 #3
Source File: DefaultTextureHomogeneity.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final IterableInterval<T> input, final DoubleType output) { final double[][] matrix = getCooccurrenceMatrix(input); final double nrGreyLevel = matrix.length; double res = 0; for (int i = 0; i < nrGreyLevel; i++) { for (int j = 0; j < nrGreyLevel; j++) { res += matrix[i][j] / (1 + Math.abs(i - j)); } } output.set(res); }
Example #4
Source File: TranslateViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIntervalTranslate() { Img<DoubleType> img = ArrayImgs.doubles(10,10); IntervalView<DoubleType> expected = Views.translate(img, 2, 5); IntervalView<DoubleType> actual = ops.transform().translateView(img, 2, 5); for (int i = 0; i < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix().length; i++) { for (int j = 0; j < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i].length; j++) { assertEquals(((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i][j], ((MixedTransformView<DoubleType>) actual.getSource()).getTransformToSource().getMatrix()[i][j], 1e-10); } } assertTrue(Intervals.equals(expected, actual)); }
Example #5
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testAllBackground() throws Exception { // SETUP final double expectedCount = Math.log(0.0); final Img<BitType> img = ArrayImgs.bits(TEST_DIMS); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, MAX_SIZE, MIN_SIZE, SCALING); // VERIFY assertNotNull(points); assertEquals(ITERATIONS, points.size()); for (int i = 0; i < ITERATIONS; i++) { assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12); assertEquals(expectedCount, points.get(i).b.get(), 1e-12); } }
Example #6
Source File: EulerCharacteristic26N.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@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 #7
Source File: AffineWarpFieldTransform.java From render with GNU General Public License v2.0 | 6 votes |
/** * Appends serialization of this transform's offsets and warp field to the specified data string. * * @param data target data string. */ private void serializeWarpField(final StringBuilder data) { data.append(locationOffsets[0]).append(' ').append(locationOffsets[1]).append(' '); data.append(affineWarpField.getWidth()).append(' ').append(affineWarpField.getHeight()).append(' '); data.append(affineWarpField.getRowCount()).append(' ').append(affineWarpField.getColumnCount()).append(' '); final InterpolatorFactory<RealComposite<DoubleType>, RandomAccessible<RealComposite<DoubleType>>> factory = affineWarpField.getInterpolatorFactory(); data.append(factory.getClass().getCanonicalName()).append(' '); final double[] values = affineWarpField.getValues(); if (values.length < 64) { // skip encoding for smaller fields to simplify visual inspection and testing data.append(NO_ENCODING); for (final double value : values) { data.append(' ').append(value); } } else { data.append(BASE_64_ENCODING).append(' ').append(DoubleArrayConverter.encodeBase64(values)); } }
Example #8
Source File: AbstractIntegralImg.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void initialize() { if (in() != null) { slicewiseOps = new UnaryComputerOp[in().numDimensions()]; for (int i = 0; i < in().numDimensions(); ++i) { slicewiseOps[i] = Computers.unary(ops(), Slice.class, RandomAccessibleInterval.class, RandomAccessibleInterval.class, getComputer(i), i); } } createLongRAI = Functions.unary(ops(), Ops.Create.Img.class, RandomAccessibleInterval.class, Dimensions.class, new LongType()); createDoubleRAI = Functions.unary(ops(), Ops.Create.Img.class, RandomAccessibleInterval.class, Dimensions.class, new DoubleType()); }
Example #9
Source File: KendallTauTest.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
@Test public void exhaustiveTesting() throws Exception { assumeTrue(exhaustive); final int n = 5, m = 10; final int[] values1 = new int[n], values2 = new int[n]; for (int i = 0; i < 100; i++) { for (int j = 0; j < n; j++) { values1[j] = Math.abs(pseudoRandom()) % m; values2[j] = Math.abs(pseudoRandom()) % m; } final PairIterator<DoubleType> iter = pairIterator(values1, values2); double value1 = KendallTauRankCorrelation.calculateNaive(iter); iter.reset(); double value2 = KendallTauRankCorrelation.calculateMergeSort(iter); if (Double.isNaN(value1)) { assertTrue("i: " + i + ", value2: " + value2, Double.isInfinite(value2) || Double.isNaN(value2)); } else { assertEquals("i: " + i, value1, value2, 1e-10); } } }
Example #10
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Test box counting with a hyper cube and one grid translation (should find a * better fit than in @see {@link #testHyperCube()}) */ @Test public void testHyperCubeTranslations() { final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log( i)).toArray(); final double[] expectedCounts = DoubleStream.of(1, 1, 16).map(Math::log) .toArray(); final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4); final IntervalView<BitType> hyperView = Views.offsetInterval(img, new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 }); hyperView.forEach(BitType::setOne); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, 4L, 1L, 2.0, 1L); // VERIFY for (int i = 0; i < expectedSizes.length; i++) { assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12); assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12); } }
Example #11
Source File: DefaultDifferenceVariance.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final IterableInterval<T> input, final DoubleType output) { final double[][] matrix = getCooccurrenceMatrix(input); final double[] pxminusy = coocPXMinusYFunc.calculate(matrix); double mu = 0.0; for (int i = 0; i < numGreyLevels; i++) { mu += i * pxminusy[i]; } double sum = 0.0d; for (int k = 0; k < numGreyLevels; k++) { sum += Math.pow(k - mu, 2) * pxminusy[k]; } output.set(sum); }
Example #12
Source File: UnshearViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void defaultUnshearTest() { 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); } TransformView<DoubleType> il2 = Views.unshear(Views.shear(Views.extendZero(img), 0, 1), 0, 1); TransformView<DoubleType> opr = ops.transform().unshearView(Views.shear(Views.extendZero(img), 0, 1), 0, 1); Cursor<DoubleType> il2C = Views.interval(il2, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })) .cursor(); RandomAccess<DoubleType> oprRA = Views .interval(opr, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })).randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } }
Example #13
Source File: IntervalViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@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 #14
Source File: ShearViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** Tests {@link DefaultShearView}. */ @Test public void defaultShearTest() { 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); } TransformView<DoubleType> il2 = Views.shear(Views.extendZero(img), 0, 1); TransformView<DoubleType> opr = ops.transform().shearView(Views.extendZero(img), 0, 1); Cursor<DoubleType> il2C = Views.interval(il2, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })) .cursor(); RandomAccess<DoubleType> oprRA = Views .interval(opr, new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 })).randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } }
Example #15
Source File: CreateNativeTypeTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testCreateNativeType() { // default Object type = ops.run(DefaultCreateNativeType.class); assertEquals(type.getClass(), DoubleType.class); // FloatType type = ops.run(CreateNativeTypeFromClass.class, FloatType.class); assertEquals(type.getClass(), FloatType.class); // ComplexFloatType type = ops.run(CreateNativeTypeFromClass.class, ComplexFloatType.class); assertEquals(type.getClass(), ComplexFloatType.class); // DoubleType type = ops.run(CreateNativeTypeFromClass.class, DoubleType.class); assertEquals(type.getClass(), DoubleType.class); // ComplexDoubleType type = ops.run(CreateNativeTypeFromClass.class, ComplexDoubleType.class); assertEquals(type.getClass(), ComplexDoubleType.class); }
Example #16
Source File: CreateKernelGaussSymmetricDoubleType.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override @SuppressWarnings({ "rawtypes", "unchecked" }) public UnaryFunctionOp<Double, RandomAccessibleInterval<DoubleType>> createWorker(final Double t) { return (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.KernelGauss.class, RandomAccessibleInterval.class, Double.class, numDims, new DoubleType()); }
Example #17
Source File: UnaryRealTypeMathTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testArcsech() { final LongType in = new LongType(1234567890); final DoubleType out = new DoubleType(); ops.run(Arcsech.class, out, in); final double numer = 1 + Math.sqrt(1 - 1234567890.0 * 1234567890.0); assertEquals(out.get(), Math.log(numer / 1234567890.0), 0.0); }
Example #18
Source File: UnaryRealTypeMathTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testArccot() { final LongType in = new LongType(1234567890); final DoubleType out = new DoubleType(); ops.run(Arccot.class, out, in); assertEquals(out.get(), Math.atan(1.0 / 1234567890), 0.0); }
Example #19
Source File: DefaultVolumeMesh.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public DoubleType calculate(final Mesh input) { double volume = 0; for (final Triangle triangle : input.triangles()) { volume += signedVolumeOfTriangle(// triangle.v0x(), triangle.v0y(), triangle.v0z(), // triangle.v1x(), triangle.v1y(), triangle.v1z(), // triangle.v2x(), triangle.v2y(), triangle.v2z()); } return new DoubleType(Math.abs(volume)); }
Example #20
Source File: LocalSauvolaThresholdIntegral.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings("unchecked") @Override protected CenterAwareIntegralComputerOp<T, BitType> unaryComputer() { final CenterAwareIntegralComputerOp<T, BitType> op = new LocalSauvolaThresholdComputer<>(ops().op(IntegralMean.class, DoubleType.class, RectangleNeighborhood.class), ops() .op(IntegralVariance.class, DoubleType.class, RectangleNeighborhood.class)); op.setEnvironment(ops()); return op; }
Example #21
Source File: UnaryRealTypeMathTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testCos() { final LongType in = new LongType(1234567890); final DoubleType out = new DoubleType(); ops.run(Cos.class, out, in); assertEquals(out.get(), Math.cos(1234567890), 0.0); }
Example #22
Source File: UnaryRealTypeMathTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testUlp() { final LongType in = new LongType(LARGE_NUM); final DoubleType out = new DoubleType(); ops.run(Ulp.class, out, in); assertEquals(out.get(), 2.0, 0.0); }
Example #23
Source File: DefaultDerivativeGaussTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test(expected = IllegalArgumentException.class) public void testImgParamDimensionsMismatch() { final Img<DoubleType> input = ops.convert().float64( generateFloatArrayTestImg(false, 30, 30, 30)); final Img<DoubleType> output = ops.create().img(input); final int[] derivatives = new int[] { 1, 0 }; final double[] sigmas = new double[] { 1, 1 }; ops.filter().derivativeGauss(output, input, derivatives, sigmas); }
Example #24
Source File: CoocMeanY.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public DoubleType calculate(double[][] input) { double res = 0; final double[] py = coocPYFunc.calculate(input); for (int i = 0; i < py.length; i++) { res += i * py[i]; } return new DoubleType(res); }
Example #25
Source File: CoocStdY.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void initialize() { super.initialize(); coocMeanYFunc = Functions.unary(ops(), CoocMeanY.class, DoubleType.class, double[][].class); coocPYFunc = Functions.unary(ops(), CoocPY.class, double[].class, double[][].class); }
Example #26
Source File: CopyIITest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Before public void createData() { input = new PlanarImgFactory<DoubleType>().create( new int[] { 120, 100 }, new DoubleType()); final MersenneTwisterFast r = new MersenneTwisterFast(System.currentTimeMillis()); final Cursor<DoubleType> inc = input.cursor(); while (inc.hasNext()) { inc.next().set(r.nextDouble()); } }
Example #27
Source File: CreateNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Convenience wrapper to create an {@link Img} of type {@link DoubleType} * with an isotropic Gabor kernel. */ @OpMethod( op = net.imagej.ops.create.kernelGabor.CreateKernelGaborIsotropicDoubleType.class) public RandomAccessibleInterval<DoubleType> kernelGaborDouble(final Double sigma, final double... period) { @SuppressWarnings("unchecked") final RandomAccessibleInterval<DoubleType> result = (RandomAccessibleInterval<DoubleType>) ops().run( net.imagej.ops.create.kernelGabor.CreateKernelGaborIsotropicDoubleType.class, sigma, period); return result; }
Example #28
Source File: HaralickNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@OpMethod(op = net.imagej.ops.features.haralick.DefaultASM.class) public <T extends RealType<T>> DoubleType asm(final IterableInterval<T> in, final int numGreyLevels, final int distance, final MatrixOrientation orientation) { final DoubleType result = (DoubleType) ops().run( net.imagej.ops.Ops.Haralick.ASM.class, in, numGreyLevels, distance, orientation); return result; }
Example #29
Source File: IO.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * @deprecated Use {@link #openAllDouble(String)}. */ @Deprecated public static List<SCIFIOImgPlus<DoubleType>> openDoubleImgs( final String source) { return openAllDouble(source); }
Example #30
Source File: UnaryRealTypeMathTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testSec() { final LongType in = new LongType(1234567890); final DoubleType out = new DoubleType(); ops.run(Sec.class, out, in); assertEquals(out.get(), 1 / Math.cos(1234567890), 0.0); }