net.imglib2.img.array.ArrayImgs Java Examples
The following examples show how to use
net.imglib2.img.array.ArrayImgs.
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: AbstractThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Before public void initialize() { final long[] dimensions = new long[] { xSize, ySize }; final Random r = new Random(0xdeadbeef); // create image and output in = ArrayImgs.unsignedShorts(dimensions); final RandomAccess<UnsignedShortType> ra = in.randomAccess(); // populate pixel values with a ramp function + a constant for (int x = 0; x < xSize; x++) { for (int y = 0; y < ySize; y++) { ra.setPosition(new int[] { x, y }); ra.get().setReal(r.nextInt(65535)); } } }
Example #2
Source File: AbstractOpTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
public ArrayImg<UnsignedVariableBitLengthType, LongArray> generateUnsignedVariableBitLengthTypeArrayTestImg(final boolean fill, final int nbits, final long... dims) { final long[] array = new long[(int) Intervals.numElements(new FinalInterval( dims))]; if (fill) { seed = 17; for (int i = 0; i < array.length; i++) { array[i] = (long) (((pseudoRandom() / Integer.MAX_VALUE)) % (Math.pow(2, nbits))) ; } } final LongArray l = new LongArray(array); return ArrayImgs.unsignedVariableBitLengths(l, nbits, dims); }
Example #3
Source File: Utils.java From sciview with BSD 2-Clause "Simplified" License | 6 votes |
static public Img<ARGBType> convertToARGB(Img<UnsignedByteType> screenshot) { Img<ARGBType> out = ArrayImgs.argbs(screenshot.dimension(0), screenshot.dimension(1)); long[] pos = new long[3]; Cursor<ARGBType> outCur = Views.iterable(out).cursor(); RandomAccess<UnsignedByteType> sRA = screenshot.randomAccess(); while( outCur.hasNext() ) { outCur.fwd(); outCur.localize(pos); pos[2] = 0; sRA.setPosition(pos); int r = sRA.get().get(); pos[2] = 1; sRA.setPosition(pos); int g = sRA.get().get(); pos[2] = 2; sRA.setPosition(pos); int b = sRA.get().get(); int a = 255;// FIXME outCur.get().set(ARGBType.rgba(r, g, b, a)); } return out; }
Example #4
Source File: OutlineTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** Test the op with a 2x2 square. The square is in the middle of a 4x4 img */ @Test public void testSquare() { // SETUP final Img<BitType> img = ArrayImgs.bits(4, 4); final IntervalView<BitType> square = Views.offsetInterval(img, new long[] { 1, 1 }, new long[] { 2, 2 }); square.cursor().forEachRemaining(BitType::setOne); // EXECUTE final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img, Boolean.TRUE); // VERIFY assertEquals("Wrong number of foreground elements in interval", 4, countForeground(result)); final IntervalView<BitType> resultSquare = Views.offsetInterval(result, new long[] { 1, 1 }, new long[] { 2, 2 }); assertTrue("Wrong number of foreground elements in object", allForeground( resultSquare)); }
Example #5
Source File: LegacyMicroManagerImgLoader.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
@Override public RandomAccessibleInterval< UnsignedShortType > getImage( final ViewId view ) { try { final MultipageTiffReader r = new MultipageTiffReader( mmFile ); final ArrayImg< UnsignedShortType, ? > img = ArrayImgs.unsignedShorts( r.width(), r.height(), r.depth() ); final BasicViewDescription< ? > vd = sequenceDescription.getViewDescriptions().get( view ); populateImage( img, vd, r ); updateMetaDataCache( view, r.width(), r.height(), r.depth(), r.calX(), r.calY(), r.calZ() ); r.close(); return img; } catch ( Exception e ) { IOFunctions.printlnSafe( "Failed to load viewsetup=" + view.getViewSetupId() + " timepoint=" + view.getTimePointId() + ": " + e ); e.printStackTrace(); return null; } }
Example #6
Source File: MinimalTest.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
@Override public RandomAccessibleInterval< FloatType > getFloatImage( int timepointId, boolean normalize, ImgLoaderHint... hints ) { final Random rnd = new Random( setupId ); final Img< FloatType > img = ArrayImgs.floats( 512, 512, 86 ); final float scale; if ( normalize ) scale = 1; else scale = 20000; for ( final FloatType t : img ) t.set( rnd.nextFloat() * scale); return img; }
Example #7
Source File: DefaultBilateralTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testNegatives() { final byte[] data = { -7, -8, -9, -1, -2, -3, -7, -9, -8, -1, -3, -2, -8, -7, -9, -2, -1, -3, -8, -9, -7, -2, -3, -1, -9, -7, -8, -3, -1, -2, -9, -8, -7, -3, -2, -1 }; final Img<ByteType> in = ArrayImgs.bytes(data, 6, 6); final Img<ByteType> out = generateByteArrayTestImg(false, 6, 6); ops.run(DefaultBilateral.class, out, in, 15, 5, 2); final byte[] expected = { -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2 }; Cursor<ByteType> cout = out.cursor(); for (int i = 0; i < expected.length; i++) { assertEquals(cout.next().get(), expected[i]); } }
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: VolumeTimeseriesDemo.java From sciview with BSD 2-Clause "Simplified" License | 6 votes |
public Img<UnsignedByteType> hardCopy(RandomAccessibleInterval<UnsignedByteType> img) { Img<UnsignedByteType> out = ArrayImgs.unsignedBytes( img.dimension(0), img.dimension(1), img.dimension(2), img.dimension(3)); RandomAccess<UnsignedByteType> imgAccess = img.randomAccess(); Cursor<UnsignedByteType> outCur = out.localizingCursor(); while( outCur.hasNext() ) { outCur.fwd(); imgAccess.setPosition(outCur); outCur.get().set(imgAccess.get()); } return out; }
Example #10
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testHyperCube() { // SETUP final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log( i)).toArray(); final double[] expectedCounts = DoubleStream.of(1, 16, 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); // 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: ASCIITest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testDefaultASCII() { // character set used in DefaultASCII, could be updated if necessary final String CHARS = "#O*o+-,. "; final int len = CHARS.length(); final int width = 10; final int offset = 47; final byte[] array = new byte[width * len]; for (int i = 0; i < len; i++) { for (int j = 0; j < width; j++) { array[i * width + j] = (byte) (offset + i * width + j); } } final Img<UnsignedByteType> img = ArrayImgs.unsignedBytes(array, width, len); final String ascii = (String) ops.run(DefaultASCII.class, img); for (int i = 0; i < len; i++) { for (int j = 0; j < width; j++) { assertTrue(ascii.charAt(i * (width + 1) + j) == CHARS.charAt(i)); } assertTrue(ascii.charAt(i * (width + 1) + width) == '\n'); } }
Example #12
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 #13
Source File: DefaultBilateralTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testBigImage() { final byte[] data = { 7, 8, 9, 1, 2, 3, 7, 9, 8, 1, 3, 2, 8, 7, 9, 2, 1, 3, 8, 9, 7, 2, 3, 1, 9, 7, 8, 3, 1, 2, 9, 8, 7, 3, 2, 1 }; final Img<ByteType> in = ArrayImgs.bytes(data, 6, 6); final Img<ByteType> out = generateByteArrayTestImg(false, 6, 6); ops.run(DefaultBilateral.class, out, in, 15, 5, 2); final byte[] expected = { 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3, 2, 8, 7, 6, 4, 3, 2 }; Cursor<ByteType> cout = out.cursor(); for (int i = 0; i < expected.length; i++) { assertEquals(cout.next().get(), expected[i]); } }
Example #14
Source File: ConvertMapTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
private static Img<UnsignedByteType> generateUnsignedByteImg( final byte[] values) { final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(dims))]; if (array.length != values.length) { throw new RuntimeException("Number of values doesn't match dimmensions"); } for (int i = 0; i < array.length; i++) { array[i] = values[i]; } return ArrayImgs.unsignedBytes(array, dims); }
Example #15
Source File: GenerateSpimData.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
public static Img< UnsignedShortType > copyChannelUSST( final ImagePlus imp, final int channel ) { final int w, h, d; Img< UnsignedShortType > img = ArrayImgs.unsignedShorts( w = imp.getWidth(), h = imp.getHeight(), d = imp.getNSlices() ); final Cursor< UnsignedShortType > c = img.cursor(); for ( int z = 0; z < d; ++z ) { final int[] pixels = (int[])imp.getStack().getProcessor( z + 1 ).getPixels(); for ( int i = 0; i < w*h; ++i ) { if ( channel == 0 ) c.next().set( ( pixels[ i ] & 0xff0000) >> 16 ); else if ( channel == 1 ) c.next().set( ( pixels[ i ] & 0xff00 ) >> 8 ); else c.next().set( pixels[ i ] & 0xff ); } } return img; }
Example #16
Source File: GenerateSpimData.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
public static Img< FloatType > copyChannel( final ImagePlus imp, final int channel ) { final int w, h, d; Img< FloatType > img = ArrayImgs.floats( w = imp.getWidth(), h = imp.getHeight(), d = imp.getNSlices() ); final Cursor< FloatType > c = img.cursor(); for ( int z = 0; z < d; ++z ) { final int[] pixels = (int[])imp.getStack().getProcessor( z + 1 ).getPixels(); for ( int i = 0; i < w*h; ++i ) { if ( channel == 0 ) c.next().set( ( pixels[ i ] & 0xff0000) >> 16 ); else if ( channel == 1 ) c.next().set( ( pixels[ i ] & 0xff00 ) >> 8 ); else c.next().set( pixels[ i ] & 0xff ); } } return img; }
Example #17
Source File: BlendingRealRandomAccess.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public static void main( String[] args ) { new ImageJ(); Img< FloatType > img = ArrayImgs.floats( 500, 500 ); BlendingRealRandomAccess blend = new BlendingRealRandomAccess( img, new float[]{ 100, 0 }, new float[]{ 12, 150 } ); Cursor< FloatType > c = img.localizingCursor(); while ( c.hasNext() ) { c.fwd(); blend.setPosition( c ); c.get().setReal( blend.get().getRealFloat() ); } ImageJFunctions.show( img ); }
Example #18
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 #19
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
public ArrayImg<ByteType, ByteArray> generateKnownByteArrayTestImgLarge() { final long[] dims = new long[] { 3, 3 }; final byte[] array = new byte[9]; array[0] = (byte) 40; array[1] = (byte) 40; array[2] = (byte) 20; array[3] = (byte) 40; array[4] = (byte) 40; array[5] = (byte) 20; array[6] = (byte) 20; array[7] = (byte) 20; array[8] = (byte) 100; return ArrayImgs.bytes(array, dims); }
Example #20
Source File: SquareIntegralImgTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
private Img<ByteType> generateKnownSquareIntegralImage() { final long[] dims = new long[] { 3, 3 }; final byte[] array = new byte[9]; array[0] = (byte) 16; array[1] = (byte) 32; array[2] = (byte) 36; array[3] = (byte) 32; array[4] = (byte) 64; array[5] = (byte) 72; array[6] = (byte) 36; array[7] = (byte) 72; array[8] = (byte) 116; Img<ByteType> bytes = ArrayImgs.bytes(array, dims); return bytes; }
Example #21
Source File: LegacyDHMImgLoader.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
@Override public RandomAccessibleInterval< UnsignedShortType > getImage( final ViewId view ) { final BasicViewDescription< ? > vd = sd.getViewDescriptions().get( view ); final Dimensions d = vd.getViewSetup().getSize(); final VoxelDimensions dv = vd.getViewSetup().getVoxelSize(); final ArrayImg< UnsignedShortType, ? > img = ArrayImgs.unsignedShorts( d.dimension( 0 ), d.dimension( 1 ), d.dimension( 2 ) ); final String ampOrPhaseDir; if ( vd.getViewSetup().getAttribute( Channel.class ).getId() == ampChannelId ) ampOrPhaseDir = amplitudeDir; else if ( vd.getViewSetup().getAttribute( Channel.class ).getId() == phaseChannelId ) ampOrPhaseDir = phaseDir; else throw new RuntimeException( "viewSetupId=" + view.getViewSetupId() + " is not Amplitude nor phase." ); populateImage( img, directory, stackDir, ampOrPhaseDir, zPlanes, timepoints.get( view.getTimePointId() ), extension ); updateMetaDataCache( view, (int)d.dimension( 0 ), (int)d.dimension( 1 ), (int)d.dimension( 2 ), dv.dimension( 0 ), dv.dimension( 1 ), dv.dimension( 2 ) ); return img; }
Example #22
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testOneVoxel() { // SETUP final PrimitiveIterator.OfDouble sizes = DoubleStream.of(9, 3, 1).map( i -> -Math.log(i)).iterator(); final PrimitiveIterator.OfDouble counts = DoubleStream.of(1, 1, 1).map( Math::log).iterator(); final Img<BitType> img = ArrayImgs.bits(9, 9, 9); final RandomAccess<BitType> access = img.randomAccess(); access.setPosition(new long[] { 4, 4, 4 }); access.get().setOne(); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, 9L, 3L, 3.0); // VERIFY points.forEach(p -> { assertEquals(p.a.get(), sizes.next(), 1e-12); assertEquals(p.b.get(), counts.next(), 1e-12); }); }
Example #23
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 #24
Source File: DefaultCoarsenessFeature.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Apply mean filter with given size of reactangle shape * * @param input * Input image * @param i * Size of rectangle shape * @return Filered mean image */ @SuppressWarnings("unchecked") private Img<I> mean(final RandomAccessibleInterval<I> input, final int i) { long[] dims = new long[input.numDimensions()]; input.dimensions(dims); final byte[] array = new byte[(int) Intervals.numElements(new FinalInterval(dims))]; Img<I> meanImg = (Img<I>) ArrayImgs.unsignedBytes(array, dims); OutOfBoundsMirrorFactory<ByteType, Img<ByteType>> oobFactory = new OutOfBoundsMirrorFactory<>( Boundary.SINGLE); ops().run(MeanFilterOp.class, meanImg, input, new RectangleShape(i, true), oobFactory); return meanImg; }
Example #25
Source File: PermuteViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testIntervalPermuteInverseDimensionCoordinates() { 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}, 1); Cursor<DoubleType> e = expected.cursor(); RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(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 #26
Source File: SliceTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testNonZeroMinimumInterval() { Img<ByteType> img3D = ArrayImgs.bytes(50, 50, 3); IntervalView<ByteType> interval2D = Views.interval(img3D, new FinalInterval(new long[] { 25, 25, 2 }, new long[] { 35, 35, 2 })); final int[] xyAxis = new int[] { 0, 1 }; // iterate through every slice, should return a single // RandomAccessibleInterval<?> from 25, 25, 2 to 35, 35, 2 final SlicesII<ByteType> hyperSlices = new SlicesII<>(interval2D, xyAxis, true); final Cursor<RandomAccessibleInterval<ByteType>> c = hyperSlices.cursor(); int i = 0; while (c.hasNext()) { c.next(); i++; } assertEquals(1, i); }
Example #27
Source File: SliceTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
private void testXYZCropping(int t) { Img<ByteType> inSequence = ArrayImgs.bytes(20, 20, 21, t); ArrayImg<ByteType, ByteArray> outSequence = ArrayImgs.bytes(20, 20, 21, t); // fill array img with values (plane position = value in px); for (final Cursor<ByteType> cur = inSequence.cursor(); cur.hasNext();) { cur.fwd(); cur.get().set((byte) cur.getIntPosition(2)); } // selected interval XYZ final int[] xyAxis = new int[] { 0, 1, 2 }; ops.run(SliceRAI2RAI.class, outSequence, inSequence, new DummyOp(), xyAxis); for (final Cursor<ByteType> cur = outSequence.cursor(); cur.hasNext();) { cur.fwd(); assertEquals(cur.getIntPosition(2), cur.get().getRealDouble(), 0); } }
Example #28
Source File: SliceTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override @Before public void setUp() { context = new Context(OpService.class); ops = context.service(OpService.class); in = ArrayImgs.bytes(20, 20, 21); out = ArrayImgs.bytes(20, 20, 21); // fill array img with values (plane position = value in px); for (final Cursor<ByteType> cur = in.cursor(); cur.hasNext();) { cur.fwd(); cur.get().set((byte) cur.getIntPosition(2)); } }
Example #29
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 #30
Source File: BoxCountTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testAllForeground() { // SETUP final double scalingPow = DoubleStream.generate(() -> SCALING).limit( DIMENSIONS).reduce((i, j) -> i * j).orElse(0); final double[] expectedCounts = DoubleStream.iterate(1.0, i -> i * scalingPow).map(Math::log).limit(ITERATIONS).toArray(); final Img<BitType> img = ArrayImgs.bits(TEST_DIMS); img.forEach(BitType::setOne); // EXECUTE final List<ValuePair<DoubleType, DoubleType>> points = ops.topology() .boxCount(img, MAX_SIZE, MIN_SIZE, SCALING); // VERIFY for (int i = 0; i < ITERATIONS; i++) { assertEquals(EXPECTED_SIZES[i], points.get(i).a.get(), 1e-12); assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12); } }