@Test public void testIterableIntervalView() { @SuppressWarnings("unchecked") final IterableInterval<ByteType> res = (IterableInterval<ByteType>) ops.run(MapViewIterableIntervalToIterableInterval.class, in, op, new ByteType()); final Cursor<ByteType> iterable = res.cursor(); while (iterable.hasNext()) { assertEquals((byte) 10, iterable.next().get()); } }
public static final <T extends RealType<T>> void addGaussianNoiseToImage( RandomAccessibleInterval<T> img, double sigma_noise) { IterableInterval<T> iterImg = Views.iterable(img); Cursor<T> lc = iterImg.localizingCursor(); double val; T var = iterImg.firstElement().createVariable(); while (lc.hasNext()) { lc.fwd(); val = Math.max(0, sigma_noise * ran.nextGaussian()); var.setReal(val); lc.get().add(var); } }
public static final <T extends RealType<T>> void addGaussianSpotToImage( RandomAccessibleInterval<T> img, double[] params) { IterableInterval<T> iterImg = Views.iterable(img); Cursor<T> lc = iterImg.localizingCursor(); int nDims = img.numDimensions(); double[] position = new double[nDims]; double val; T var = iterImg.firstElement().createVariable(); while (lc.hasNext()) { lc.fwd(); lc.localize(position); val = gaussian.val(position, params); var.setReal(val); lc.get().add(var); } }
@Test public void testListDilateFull() { final List<Shape> shapes = new ArrayList<Shape>(); 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, true); final Img<ByteType> out2 = Dilation.dilateFull(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()); }
@Override public RealSum call() throws Exception { final Cursor<FloatType> psiCursor = psiIterable.localizingCursor(); psiCursor.jumpFwd(portion.getStartPosition()); final int m = iterableImgs.size(); if (compatibleIteration) { final ArrayList<Cursor<FloatType>> cursorWeights = new ArrayList<Cursor<FloatType>>(); final ArrayList<Cursor<FloatType>> cursorImgs = new ArrayList<Cursor<FloatType>>(); for (final IterableInterval<FloatType> img : iterableImgs) { final Cursor<FloatType> imgCursor = img.cursor(); imgCursor.jumpFwd(portion.getStartPosition()); cursorImgs.add(imgCursor); } for (final IterableInterval<FloatType> weight : iterableWeights) { final Cursor<FloatType> weightCursor = weight.cursor(); weightCursor.jumpFwd(portion.getStartPosition()); cursorWeights.add(weightCursor); } for (int j = 0; j < portion.getLoopSize(); ++j) compatibleLoop(psiCursor, cursorWeights, cursorImgs, realSum, m); } else { final ArrayList<RandomAccess<FloatType>> randomAccessWeights = new ArrayList<RandomAccess<FloatType>>(); final ArrayList<RandomAccess<FloatType>> randomAccessImgs = new ArrayList<RandomAccess<FloatType>>(); for (final RandomAccessibleInterval<FloatType> img : imgs) randomAccessImgs.add(img.randomAccess()); for (final RandomAccessibleInterval<FloatType> weight : weights) randomAccessWeights.add(weight.randomAccess()); for (int j = 0; j < portion.getLoopSize(); ++j) incompatibleLoop(psiCursor, randomAccessWeights, randomAccessImgs, realSum, m); } return realSum; }
@Override public void map() { for (int d = 2; d < position.length; ++d) min[d] = max[d] = position[d]; min[0] = target.min(0); min[1] = target.min(1); max[0] = target.max(0); max[1] = target.max(1); final FinalInterval sourceInterval = new FinalInterval(min, max); final Cursor<B> targetCursor = target.cursor(); final RandomAccess<A> sourceRandomAccess = source.randomAccess(sourceInterval); sourceRandomAccess.setPosition(position); while (targetCursor.hasNext()) { final B b = targetCursor.next(); sourceRandomAccess.setPosition(targetCursor.getLongPosition(0), 0); if (numDimensions > 1) sourceRandomAccess.setPosition(targetCursor.getLongPosition(1), 1); converter.convert(sourceRandomAccess.get(), b); } }
public FirstIteration( final ImagePortion portion, final RandomAccessibleInterval<FloatType> psi, final ArrayList<RandomAccessibleInterval<FloatType>> imgs, final ArrayList<RandomAccessibleInterval<FloatType>> weights) { this.portion = portion; this.psi = psi; this.imgs = imgs; this.weights = weights; this.psiIterable = Views.iterable(psi); this.iterableImgs = new ArrayList<IterableInterval<FloatType>>(); this.iterableWeights = new ArrayList<IterableInterval<FloatType>>(); this.realSum = new RealSum(); if (imgs.size() != weights.size()) throw new RuntimeException("Number of weights and images must be equal."); compatibleIteration = true; for (final RandomAccessibleInterval<FloatType> img : imgs) { final IterableInterval<FloatType> imgIterable = Views.iterable(img); if (!psiIterable.iterationOrder().equals(imgIterable.iterationOrder())) compatibleIteration = false; this.iterableImgs.add(imgIterable); } for (final RandomAccessibleInterval<FloatType> weight : weights) { final IterableInterval<FloatType> weightIterable = Views.iterable(weight); if (!psiIterable.iterationOrder().equals(weightIterable.iterationOrder())) compatibleIteration = false; for (final IterableInterval<FloatType> imgIterable : iterableImgs) if (!imgIterable.iterationOrder().equals(weightIterable.iterationOrder())) compatibleIteration = false; this.iterableWeights.add(weightIterable); } }
@Override public void compute1(final IterableInterval<I> input, final O output) { double moment10 = 0; final Cursor<I> cur = input.localizingCursor(); while (cur.hasNext()) { cur.fwd(); double x = cur.getDoublePosition(0); double val = cur.get().getRealDouble(); moment10 += x * val; } output.setReal(moment10); }
@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()); } }
@Override public void compute(final IterableInterval<I> input, final O output) { final double moment00 = moment00Func.compute(input).getRealDouble(); final double moment01 = moment01Func.compute(input).getRealDouble(); final double centerY = moment01 / moment00; double centralmoment02 = 0; final Cursor<I> it = input.localizingCursor(); while (it.hasNext()) { it.fwd(); final double y = it.getDoublePosition(1) - centerY; final double val = it.get().getRealDouble(); centralmoment02 += val * y * y; } output.setReal(centralmoment02); }