net.imglib2.RandomAccessible Java Examples
The following examples show how to use
net.imglib2.RandomAccessible.
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: FloodFill.java From paintera with GNU General Public License v2.0 | 6 votes |
private static <T extends IntegerType<T>> void fillPrimitiveType( final RandomAccessibleInterval<T> input, final RandomAccessible<UnsignedLongType> output, final Localizable seed, final long seedLabel, final FragmentSegmentAssignment assignment) { final T extension = Util.getTypeFromInterval(input).createVariable(); extension.setInteger(Label.OUTSIDE); net.imglib2.algorithm.fill.FloodFill.fill( Views.extendValue(input, extension), output, seed, new UnsignedLongType(1), new DiamondShape(1), makePredicate(seedLabel, assignment) ); }
Example #2
Source File: Align.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
/** * Compute the partial derivative of source in a particular dimension. * * @param source * source image, has to provide valid data in the interval of the * gradient image plus a one pixel border in dimension. * @param target * output image, the partial derivative of source in the * specified dimension. * @param dimension * along which dimension the partial derivatives are computed * @param <T> pixel type source * @param <S> pixel type target */ public static < T extends RealType< T >, S extends RealType< S > > void gradient( final RandomAccessible< T > source, final RandomAccessibleInterval< S > target, final int dimension ) { final Cursor< T > front = Views.flatIterable( Views.interval( source, Intervals.translate( target, 1, dimension ) ) ).cursor(); final Cursor< T > back = Views.flatIterable( Views.interval( source, Intervals.translate( target, -1, dimension ) ) ).cursor(); for( final S t : Views.flatIterable( target ) ) { t.setReal( front.next().getRealDouble() - back.next().getRealDouble()); t.mul( 0.5 ); } }
Example #3
Source File: VolatileHierarchyProjectorPreMultiply.java From paintera with GNU General Public License v2.0 | 6 votes |
public VolatileHierarchyProjectorPreMultiply( final List<? extends RandomAccessible<A>> sources, final Converter<? super A, ARGBType> converter, final RandomAccessibleInterval<ARGBType> target, final int numThreads, final ExecutorService executorService) { this( sources, converter, target, ArrayImgs.bytes(Intervals.dimensionsAsLongArray(target)), numThreads, executorService ); }
Example #4
Source File: TestImageAccessor.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Gaussian Smooth of the input image using intermediate float format. * @param <T> * @param img * @param sigma * @return */ public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> gaussianSmooth( RandomAccessibleInterval<T> img, double[] sigma) { Interval interval = Views.iterable(img); ImgFactory<T> outputFactory = new ArrayImgFactory<T>(Util.getTypeFromInterval(img)); final long[] dim = new long[ img.numDimensions() ]; img.dimensions(dim); RandomAccessibleInterval<T> output = outputFactory.create( dim ); final long[] pos = new long[ img.numDimensions() ]; Arrays.fill(pos, 0); Localizable origin = new Point(pos); ImgFactory<FloatType> tempFactory = new ArrayImgFactory<FloatType>(new FloatType()); RandomAccessible<T> input = Views.extendMirrorSingle(img); Gauss.inFloat(sigma, input, interval, output, origin, tempFactory); return output; }
Example #5
Source File: N5Data.java From paintera with GNU General Public License v2.0 | 6 votes |
/** * * @param reader container * @param dataset dataset * @param transform transforms voxel data into real world coordinates * @param priority in fetching queue * @param dataInterpolation interpolator factory for data * @param interpolation interpolator factory for viewer data * @param name initialize with this name * @param <T> data type * @param <V> viewer type * @return {@link DataSource} * @throws IOException if any N5 operation throws {@link IOException} */ public static <T extends NativeType<T>, V extends Volatile<T> & NativeType<V>> DataSource<T, V> openScalarAsSource( final N5Reader reader, final String dataset, final AffineTransform3D transform, final SharedQueue queue, final int priority, final Function<Interpolation, InterpolatorFactory<T, RandomAccessible<T>>> dataInterpolation, final Function<Interpolation, InterpolatorFactory<V, RandomAccessible<V>>> interpolation, final String name) throws IOException, ReflectionException { LOG.debug("Creating N5 Data source from {} {}", reader, dataset); return new N5DataSource<>( Objects.requireNonNull(N5Meta.fromReader(reader, dataset)), transform, name, queue, priority, dataInterpolation, interpolation); }
Example #6
Source File: ProcessIndependentPortion.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public ProcessIndependentPortion( final ImagePortion portion, final RandomAccessibleInterval< T > img, final InterpolatorFactory<T, RandomAccessible< T > > interpolatorFactory, final AffineTransform3D transform, final Img< T > fusedImg, final BoundingBoxGUI bb ) { this.portion = portion; this.img = img; this.interpolatorFactory = interpolatorFactory; this.transform = transform; this.fusedImg = fusedImg; this.bb = bb; this.downSampling = bb.getDownSampling(); if ( downSampling == 1 ) doDownSampling = false; else doDownSampling = true; }
Example #7
Source File: ClearingCompositeProjector.java From paintera with GNU General Public License v2.0 | 6 votes |
@Override public VolatileProjector createAccumulateProjector( final ArrayList<VolatileProjector> sourceProjectors, final ArrayList<Source<?>> sources, final ArrayList<? extends RandomAccessible<? extends A>> sourceScreenImages, final RandomAccessibleInterval<A> targetScreenImage, final int numThreads, final ExecutorService executorService) { final ClearingCompositeProjector<A> projector = new ClearingCompositeProjector<>( sourceProjectors, sourceScreenImages, targetScreenImage, clearValue, numThreads, executorService ); final ArrayList<Composite<A, A>> activeComposites = new ArrayList<>(); for (final Source<?> activeSource : sources) activeComposites.add(composites.get(activeSource)); projector.setComposites(activeComposites); return projector; }
Example #8
Source File: RandomAccessibleIntervalDataSource.java From paintera with GNU General Public License v2.0 | 6 votes |
@SuppressWarnings("unchecked") public RandomAccessibleIntervalDataSource( final RandomAccessibleInterval<D> dataSource, final RandomAccessibleInterval<T> source, final AffineTransform3D mipmapTransform, final Invalidate<Long> invalidate, final Function<Interpolation, InterpolatorFactory<D, RandomAccessible<D>>> dataInterpolation, final Function<Interpolation, InterpolatorFactory<T, RandomAccessible<T>>> interpolation, final String name) { this( new RandomAccessibleInterval[] {dataSource}, new RandomAccessibleInterval[] {source}, new AffineTransform3D[] {mipmapTransform}, invalidate, dataInterpolation, interpolation, name); }
Example #9
Source File: ColocalisationTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Gaussian Smooth of the input image using intermediate float format. * * @param <T> * @param img * @param sigma * @return */ public static <T extends RealType<T> & NativeType<T>> Img<T> gaussianSmooth(RandomAccessibleInterval<T> img, double[] sigma) { Interval interval = Views.iterable(img); ImgFactory<T> outputFactory = new ArrayImgFactory<>(Util.getTypeFromInterval(img)); final long[] dim = new long[img.numDimensions()]; img.dimensions(dim); Img<T> output = outputFactory.create(dim); final long[] pos = new long[img.numDimensions()]; Arrays.fill(pos, 0); Localizable origin = new Point(pos); ImgFactory<FloatType> tempFactory = new ArrayImgFactory<>(new FloatType()); RandomAccessible<T> input = Views.extendMirrorSingle(img); Gauss.inFloat(sigma, input, interval, output, origin, tempFactory); return output; }
Example #10
Source File: CompositeProjectorPreMultiply.java From paintera with GNU General Public License v2.0 | 6 votes |
@Override public VolatileProjector createAccumulateProjector( final ArrayList<VolatileProjector> sourceProjectors, final ArrayList<Source<?>> sources, final ArrayList<? extends RandomAccessible<? extends ARGBType>> sourceScreenImages, final RandomAccessibleInterval<ARGBType> targetScreenImage, final int numThreads, final ExecutorService executorService) { final CompositeProjectorPreMultiply projector = new CompositeProjectorPreMultiply( sourceProjectors, sourceScreenImages, targetScreenImage, numThreads, executorService ); final ArrayList<Composite<ARGBType, ARGBType>> activeComposites = new ArrayList<>(); for (final Source<?> activeSource : sources) activeComposites.add(composites.get(activeSource)); projector.setComposites(activeComposites); return projector; }
Example #11
Source File: AddDimensionViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void addDimensionTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); MixedTransformView<DoubleType> il2 = Views.addDimension((RandomAccessible<DoubleType>)img); MixedTransformView<DoubleType> opr = ops.transform().addDimensionView((RandomAccessible<DoubleType>)img); assertEquals(il2.numDimensions(), opr.numDimensions()); boolean[] il2Transform = new boolean[3]; boolean[] oprTransform = new boolean[3]; il2.getTransformToSource().getComponentZero(il2Transform); opr.getTransformToSource().getComponentZero(oprTransform); for (int i = 0; i < il2Transform.length; i++) { assertEquals(il2Transform[i], oprTransform[i]); } }
Example #12
Source File: N5DataSource.java From paintera with GNU General Public License v2.0 | 6 votes |
public N5DataSource( final N5Meta meta, final AffineTransform3D transform, final String name, final SharedQueue queue, final int priority, final Function<Interpolation, InterpolatorFactory<D, RandomAccessible<D>>> dataInterpolation, final Function<Interpolation, InterpolatorFactory<T, RandomAccessible<T>>> interpolation) throws IOException { super( RandomAccessibleIntervalDataSource.asDataWithInvalidate((ImagesWithTransform<D, T>[])getData(meta.writer(), meta.dataset(), transform, queue, priority)), dataInterpolation, interpolation, name); this.meta = meta; }
Example #13
Source File: SubsampleViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void defaultSubsampleStepsTest() { 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()); } SubsampleView<DoubleType> il2 = Views.subsample((RandomAccessible<DoubleType>) img, 2, 1); SubsampleView<DoubleType> opr = ops.transform().subsampleView(img, 2, 1); Cursor<DoubleType> il2C = Views.interval(il2, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor(); RandomAccess<DoubleType> oprRA = opr.randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } }
Example #14
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 #15
Source File: N5ChannelDataSource.java From paintera with GNU General Public License v2.0 | 6 votes |
private static <T extends RealType<T>> RandomAccessible<RealComposite<T>> collapseDimension( final RandomAccessibleInterval<T> rai, final int dimension, final long[] channels, final T extension ) { final int lastDim = rai.numDimensions() - 1; final int numChannels = (int) rai.dimension(dimension); long[] min = Intervals.minAsLongArray(rai); long[] max = Intervals.maxAsLongArray(rai); assert LongStream.of(channels).filter(c -> c > max[dimension] && c < min[dimension]).count() == 0; final RandomAccessibleInterval<T> relevantRai = isFullRange(channels, numChannels) ? rai : Views.stack(LongStream.of(channels).mapToObj(channel -> Views.hyperSlice(rai, dimension, channel)).collect(Collectors.toList())); final RandomAccessible<T> ra = Views.extendValue(lastDim == dimension ? relevantRai : Views.moveAxis(relevantRai, dimension, lastDim), extension); return Views.collapseReal(ra, numChannels); }
Example #16
Source File: TransformNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Invert the d-axis. * * @param input the source * @param d the axis to invert */ @OpMethod( op = net.imagej.ops.transform.invertAxisView.DefaultInvertAxisView.class) public <T> MixedTransformView<T> invertAxisView( final RandomAccessible<T> input, final int d) { return (MixedTransformView<T>) ops().run(Ops.Transform.InvertAxisView.class, input, d); }
Example #17
Source File: CompositeProjectorPreMultiply.java From paintera with GNU General Public License v2.0 | 5 votes |
public CompositeProjectorPreMultiply( final ArrayList<VolatileProjector> sourceProjectors, final ArrayList<? extends RandomAccessible<? extends ARGBType>> sources, final RandomAccessibleInterval<ARGBType> target, final int numThreads, final ExecutorService executorService) { super(sourceProjectors, sources, target, numThreads, executorService); LOG.debug("Creating {}", this.getClass().getName()); }
Example #18
Source File: RotateViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testDefaultRotate() { final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 20, 10 }, new DoubleType()); final MixedTransformView<DoubleType> il2 = Views.rotate((RandomAccessible<DoubleType>) img, 1, 0); final MixedTransformView<DoubleType> opr = ops.transform().rotateView(deinterval(img), 1, 0); for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) { for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) { assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j], 1e-10); } } }
Example #19
Source File: ImageInterpolation.java From Stitching with GNU General Public License v2.0 | 5 votes |
public ImageInterpolation( final Img< T > image, final InterpolatorFactory< T, RandomAccessible< T > > interpolatorFactory, final boolean mirror ) { this.image = image; this.interpolatorFactory = interpolatorFactory; if ( mirror ) this.interpolated = Views.interpolate( Views.extendMirrorSingle( image ), interpolatorFactory ); else this.interpolated = Views.interpolate( Views.extendZero( image ), interpolatorFactory ); }
Example #20
Source File: N5DataSource.java From paintera with GNU General Public License v2.0 | 5 votes |
private static <T extends NativeType<T>> Function<Interpolation, InterpolatorFactory<T, RandomAccessible<T>>> interpolation(final N5Reader n5, final String dataset) throws IOException { return N5Types.isLabelMultisetType(n5, dataset) ? i -> new NearestNeighborInterpolatorFactory<>() : (Function) realTypeInterpolation(); }
Example #21
Source File: OffsetViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void defaultOffsetTest() { Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType()); MixedTransformView<DoubleType> il2 = Views.offset((RandomAccessible<DoubleType>) img, new long[] { 2, 2 }); MixedTransformView<DoubleType> opr = ops.transform().offsetView((RandomAccessible<DoubleType>) img, new long[] { 2, 2 }); for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) { for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) { assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j], 1e-10); } } }
Example #22
Source File: RandomAccessibleTriple.java From paintera with GNU General Public License v2.0 | 5 votes |
public RandomAccessibleTriple( final RandomAccessible<A> sourceA, final RandomAccessible<B> sourceB, final RandomAccessible<C> sourceC) { this.sourceA = sourceA; this.sourceB = sourceB; this.sourceC = sourceC; }
Example #23
Source File: AveragedRandomAccessible.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
public AverageRandomAccess(int numD) { // TODO: this (and methods below) will throw NPE if there are no RAbles RAs = new ArrayList<>(); type = randomAccessibles.get( 0 ).randomAccess().get().createVariable(); for (final RandomAccessible< T > RAbleI : randomAccessibles) { RAs.add( RAbleI.randomAccess() ); } }
Example #24
Source File: LinearIntensityMap.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
public LinearIntensityMap( final RandomAccessibleInterval< T > source, final InterpolatorFactory< RealComposite< T >, RandomAccessible< RealComposite< T > > > interpolatorFactory ) { this.interpolatorFactory = interpolatorFactory; final CompositeIntervalView< T, RealComposite< T > > collapsedSource = Views.collapseReal( source ); dimensions = new FinalInterval( collapsedSource ); final double[] shift = new double[ dimensions.numDimensions() ]; for ( int d = 0; d < shift.length; ++d ) shift[ d ] = 0.5; translation = new Translation( shift ); final RandomAccessible< RealComposite< T > > extendedCollapsedSource = Views.extendBorder( collapsedSource ); coefficients = Views.interpolate( extendedCollapsedSource, interpolatorFactory ); }
Example #25
Source File: MarchingCubes.java From paintera with GNU General Public License v2.0 | 5 votes |
/** * Initialize the class parameters with default values */ public MarchingCubes( final RandomAccessible<B> input, final Interval interval, final AffineTransform3D transform) { this.input = input; this.interval = interval; this.transform = transform; }
Example #26
Source File: MaximumProjectorARGB.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
@Override public VolatileProjector createAccumulateProjector( ArrayList< VolatileProjector > sourceProjectors, ArrayList< Source< ? > > sources, ArrayList< ? extends RandomAccessible< ? extends ARGBType > > sourceScreenImages, RandomAccessibleInterval< ARGBType > targetScreenImage, int numThreads, ExecutorService executorService) { return new MaximumProjectorARGB( sourceProjectors, sourceScreenImages, targetScreenImage, numThreads, executorService ); }
Example #27
Source File: MaximumProjectorARGB.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
public MaximumProjectorARGB( final ArrayList< VolatileProjector > sourceProjectors, final ArrayList< ? extends RandomAccessible< ? extends ARGBType > > sources, final RandomAccessibleInterval< ARGBType > target, final int numThreads, final ExecutorService executorService ) { super( sourceProjectors, sources, target, numThreads, executorService ); }
Example #28
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 5 votes |
/** * Downsample affected blocks of img. * @param source * @param img * @param affectedBlocks * @param steps * @param interval */ public static void downsampleBlocks( final RandomAccessible<UnsignedLongType> source, final CachedCellImg<UnsignedLongType, LongAccess> img, final TLongSet affectedBlocks, final int[] steps, final Interval interval) { final BlockSpec blockSpec = new BlockSpec(img.getCellGrid()); final long[] intersectedCellMin = new long[blockSpec.grid.numDimensions()]; final long[] intersectedCellMax = new long[blockSpec.grid.numDimensions()]; LOG.debug("Initializing affected blocks: {}", affectedBlocks); for (final TLongIterator it = affectedBlocks.iterator(); it.hasNext(); ) { final long blockId = it.next(); blockSpec.fromLinearIndex(blockId); Arrays.setAll(intersectedCellMin, d -> blockSpec.min[d]); Arrays.setAll(intersectedCellMax, d -> blockSpec.max[d]); intersect(intersectedCellMin, intersectedCellMax, interval); if (isNonEmpty(intersectedCellMin, intersectedCellMax)) { LOG.trace("Downsampling for intersected min/max: {} {}", intersectedCellMin, intersectedCellMax); downsample(source, Views.interval(img, intersectedCellMin, intersectedCellMax), steps); } } }
Example #29
Source File: AccessBoxRandomAccessibleOnGet.java From paintera with GNU General Public License v2.0 | 5 votes |
public AccessBoxRandomAccessibleOnGet(final RandomAccessible<T> source) { this.source = source; min = new long[source.numDimensions()]; max = new long[source.numDimensions()]; sourceAccess = source.randomAccess(); }
Example #30
Source File: AveragingProjectorARGB.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
@Override public VolatileProjector createAccumulateProjector(ArrayList< VolatileProjector > sourceProjectors, ArrayList< Source< ? > > sources, ArrayList< ? extends RandomAccessible< ? extends ARGBType > > sourceScreenImages, RandomAccessibleInterval< ARGBType > targetScreenImage, int numThreads, ExecutorService executorService) { return new AveragingProjectorARGB( sourceProjectors, sourceScreenImages, targetScreenImage, numThreads, executorService ); }