net.imglib2.Cursor Java Examples
The following examples show how to use
net.imglib2.Cursor.
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: PermuteViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void defaultPermuteCoordinatesInverseTest() { 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()); } Cursor<DoubleType> il2 = Views.permuteCoordinatesInverse(img, new int[]{0, 1}).cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }
Example #2
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 #3
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 #4
Source File: FFTTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
protected void assertRAIsEqual(final RandomAccessibleInterval<FloatType> rai1, final RandomAccessibleInterval<FloatType> rai2, final float delta) { final IterableInterval<FloatType> rai1Iterator = Views.iterable(rai1); final IterableInterval<FloatType> rai2Iterator = Views.iterable(rai2); final Cursor<FloatType> c1 = rai1Iterator.cursor(); final Cursor<FloatType> c2 = rai2Iterator.cursor(); while (c1.hasNext()) { c1.fwd(); c2.fwd(); // assert that the inverse = the input within the error delta assertEquals(c1.get().getRealFloat(), c2.get().getRealFloat(), delta); } }
Example #5
Source File: IntegralAdd.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final IterableInterval<I> input, final IterableInterval<I> output) { final Cursor<I> inputCursor = input.cursor(); final Cursor<I> outputCursor = output.cursor(); double tmp = 0.0d; while (outputCursor.hasNext()) { final I inputValue = inputCursor.next(); final I outputValue = outputCursor.next(); tmp += inputValue.getRealDouble(); outputValue.setReal(tmp); } }
Example #6
Source File: IdSelector.java From paintera with GNU General Public License v2.0 | 6 votes |
private void selectAllLabelMultisetType(final TLongSet allIds) { @SuppressWarnings("unchecked") final RandomAccessibleInterval<LabelMultisetType> data = (RandomAccessibleInterval<LabelMultisetType>) source.getDataSource(0, source.getNumMipmapLevels() - 1); final Cursor<LabelMultisetType> cursor = Views.iterable(data).cursor(); while (cursor.hasNext()) { final LabelMultisetType lmt = cursor.next(); for (final Entry<Label> entry : lmt.entrySet()) { final long id = entry.getElement().id(); if (foregroundCheck.test(id)) allIds.add(id); } } }
Example #7
Source File: DefaultBilateralTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testArrayToCellImg() { 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); final Img<ByteType> cellOut = generateByteTestCellImg(false, 6, 6); ops.run(DefaultBilateral.class, out, in, 15, 5, 2); ops.run(DefaultBilateral.class, cellOut, in, 15, 5, 2); Cursor<ByteType> cout = out.cursor(); Cursor<ByteType> cCellOut = cellOut.cursor(); while (cout.hasNext()) { byte expected = cout.next().get(); byte actual = cCellOut.next().get(); assertEquals(expected, actual); } }
Example #8
Source File: ImageStatistics.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Calculates the min of an image. * * @param img The image to calculate the min of * @return The min of the image passed */ final public static <T extends Type<T> & Comparable<T>> T getImageMin( final RandomAccessibleInterval<T> img ) { final Cursor<T> cursor = Views.iterable(img).cursor(); cursor.fwd(); // copy first element as current maximum final T min = cursor.get().copy(); while ( cursor.hasNext() ) { cursor.fwd(); final T currValue = cursor.get(); if ( currValue.compareTo( min ) < 0 ) min.set( currValue ); } return min; }
Example #9
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 #10
Source File: HistogramOfOrientedGradients2D.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Void call() throws Exception { final FinalInterval interval = new FinalInterval(in.dimension(0), in.dimension(1)); for (int j = 0; j < in.dimension(1); j++) { // sum up the magnitudes of all bins in a neighborhood raNeighbor.setPosition(new long[] { i, j }); final Cursor<FloatType> cursorNeighborHood = raNeighbor.get().cursor(); while (cursorNeighborHood.hasNext()) { cursorNeighborHood.next(); if (Intervals.contains(interval, cursorNeighborHood)) { raAngles.setPosition(cursorNeighborHood); raMagnitudes.setPosition(cursorNeighborHood); raOut.setPosition(new long[] { i, j, (int) (raAngles.get().getRealFloat() / (360 / numOrientations) - 0.5) }); raOut.get().add(raMagnitudes.get()); } } } return null; }
Example #11
Source File: MeanTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMean() { final Img<ByteType> image = generateByteArrayTestImg(true, 40, 50); final DoubleType mean = new DoubleType(); ops.run(IterableMean.class, mean, image); assertEquals(1.0 / 15.625, mean.get(), 0.0); Cursor<ByteType> c = image.cursor(); // this time lets just make every value 100 while (c.hasNext()) { c.fwd(); c.get().setReal(100.0); } ops.run(IterableMean.class, mean, image); // the mean should be 100 assertEquals(100.0, mean.get(), 0.0); }
Example #12
Source File: CopyRAITest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void copyRAINoOutputTest() { @SuppressWarnings("unchecked") final RandomAccessibleInterval<UnsignedByteType> output = (RandomAccessibleInterval<UnsignedByteType>) ops.run(CopyRAI.class, input); final Cursor<UnsignedByteType> inc = input.localizingCursor(); final RandomAccess<UnsignedByteType> outRA = output.randomAccess(); while (inc.hasNext()) { inc.fwd(); outRA.setPosition(inc); assertEquals(inc.get().get(), outRA.get().get()); } }
Example #13
Source File: NormalizeTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testNormalize() { Img<ByteType> in = generateByteArrayTestImg(true, 5, 5); Img<ByteType> out = in.factory().create(in, new ByteType()); ops.run(NormalizeIIComputer.class, out, in); final Pair<ByteType, ByteType> minMax2 = ops.stats().minMax(out); assertEquals(minMax2.getA().get(), Byte.MIN_VALUE); assertEquals(minMax2.getB().get(), Byte.MAX_VALUE); final IterableInterval<ByteType> lazyOut = ops.image().normalize(in); final IterableInterval<ByteType> notLazyOut = ops.image().normalize(in, null, null, null, null, false); final Cursor<ByteType> outCursor = out.cursor(); final Cursor<ByteType> lazyCursor = lazyOut.cursor(); final Cursor<ByteType> notLazyCursor = notLazyOut.cursor(); while (outCursor.hasNext()) { assertEquals(outCursor.next().get(), lazyCursor.next().get()); assertEquals(outCursor.get().get(), notLazyCursor.next().get()); } }
Example #14
Source File: ProjectRAIToIterableInterval.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final RandomAccessibleInterval<T> input, final IterableInterval<V> output) { final Cursor<V> cursor = output.localizingCursor(); final RandomAccess<T> access = input.randomAccess(); while (cursor.hasNext()) { cursor.fwd(); for (int d = 0; d < input.numDimensions(); d++) { if (d != dim) { access.setPosition(cursor.getIntPosition(d - (d > dim ? -1 : 0)), d); } } method.compute(new DimensionIterable(input.dimension(dim), access), cursor.get()); } }
Example #15
Source File: InvertTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
private <T extends IntegerType<T>> void assertIntegerInvert(final Img<T> in, final Img<T> out) { final Op op = ops.op(Ops.Image.Invert.class, out, in); assertSame(InvertIIInteger.class, op.getClass()); op.run(); Cursor<T> inCursor = in.localizingCursor(); Cursor<T> outCursor = out.localizingCursor(); while(inCursor.hasNext()) { inCursor.fwd(); outCursor.fwd(); } integerCompare(in, out, null, null); }
Example #16
Source File: PermuteViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void defaultPermuteCoordinatesTest() { 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()); } Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[]{0, 1}).cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}).randomAccess(); while (il2.hasNext()) { il2.next(); opr.setPosition(il2); assertEquals(il2.get().get(), opr.get().get(), 1e-10); } }
Example #17
Source File: DefaultCentralMoment30.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@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 #18
Source File: DefaultCentralMoment20.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@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 #19
Source File: ColocImgLibGadgets.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
protected double calculatePearson(Cursor<T> cursor1, double mean1, Cursor<T> cursor2, double mean2) { double pearsonDenominator = 0; double ch1diffSquaredSum = 0; double ch2diffSquaredSum = 0; while (cursor1.hasNext() && cursor2.hasNext()) { cursor1.fwd(); cursor2.fwd(); T type1 = cursor1.get(); double ch1diff = type1.getRealDouble() - mean1; T type2 = cursor2.get(); double ch2diff = type2.getRealDouble() - mean2; pearsonDenominator += ch1diff*ch2diff; ch1diffSquaredSum += (ch1diff*ch1diff); ch2diffSquaredSum += (ch2diff*ch2diff); } double pearsonNumerator = Math.sqrt(ch1diffSquaredSum * ch2diffSquaredSum); return pearsonDenominator / pearsonNumerator; }
Example #20
Source File: DilationTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testListDilate() { final List<Shape> shapes = new ArrayList<>(); shapes.add(new DiamondShape(1)); shapes.add(new DiamondShape(1)); shapes.add(new RectangleShape(1, false)); shapes.add(new HorizontalLineShape(2, 1, false)); @SuppressWarnings("unchecked") final IterableInterval<ByteType> out1 = (IterableInterval<ByteType>) ops .run(ListDilate.class, IterableInterval.class, in, shapes, false); final Img<ByteType> out2 = Dilation.dilate(in, shapes, 1); final Cursor<ByteType> c1 = out1.cursor(); final Cursor<ByteType> c2 = out2.cursor(); while (c1.hasNext()) assertEquals(c1.next().get(), c2.next().get()); }
Example #21
Source File: CreateKernel2D.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public RandomAccessibleInterval<T> calculate(double[][] input) { final long[] dims = { input.length, input[0].length }; final RandomAccessibleInterval<T> rai = createOp.calculate(new FinalInterval( dims)); final Cursor<T> cursor = Views.iterable(rai).cursor(); for (int j = 0; j < input.length; j++) { for (int k = 0; k < input[j].length; k++) { cursor.fwd(); cursor.get().setReal(input[j][k]); } } return rai; }
Example #22
Source File: PermuteViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void permuteCoordinatesOfDimensionTest() { 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()); } Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[]{0, 1}, 1).cursor(); RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(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 #23
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 #24
Source File: TransformInputAndWeights.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
@Override public String call() throws Exception { final NLinearInterpolatorFactory< FloatType > f = new NLinearInterpolatorFactory< FloatType >(); // make the interpolators and get the transformations final RealRandomAccess< FloatType > ir = Views.interpolate( Views.extendMirrorSingle( img ), f ).realRandomAccess(); final RealRandomAccess< FloatType > wr = blending.realRandomAccess(); final Cursor< FloatType > cursor = Views.iterable( transformedImg ).localizingCursor(); final Cursor< FloatType > cursorW = Views.iterable( weightImg ).cursor(); final float[] s = new float[ 3 ]; final float[] t = new float[ 3 ]; cursor.jumpFwd( portion.getStartPosition() ); cursorW.jumpFwd( portion.getStartPosition() ); for ( int j = 0; j < portion.getLoopSize(); ++j ) loop( cursor, cursorW, ir, wr, transform, s, t, offsetX, offsetY, offsetZ, imgSizeX, imgSizeY, imgSizeZ ); return portion + " finished successfully (transform input & precompute weights)."; }
Example #25
Source File: Maps.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
public static <I1, I2, O> void map(final IterableInterval<I1> a, final IterableInterval<I2> b, final IterableInterval<O> c, final BinaryComputerOp<I1, I2, O> op, final long startIndex, final long stepSize, final long numSteps) { if (numSteps <= 0) return; final Cursor<I1> aCursor = a.cursor(); final Cursor<I2> bCursor = b.cursor(); final Cursor<O> cCursor = c.cursor(); for (long ctr = 0; ctr < numSteps; ctr++) { final long m = ctr == 0 ? startIndex + 1 : stepSize; aCursor.jumpFwd(m); bCursor.jumpFwd(m); cCursor.jumpFwd(m); op.compute(aCursor.get(), bCursor.get(), cCursor.get()); } }
Example #26
Source File: DefaultBilateralTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMath() { final byte[] data = { 7, 4, 9, 1 }; final Img<ByteType> in = ArrayImgs.bytes(data, 2, 2); final Img<ByteType> out = generateByteArrayTestImg(false, 2, 2); ops.run(DefaultBilateral.class, out, in, 15, 5, 1); Cursor<ByteType> cout = out.cursor(); final byte[] expected = { 5, 5, 5, 5 }; int counter = 0; while (cout.hasNext()) { byte actual = cout.next().get(); assertEquals(expected[counter++], actual); } }
Example #27
Source File: IntervalViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void intervalMinMaxTest() { 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, new long[]{1, 1}, new long[]{8,9}).localizingCursor(); RandomAccess<DoubleType> opr = ops.transform().intervalView(img, new long[]{1, 1}, new long[]{8,9}).randomAccess(); while (il2.hasNext()) { DoubleType e = il2.next(); opr.setPosition(il2); assertEquals(e.get(), opr.get().get(), 1e-10); } }
Example #28
Source File: LoopTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testInplace() { ops.run(DefaultLoopInplace.class, in, inplaceOp, numIterations); // test final Cursor<ByteType> c = in.cursor(); while (c.hasNext()) { org.junit.Assert.assertEquals(numIterations, c.next().get()); } }
Example #29
Source File: Maps.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public static <I, O> void map(final IterableInterval<I> a, final IterableInterval<O> b, final UnaryComputerOp<I, O> op) { final Cursor<I> aCursor = a.cursor(); final Cursor<O> bCursor = b.cursor(); while (aCursor.hasNext()) { op.compute(aCursor.next(), bCursor.next()); } }
Example #30
Source File: ClearingCompositeProjector.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override protected void accumulate(final Cursor<? extends A>[] accesses, final A t) { t.set(clearValue); for (int i = 0; i < composites.size(); ++i) composites.get(i).compose(t, accesses[i].get()); }