Java Code Examples for net.imglib2.img.array.ArrayImgs#doubles()
The following examples show how to use
net.imglib2.img.array.ArrayImgs#doubles() .
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: MTKTTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMTKTpValueAll() { double[][] values = new double[10][2]; double[] values1 = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 }; double[] values2 = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 }; for (int i = 0; i < 4; i++) { values[i][0] = values1[i]; values[i][1] = values2[i]; } Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length); Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length); BinaryFunctionOp<RandomAccessibleInterval<DoubleType>, RandomAccessibleInterval<DoubleType>, Double> op = Functions.binary(ops, MTKT.class, Double.class, vImage1, vImage2); PValueResult value = (PValueResult) ops.run(Ops.Coloc.PValue.class, new PValueResult(), vImage1, vImage2, op, 5); assertEquals(0.0, value.getPValue(), 0.0); }
Example 2
Source File: MTKTTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMTKTpValueNone() { double[][] values = new double[10][2]; double[] values1 = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; double[] values2 = { 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 }; for (int i = 0; i < 4; i++) { values[i][0] = values1[i]; values[i][1] = values2[i]; } Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length); Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length); BinaryFunctionOp<RandomAccessibleInterval<DoubleType>, RandomAccessibleInterval<DoubleType>, Double> op = Functions.binary(ops, MTKT.class, Double.class, vImage1, vImage2); PValueResult value = (PValueResult) ops.run(Ops.Coloc.PValue.class, new PValueResult(), vImage1, vImage2, op, 5); assertEquals(0.0, value.getPValue(), 0.0); }
Example 3
Source File: AffineWarpField.java From render with GNU General Public License v2.0 | 6 votes |
/** * Logic stolen from * <a href='https://github.com/trakem2/TrakEM2/blob/master/TrakEM2_/src/main/java/org/janelia/intensity/LinearIntensityMap.java'> * TrakEM2 LinearIntensityMap * </a>. * * @return an accessor for deriving warped pixel intensities. */ public RealRandomAccess<RealComposite<DoubleType>> getAccessor() { final ArrayImg<DoubleType, DoubleArray> warpField = ArrayImgs.doubles(values, columnCount, rowCount, VALUES_PER_AFFINE); final CompositeIntervalView<DoubleType, RealComposite<DoubleType>> collapsedSource = Views.collapseReal(warpField); final RandomAccessible<RealComposite<DoubleType>> extendedCollapsedSource = Views.extendBorder(collapsedSource); final RealRandomAccessible<RealComposite<DoubleType>> coefficients = Views.interpolate(extendedCollapsedSource, interpolatorFactory); final double xScale = getXScale(); final double yScale = getYScale(); final double[] scale = { xScale, yScale }; final double[] shift = { 0.5 * xScale , 0.5 * yScale }; final ScaleAndTranslation scaleAndTranslation = new ScaleAndTranslation(scale, shift); final RealRandomAccessible<RealComposite<DoubleType>> stretchedCoefficients = RealViews.transform(coefficients, scaleAndTranslation); return stretchedCoefficients.realRandomAccess(); }
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: PermuteViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIntervalPermuteCoordinates() { Img<DoubleType> img = ArrayImgs.doubles(2, 2); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } IntervalView<DoubleType> expected = Views.permuteCoordinates(img, new int[]{0, 1}); Cursor<DoubleType> e = expected.cursor(); RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}); RandomAccess<DoubleType> actualRA = actual.randomAccess(); while (e.hasNext()) { e.next(); actualRA.setPosition(e); assertEquals(e.get().get(), actualRA.get().get(), 1e-10); } assertTrue(Intervals.equals(expected, actual)); }
Example 6
Source File: PermuteViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIntervalPermuteDimensionCoordinates() { Img<DoubleType> img = ArrayImgs.doubles(2, 2); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } IntervalView<DoubleType> expected = Views.permuteCoordinates(img, new int[]{0, 1}, 1); Cursor<DoubleType> e = expected.cursor(); RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}, 1); RandomAccess<DoubleType> actualRA = actual.randomAccess(); while (e.hasNext()) { e.next(); actualRA.setPosition(e); assertEquals(e.get().get(), actualRA.get().get(), 1e-10); } assertTrue(Intervals.equals(expected, actual)); }
Example 7
Source File: PermuteViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIntervalPermuteInverseCoordinates() { Img<DoubleType> img = ArrayImgs.doubles(2, 2); Cursor<DoubleType> c = img.cursor(); MersenneTwisterFast r = new MersenneTwisterFast(SEED); while (c.hasNext()) { c.next().set(r.nextDouble()); } IntervalView<DoubleType> expected = Views.permuteCoordinatesInverse(img, new int[]{0, 1}); Cursor<DoubleType> e = expected.cursor(); RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}); RandomAccess<DoubleType> actualRA = actual.randomAccess(); while (e.hasNext()) { e.next(); actualRA.setPosition(e); assertEquals(e.get().get(), actualRA.get().get(), 1e-10); } assertTrue(Intervals.equals(expected, actual)); }
Example 8
Source File: RotateViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIntervalRotate() { final Img<DoubleType> img = ArrayImgs.doubles(20,10); final IntervalView<DoubleType> il2 = Views.rotate((RandomAccessibleInterval<DoubleType>) img, 1, 0); final IntervalView<DoubleType> opr = (IntervalView<DoubleType>) ops.transform().rotateView((RandomAccessibleInterval<DoubleType>) img, 1, 0); for (int i = 0; i < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource() .getMatrix().length; i++) { for (int j = 0; j < ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource() .getMatrix()[i].length; j++) { assertEquals( ((MixedTransformView<DoubleType>) il2.getSource()).getTransformToSource().getMatrix()[i][j], ((MixedTransformView<DoubleType>) opr.getSource()).getTransformToSource().getMatrix()[i][j], 1e-10); } } }
Example 9
Source File: SubsampleViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIntervalSubsample() { Img<DoubleType> img = ArrayImgs.doubles(10, 10); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } SubsampleIntervalView<DoubleType> expected = Views.subsample((RandomAccessibleInterval<DoubleType>) img, 2); SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2); Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 4 }).localizingCursor(); RandomAccess<DoubleType> oprRA = actual.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } assertTrue(Intervals.equals(expected, actual)); }
Example 10
Source File: SubsampleViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIntervalSubsampleSteps() { Img<DoubleType> img = ArrayImgs.doubles(10,10); MersenneTwisterFast r = new MersenneTwisterFast(SEED); for (DoubleType d : img) { d.set(r.nextDouble()); } SubsampleIntervalView<DoubleType> expected = Views.subsample((RandomAccessibleInterval<DoubleType>) img, 2, 1); SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2, 1); Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor(); RandomAccess<DoubleType> oprRA = actual.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } assertTrue(Intervals.equals(expected, actual)); }
Example 11
Source File: MTKTTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testRankTransformationNoTie() { double[][] values = new double[4][2]; double[] values1 = { 2.1, 1.2, 3.3, 4.6 }; double[] values2 = { 2.1, 1.2, 3.3, 4.6 }; for (int i = 0; i < 4; i++) { values[i][0] = values1[i]; values[i][1] = values2[i]; } Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length); Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length); long seed = 0x89302341; double[][] rank = MTKT.rankTransformation(vImage1, vImage2, 0.0, 0.0, 4, seed); double[] expectedRankOrder = { 1, 0, 2, 3 }; for (int i = 0; i < 4; i++) { assertEquals(expectedRankOrder[i], rank[i][0], 0.0); assertEquals(expectedRankOrder[i], rank[i][1], 0.0); } }
Example 12
Source File: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public ArrayImg<DoubleType, DoubleArray> generateDoubleArrayTestImg( final boolean fill, final long... dims) { final double[] array = new double[(int) Intervals.numElements( new FinalInterval(dims))]; if (fill) { seed = 17; for (int i = 0; i < array.length; i++) { array[i] = (double) pseudoRandom() / (double) Integer.MAX_VALUE; } } return ArrayImgs.doubles(array, dims); }
Example 13
Source File: MTKTTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testMTKTall() { double[][] values = new double[10][2]; double[] values1 = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 }; double[] values2 = { 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0 }; for (int i = 0; i < 4; i++) { values[i][0] = values1[i]; values[i][1] = values2[i]; } Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length); Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length); double result = (Double) ops.run(MTKT.class, vImage1, vImage2); assertEquals(1.0, result, 0.0); }
Example 14
Source File: MTKTTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testMTKTnone() { double[][] values = new double[10][2]; double[] values1 = { 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0 }; double[] values2 = { 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0 }; for (int i = 0; i < 4; i++) { values[i][0] = values1[i]; values[i][1] = values2[i]; } Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length); Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length); double result = (Double) ops.run(MTKT.class, vImage1, vImage2); assertEquals(4.9E-324, result, 0.0); }
Example 15
Source File: LinearIntensityMap.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
public static void main( final String[] args ) { new ImageJ(); final double[] coefficients = new double[]{ 0, 2, 4, 8, 1, 1, 1, 1, 1, 10, 5, 1, 1, 1, 1, 1, 0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150 }; final LinearIntensityMap< DoubleType > transform = new LinearIntensityMap< DoubleType >( ArrayImgs.doubles( coefficients, 4, 4, 2 ) ); //final ImagePlus imp = new ImagePlus( "http://upload.wikimedia.org/wikipedia/en/2/24/Lenna.png" ); final ImagePlus imp1 = new ImagePlus( "http://fly.mpi-cbg.de/~saalfeld/Pictures/norway.jpg"); final ArrayImg< FloatType, FloatArray > image1 = ArrayImgs.floats( ( float[] )imp1.getProcessor().convertToFloatProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< UnsignedByteType, ByteArray > image2 = ArrayImgs.unsignedBytes( ( byte[] )imp1.getProcessor().convertToByteProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< UnsignedShortType, ShortArray > image3 = ArrayImgs.unsignedShorts( ( short[] )imp1.getProcessor().convertToShortProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); final ArrayImg< ARGBType, IntArray > image4 = ArrayImgs.argbs( ( int[] )imp1.getProcessor().getPixels(), imp1.getWidth(), imp1.getHeight() ); ImageJFunctions.show( ArrayImgs.doubles( coefficients, 4, 4, 2 ) ); transform.run( image1 ); transform.run( image2 ); transform.run( image3 ); transform.run( image4 ); ImageJFunctions.show( image1 ); ImageJFunctions.show( image2 ); ImageJFunctions.show( image3 ); ImageJFunctions.show( image4 ); }
Example 16
Source File: DefaultEquation.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public IterableInterval<T> createOutput(final String input) { // produce a 256x256 float64 array-backed image by default @SuppressWarnings({ "rawtypes", "unchecked" }) final IterableInterval<T> newImage = (IterableInterval) ArrayImgs.doubles( 256, 256); return newImage; }
Example 17
Source File: N5.java From sciview with BSD 2-Clause "Simplified" License | 5 votes |
public static void save(List<RealLocalizable> points, N5Writer n5, String dataset, int[] vertexBlockSize, Compression compression) throws IOException { Img<DoubleType> vertImg = ArrayImgs.doubles(points.size(), points.get(0).numDimensions()); RandomAccess<DoubleType> vAccess = vertImg.randomAccess(); long[] vPos = new long[2]; for( vPos[0] = 0; vPos[0] < points.size(); vPos[0]++ ) { for( vPos[1] = 0; vPos[1] < points.get(0).numDimensions(); vPos[1]++ ) { vAccess.setPosition(vPos); vAccess.get().set(points.get((int) vPos[0]).getDoublePosition((int) vPos[1])); } } N5Utils.save(vertImg, n5, dataset, vertexBlockSize, compression); n5.setAttribute(dataset, "nodeType", "sciview-1.0.0 points"); }
Example 18
Source File: N5.java From sciview with BSD 2-Clause "Simplified" License | 5 votes |
/** * Save an ImageJ mesh into n5 * @param mesh * @param n5 * @param dataset * @param vertexBlockSize * @param triangleBlockSize * @param compression * @throws IOException */ public static void save(Mesh mesh, N5Writer n5, String dataset, int[] vertexBlockSize, int[] triangleBlockSize, Compression compression) throws IOException { Img<DoubleType> vertImg = ArrayImgs.doubles(mesh.vertices().size(), 3); Img<LongType> triImg = ArrayImgs.longs(mesh.triangles().size(), 3); RandomAccess<DoubleType> vAccess = vertImg.randomAccess(); long[] vPos = new long[2]; for( vPos[0] = 0; vPos[0] < mesh.vertices().size(); vPos[0]++ ) { for( vPos[1] = 0; vPos[1] < 3; vPos[1]++ ) { vAccess.setPosition(vPos); if( vPos[1] == 0) vAccess.get().set(mesh.vertices().x(vPos[0])); if( vPos[1] == 1) vAccess.get().set(mesh.vertices().y(vPos[0])); if( vPos[1] == 2) vAccess.get().set(mesh.vertices().z(vPos[0])); } } RandomAccess<LongType> tAccess = triImg.randomAccess(); long[] tPos = new long[2]; for( tPos[0] = 0; tPos[0] < mesh.triangles().size(); tPos[0]++ ) { for( tPos[1] = 0; tPos[1] < 3; tPos[1]++ ) { tAccess.setPosition(tPos); //System.out.println("tri vidx: " + mesh.triangles().vertex0(tPos[0])); if( tPos[1] == 0) tAccess.get().set(mesh.triangles().vertex0(tPos[0])); if( tPos[1] == 1) tAccess.get().set(mesh.triangles().vertex1(tPos[0])); if( tPos[1] == 2) tAccess.get().set(mesh.triangles().vertex2(tPos[0])); } } N5Utils.save(vertImg, n5, dataset + "/vertices", vertexBlockSize, compression); N5Utils.save(triImg, n5, dataset + "/triangles", triangleBlockSize, new GzipCompression()); n5.setAttribute(dataset, "nodeType", "sciview-1.0.0 trimesh"); }
Example 19
Source File: MTKTTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Test public void testRankTransformationTie() { double[][] values = new double[4][2]; double[] values1 = { 2.1, 3.0, 3.0, 4.2 }; double[] values2 = { 2.1, 3.0, 3.0, 4.2 }; for (int i = 0; i < 4; i++) { values[i][0] = values1[i]; values[i][1] = values2[i]; } Img<DoubleType> vImage1 = ArrayImgs.doubles(values1, values1.length); Img<DoubleType> vImage2 = ArrayImgs.doubles(values2, values2.length); long seed = 0x89302341; double[][] rank = MTKT.rankTransformation(vImage1, vImage2, 0.0, 0.0, 4, seed); double[] expectedRankOrder1 = { 0, 1, 2, 3 }; double[] expectedRankOrder2 = { 0, 2, 1, 3 }; for (int i = 0; i < 4; i++) { // first element assertEquals(expectedRankOrder1[0], rank[0][0], 0.0); assertEquals(expectedRankOrder1[0], rank[0][1], 0.0); // second element if (rank[1][0] == 1.0) { assertEquals(expectedRankOrder1[1], rank[1][0], 0.0); } else if (rank[1][0] == 2.0) { assertEquals(expectedRankOrder2[1], rank[1][0], 0.0); } if (rank[1][1] == 1.0) { assertEquals(expectedRankOrder1[1], rank[1][1], 0.0); } else if (rank[1][1] == 2.0) { assertEquals(expectedRankOrder2[1], rank[1][1], 0.0); } // third element if (rank[2][0] == 2.0) { assertEquals(expectedRankOrder1[2], rank[2][0], 0.0); } else if (rank[2][0] == 1.0) { assertEquals(expectedRankOrder2[2], rank[2][0], 0.0); } if (rank[2][1] == 2.0) { assertEquals(expectedRankOrder1[2], rank[2][1], 0.0); } else if (rank[2][1] == 1.0) { assertEquals(expectedRankOrder2[2], rank[2][1], 0.0); } // fourth element assertEquals(expectedRankOrder1[3], rank[3][0], 0.0); assertEquals(expectedRankOrder1[3], rank[3][1], 0.0); } }
Example 20
Source File: ARGBCompositeColorConverterTest.java From paintera with GNU General Public License v2.0 | 4 votes |
@Test public void test() { ARGBCompositeColorConverter<VolatileDoubleType, RealComposite<VolatileDoubleType>, Volatile<RealComposite<VolatileDoubleType>>> c = ARGBCompositeColorConverter.imp1(3); c.minProperty(0).set(0.0); c.minProperty(1).set(0.0); c.minProperty(2).set(0.0); c.maxProperty(0).set(1.0); c.maxProperty(1).set(1.0); c.maxProperty(2).set(1.0); c.colorProperty(0).set(Colors.toARGBType(Color.RED)); // Color.GREEN is only 127 green c.colorProperty(1).set(Colors.toARGBType(Color.valueOf("#00ff00"))); c.colorProperty(2).set(Colors.toARGBType(Color.BLUE)); double[] data = { 1.0, 1.0, 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 1.0 }; RandomAccessibleInterval<DoubleType> img = ArrayImgs.doubles(data, data.length / 3, 3); RandomAccessibleInterval<VolatileDoubleType> asVolatile = Converters.convert(img, new TypeVolatileConverter<>(), new VolatileDoubleType()); RandomAccessibleInterval<RealComposite<VolatileDoubleType>> collapsed = Views.collapseReal(asVolatile); int[] groundTruthData = { 0xFFFFFFFF, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF }; final Converter<RealComposite<VolatileDoubleType>, VolatileWithSet<RealComposite<VolatileDoubleType>>> viewerConverter = (source, target ) -> { target.setT(source); target.setValid(source.get(0).isValid()); }; final RandomAccessibleInterval<ARGBType> groundTruth = ArrayImgs.argbs(groundTruthData, groundTruthData.length); LOG.debug("Dimensions: {}", Intervals.dimensionsAsLongArray(collapsed)); RandomAccessibleInterval<VolatileWithSet<RealComposite<VolatileDoubleType>>> volatileComposite = Converters.convert(collapsed, viewerConverter, new VolatileWithSet<>(null, true)); RandomAccessibleInterval<ARGBType> asColor = Converters.convert(volatileComposite, c, new ARGBType(1)); Views .interval(Views.pair(groundTruth, asColor), asColor) .forEach(p -> Assert.assertEquals(p.getA().get(), p.getB().get())); }