net.imglib2.RealRandomAccessible Java Examples
The following examples show how to use
net.imglib2.RealRandomAccessible.
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: MaskedSource.java From paintera with GNU General Public License v2.0 | 6 votes |
private void setAtMaskLevel( final RealRandomAccessible<UnsignedLongType> mask, final RealRandomAccessible<VolatileUnsignedLongType> vmask, final int maskLevel, final UnsignedLongType value, final Predicate<UnsignedLongType> isPaintedForeground) { this.dMasks[maskLevel] = Converters.convert( mask, (input, output) -> output.set(isPaintedForeground.test(input) ? value : INVALID), new UnsignedLongType()); this.tMasks[maskLevel] = Converters.convert( vmask, (input, output) -> { final boolean isValid = input.isValid(); output.setValid(isValid); if (isValid) { output.get().set(input.get().get() > 0 ? value : INVALID); } }, new VolatileUnsignedLongType()); }
Example #2
Source File: RasterViewTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void defaultRasterTest() { 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()); } RealRandomAccessible<DoubleType> realImg = Views.interpolate(img, new FloorInterpolatorFactory<DoubleType>()); RandomAccessibleOnRealRandomAccessible<DoubleType> il2 = Views.raster(realImg); RandomAccessibleOnRealRandomAccessible<DoubleType> opr = ops.transform().rasterView(realImg); Cursor<DoubleType> il2C = Views.interval(il2, img).localizingCursor(); RandomAccess<DoubleType> oprRA = Views.interval(opr, img).randomAccess(); while (il2C.hasNext()) { il2C.next(); oprRA.setPosition(il2C); assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10); } }
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: TransformNamespace.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * Returns a {@link RealRandomAccessible} using interpolation * * @param input the {@link EuclideanSpace} to be interpolated * @param factory the {@link InterpolatorFactory} to provide interpolators for * source * @return */ @OpMethod( op = net.imagej.ops.transform.interpolateView.DefaultInterpolateView.class) public <T, I extends EuclideanSpace> RealRandomAccessible<T> interpolateView( final I input, final InterpolatorFactory<T, I> factory) { return (RealRandomAccessible<T>) ops().run( Ops.Transform.InterpolateView.class, input, factory); }
Example #5
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 5 votes |
private void setMasks( final RealRandomAccessible<UnsignedLongType> mask, final RealRandomAccessible<VolatileUnsignedLongType> vmask, final int maskLevel, final UnsignedLongType value, final Predicate<UnsignedLongType> isPaintedForeground) { setAtMaskLevel(mask, vmask, maskLevel, value, isPaintedForeground); LOG.debug("Created mask at scale level {}", maskLevel); setMaskScaleLevels(maskLevel); }
Example #6
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 5 votes |
private void setMaskScaleLevels(final int maskLevel) { final RealRandomAccessible<UnsignedLongType> dMask = this.dMasks[maskLevel]; final RealRandomAccessible<VolatileUnsignedLongType> tMask = this.tMasks[maskLevel]; // get mipmap transforms final AffineTransform3D[] levelToFullResTransform = new AffineTransform3D[getNumMipmapLevels()]; final AffineTransform3D fullResTransform = new AffineTransform3D(); getSourceTransform(0, 0, fullResTransform); for (int level = 0; level < getNumMipmapLevels(); ++level) { levelToFullResTransform[level] = new AffineTransform3D(); getSourceTransform(0, level, levelToFullResTransform[level]); levelToFullResTransform[level].preConcatenate(fullResTransform.inverse()); } for (int level = 0; level < getNumMipmapLevels(); ++level) { if (level != maskLevel) { final AffineTransform3D maskToLevelTransform = new AffineTransform3D(); maskToLevelTransform.preConcatenate(levelToFullResTransform[maskLevel]).preConcatenate(levelToFullResTransform[level].inverse()); this.dMasks[level] = RealViews.affineReal(dMask, maskToLevelTransform); this.tMasks[level] = RealViews.affineReal(tMask, maskToLevelTransform); } } }
Example #7
Source File: LabelSourceStateMergeDetachHandler.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public void accept(final MouseEvent e) { final long lastSelection = selectedIds.getLastSelection(); if (lastSelection == Label.INVALID) { return; } final AffineTransform3D screenScaleTransform = new AffineTransform3D(); viewer.getRenderUnit().getScreenScaleTransform(0, screenScaleTransform); final int level = viewer.getState().getBestMipMapLevel(screenScaleTransform, source); final AffineTransform3D affine = new AffineTransform3D(); source.getSourceTransform(0, level, affine); final RealRandomAccessible<? extends IntegerType<?>> transformedSource = RealViews .transformReal( source.getInterpolatedDataSource(0, level, Interpolation.NEARESTNEIGHBOR), affine); final RealRandomAccess<? extends IntegerType<?>> access = transformedSource.realRandomAccess(); viewer.getMouseCoordinates(access); access.setPosition(0L, 2); viewer.displayToGlobalCoordinates(access); final IntegerType<?> val = access.get(); final long id = val.getIntegerLong(); if (FOREGROUND_CHECK.test(id)) { final Optional<Detach> detach = assignment.getDetachAction(id, lastSelection); detach.ifPresent(assignment::apply); } }
Example #8
Source File: MultiResolutionRendererGeneric.java From paintera with GNU General Public License v2.0 | 5 votes |
private static <T> RandomAccessible<T> getTransformedSource( final Source<T> source, final int timepoint, final AffineTransform3D viewerTransform, final AffineTransform3D screenScaleTransform, final int mipmapIndex, final CacheHints cacheHints, final Interpolation interpolation) { final RandomAccessibleInterval<T> img = source.getSource(timepoint, mipmapIndex); if (VolatileCachedCellImg.class.isInstance(img)) ((VolatileCachedCellImg<?, ?>) img).setCacheHints(cacheHints); final RealRandomAccessible<T> ipimg = source.getInterpolatedSource(timepoint, mipmapIndex, interpolation); final AffineTransform3D sourceToScreen = viewerTransform.copy(); final AffineTransform3D sourceTransform = new AffineTransform3D(); source.getSourceTransform(timepoint, mipmapIndex, sourceTransform); sourceToScreen.concatenate(sourceTransform); sourceToScreen.preConcatenate(screenScaleTransform); LOG.debug( "Getting transformed source {} (name={}) for t={} level={} transform={} screen-scale={} hints={} " + "interpolation={}", source, source.getName(), timepoint, mipmapIndex, sourceToScreen, screenScaleTransform, cacheHints, interpolation ); return RealViews.affine(ipimg, sourceToScreen); }
Example #9
Source File: RealRandomAccessibleTriple.java From paintera with GNU General Public License v2.0 | 5 votes |
public RealRandomAccessibleTriple( final RealRandomAccessible<A> sourceA, final RealRandomAccessible<B> sourceB, final RealRandomAccessible<C> sourceC) { this.sourceA = sourceA; this.sourceB = sourceB; this.sourceC = sourceC; }
Example #10
Source File: AbstractRealOutOfBoundsValue.java From paintera with GNU General Public License v2.0 | 5 votes |
public < F extends RealInterval & RealRandomAccessible< T > > AbstractRealOutOfBoundsValue( final F f ) { super( f.numDimensions() ); this.sampler = f.realRandomAccess(); min = new double[ n ]; f.realMin( min ); max = new double[ n ]; f.realMax( max ); dimIsOutOfBounds = new boolean[ n ]; }
Example #11
Source File: VisitEveryDisplayPixel.java From paintera with GNU General Public License v2.0 | 5 votes |
public static <D> void visitEveryDisplayPixel( final DataSource<D, ?> dataSource, final ViewerPanelFX viewer, final Consumer<D> doAtPixel) { final ViewerState viewerState = viewer.getState().copy(); final AffineTransform3D viewerTransform = new AffineTransform3D(); viewerState.getViewerTransform(viewerTransform); final AffineTransform3D screenScaleTransform = new AffineTransform3D(); viewer.getRenderUnit().getScreenScaleTransform(0, screenScaleTransform); final int level = viewerState.getBestMipMapLevel(screenScaleTransform, dataSource); final AffineTransform3D sourceTransform = new AffineTransform3D(); dataSource.getSourceTransform(0, level, sourceTransform); final RealRandomAccessible<D> interpolatedSource = dataSource.getInterpolatedDataSource(0, level, Interpolation.NEARESTNEIGHBOR); final RealTransformRealRandomAccessible<D, InverseRealTransform> transformedSource = RealViews.transformReal( interpolatedSource, sourceTransform); final int w = (int) viewer.getWidth(); final int h = (int) viewer.getHeight(); final IntervalView<D> dataOnScreen = Views.interval( Views.hyperSlice( RealViews.affine(transformedSource, viewerTransform), 2, 0), new FinalInterval(w, h)); final Cursor<D> cursor = Views.flatIterable(dataOnScreen).cursor(); while (cursor.hasNext()) doAtPixel.accept(cursor.next()); }
Example #12
Source File: TransformedRealRandomAccessibleInterval.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
/** * @param realRandomAccessible - some {@link RealRandomAccessible} that we transform * @param transformedInterval - the interval after applying the transform that it is defined on * @param transform - the affine transformation * @param offset - an additional translational offset */ public TransformedRealRandomAccessibleInterval( final RealRandomAccessible< T > realRandomAccessible, final T zero, final Interval transformedInterval, final AffineTransform3D transform, final long[] offset ) { this.realRandomAccessible = realRandomAccessible; this.zero = zero; this.transformedInterval = transformedInterval; this.transform = transform; this.offset = offset; }
Example #13
Source File: TransformedInterpolatedRealRandomAccess.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public TransformedInterpolatedRealRandomAccess( final RealRandomAccessible< T > realRandomAccessible, final T zero, final Interval transformedInterval, final AffineTransform3D transform, final int[] offset ) { super( realRandomAccessible.numDimensions() ); this.transformedInterval = transformedInterval; this.zero = zero; this.realRandomAccessible = realRandomAccessible; this.transform = transform; this.offset = new int[ offset.length ]; for ( int d = 0; d < n; ++d ) this.offset[ d ] = offset[ d ]; this.realRandomAccess = realRandomAccessible.realRandomAccess(); final double[] imatrix = transform.inverse().getRowPackedCopy(); this.i00 = imatrix[ 0 ]; this.i01 = imatrix[ 1 ]; this.i02 = imatrix[ 2 ]; this.i03 = imatrix[ 3 ]; this.i10 = imatrix[ 4 ]; this.i11 = imatrix[ 5 ]; this.i12 = imatrix[ 6 ]; this.i13 = imatrix[ 7 ]; this.i20 = imatrix[ 8 ]; this.i21 = imatrix[ 9 ]; this.i22 = imatrix[ 10 ]; this.i23 = imatrix[ 11 ]; this.tmp = new float[ n ]; }
Example #14
Source File: ProcessSequentialPortionWeights.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public ProcessSequentialPortionWeights( final ImagePortion portion, final ArrayList< RandomAccessibleInterval< T > > imgs, final ArrayList< ArrayList< RealRandomAccessible< FloatType > > > weights, final InterpolatorFactory< T, RandomAccessible< T > > interpolatorFactory, final AffineTransform3D[] transforms, final Img< T > fusedImg, final Img< FloatType > weightImg, final BoundingBoxGUI bb ) { super( portion, imgs, interpolatorFactory, transforms, fusedImg, weightImg, bb ); this.weights = weights; }
Example #15
Source File: ProcessParalellPortionWeight.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public ProcessParalellPortionWeight( final ImagePortion portion, final ArrayList< RandomAccessibleInterval< T > > imgs, final ArrayList< RealRandomAccessible< FloatType > > weights, final InterpolatorFactory< T, RandomAccessible< T > > interpolatorFactory, final AffineTransform3D[] transforms, final Img< T > fusedImg, final BoundingBoxGUI bb ) { super( portion, imgs, interpolatorFactory, transforms, fusedImg, bb ); this.weights = weights; }
Example #16
Source File: ProcessSequentialPortionWeight.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public ProcessSequentialPortionWeight( final ImagePortion portion, final ArrayList< RandomAccessibleInterval< T > > imgs, final ArrayList< RealRandomAccessible< FloatType > > weights, final InterpolatorFactory< T, RandomAccessible< T > > interpolatorFactory, final AffineTransform3D[] transforms, final Img< T > fusedImg, final Img< FloatType > weightImg, final BoundingBoxGUI bb ) { super( portion, imgs, interpolatorFactory, transforms, fusedImg, weightImg, bb ); this.weights = weights; }
Example #17
Source File: ProcessParalellPortionWeights.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public ProcessParalellPortionWeights( final ImagePortion portion, final ArrayList< RandomAccessibleInterval< T > > imgs, final ArrayList< ArrayList< RealRandomAccessible< FloatType > > > weights, final InterpolatorFactory< T, RandomAccessible< T > > interpolatorFactory, final AffineTransform3D[] transforms, final Img< T > fusedImg, final BoundingBoxGUI bb ) { super( portion, imgs, interpolatorFactory, transforms, fusedImg, bb ); this.weights = weights; }
Example #18
Source File: ProcessFusion.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
protected < T extends RealType< T > > ArrayList< RealRandomAccessible< FloatType > > getAllWeights( final RandomAccessibleInterval< T > img, final ViewDescription desc, final ImgLoader imgLoader ) { final ArrayList< RealRandomAccessible< FloatType > > weigheners = new ArrayList< RealRandomAccessible< FloatType > >(); if ( useBlending ) weigheners.add( getBlending( new FinalInterval( img ), desc, imgLoader ) ); if ( useContentBased ) weigheners.add( getContentBased( img, desc, imgLoader ) ); return weigheners; }
Example #19
Source File: ShapeInterpolationMode.java From paintera with GNU General Public License v2.0 | 5 votes |
private static <R extends RealType<R>, T extends NativeType<T> & RealType<T>> RealRandomAccessible<T> getInterpolatedDistanceTransformMask( final RandomAccessibleInterval<R> dt1, final RandomAccessibleInterval<R> dt2, final double distance, final T targetValue, final AffineTransform3D transformToSource) { final RandomAccessibleInterval<R> distanceTransformStack = Views.stack(dt1, dt2); final R extendValue = Util.getTypeFromInterval(distanceTransformStack).createVariable(); extendValue.setReal(extendValue.getMaxValue()); final RealRandomAccessible<R> interpolatedDistanceTransform = Views.interpolate( Views.extendValue(distanceTransformStack, extendValue), new NLinearInterpolatorFactory<>() ); final RealRandomAccessible<R> scaledInterpolatedDistanceTransform = RealViews.affineReal( interpolatedDistanceTransform, new Scale3D(1, 1, -distance) ); final T emptyValue = targetValue.createVariable(); final RealRandomAccessible<T> interpolatedShape = Converters.convert( scaledInterpolatedDistanceTransform, (in, out) -> out.set(in.getRealDouble() <= 0 ? targetValue : emptyValue), emptyValue.createVariable() ); return RealViews.affineReal(interpolatedShape, transformToSource); }
Example #20
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public RealRandomAccessible<D> getInterpolatedDataSource(final int t, final int level, final Interpolation method) { final RealRandomAccessible<D> dataSourceToExtend; // ignore interpolation method because we cannot use linear interpolation on LabelMultisetType final RealRandomAccessible<D> interpolatedDataSource = this.source.getInterpolatedDataSource(t, level, Interpolation.NEARESTNEIGHBOR); if (!this.showCanvasOverBackground.get() || this.affectedBlocks.size() == 0 && this.currentMask == null) { LOG.debug("Hide canvas or no mask/canvas data present -- delegate to underlying source"); dataSourceToExtend = interpolatedDataSource; } else { final RealRandomAccessible<UnsignedLongType> dataCanvas = interpolateNearestNeighbor(Views.extendValue(this.dataCanvases[level], new UnsignedLongType(Label.INVALID))); final RealRandomAccessible<UnsignedLongType> dataMask = this.dMasks[level]; final RealRandomAccessibleTriple<D, UnsignedLongType, UnsignedLongType> composed = new RealRandomAccessibleTriple<>( interpolatedDataSource, dataCanvas, dataMask); dataSourceToExtend = new PickOne<>(composed, pacD.copyWithDifferentNumOccurences(numContainedVoxels(level))); } // extend the interpolated source with the specified out of bounds value final RealInterval bounds = new FinalRealInterval(source.getDataSource(t, level)); final RealRandomAccessibleRealInterval<D> boundedDataSource = new FinalRealRandomAccessibleRealInterval<>(dataSourceToExtend, bounds); return new ExtendedRealRandomAccessibleRealInterval<>(boundedDataSource, new RealOutOfBoundsConstantValueFactory<>(extensionD.copy())); }
Example #21
Source File: ConvertedDataSource.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public RealRandomAccessible<U> getInterpolatedDataSource(final int t, final int level, final Interpolation method) { return Views.interpolate( Views.extend(getDataSource(t, level), new OutOfBoundsConstantValueFactory<> (dataTypeExtensionSupplier)), dataInterpolation.apply(method) ); }
Example #22
Source File: ConvertedDataSource.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public RealRandomAccessible<V> getInterpolatedSource(final int t, final int level, final Interpolation method) { return Views.interpolate( Views.extend(getSource(t, level), new OutOfBoundsConstantValueFactory<>(typeExtensionSupplier)), interpolation.apply(method) ); }
Example #23
Source File: RandomAccessibleIntervalDataSource.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public RealRandomAccessible<D> getInterpolatedDataSource(final int t, final int level, final Interpolation method) { LOG.debug("Requesting data source at t={}, level={} with interpolation {}: ", t, level, method); return Views.interpolate( Views.extendValue(getDataSource(t, level), dataTypeSupplier.get()), dataInterpolation.apply(method) ); }
Example #24
Source File: RandomAccessibleIntervalDataSource.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public RealRandomAccessible<T> getInterpolatedSource(final int t, final int level, final Interpolation method) { LOG.debug("Requesting source at t={}, level={} with interpolation {}: ", t, level, method); return Views.interpolate( Views.extendValue(getSource(t, level), typeSupplier.get()), interpolation.apply(method) ); }
Example #25
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 5 votes |
public void setMask( final MaskInfo<UnsignedLongType> maskInfo, final RealRandomAccessible<UnsignedLongType> mask, final RealRandomAccessible<VolatileUnsignedLongType> vmask, final Invalidate<?> invalidate, final Invalidate<?> volatileInvalidate, final Runnable shutdown, final Predicate<UnsignedLongType> isPaintedForeground) throws MaskInUse { synchronized (this) { final boolean canSetMask = !isCreatingMask && currentMask == null && !isApplyingMask.get() && !isPersisting; LOG.debug("Can set mask? {}", canSetMask); if (!canSetMask) { LOG.error( "Currently processing, cannot set new mask: persisting? {} mask in use? {}", isPersisting, currentMask ); throw new MaskInUse("Busy, cannot set new mask."); } this.isCreatingMask = true; } setMasks(mask, vmask, maskInfo.level, maskInfo.value, isPaintedForeground); synchronized (this) { final RandomAccessibleInterval<UnsignedLongType> rasteredMask = Views.interval(Views.raster(mask), source.getSource(0, maskInfo.level)); // TODO how to get invalidateVolatile here? this.currentMask = new Mask<>(maskInfo, rasteredMask, invalidate, volatileInvalidate, shutdown); this.isCreatingMask = false; } }
Example #26
Source File: ShapeInterpolationMode.java From paintera with GNU General Public License v2.0 | 5 votes |
private static RealRandomAccessible<UnsignedLongType> getTransformedMask(final Mask<UnsignedLongType> mask, final AffineTransform3D transform) { final RealRandomAccessible<UnsignedLongType> interpolatedMask = Views.interpolate( Views.extendValue(mask.mask, new UnsignedLongType(Label.OUTSIDE)), new NearestNeighborInterpolatorFactory<>() ); return RealViews.affine(interpolatedMask, transform); }
Example #27
Source File: ShapeInterpolationMode.java From paintera with GNU General Public License v2.0 | 5 votes |
private RandomAccessibleInterval<UnsignedLongType> getTransformedMaskSection(final SectionInfo sectionInfo) { final RealInterval sectionBounds = sectionInfo.sourceToDisplayTransform.estimateBounds(sectionInfo.sourceBoundingBox); final Interval sectionInterval = Intervals.smallestContainingInterval(sectionBounds); final RealRandomAccessible<UnsignedLongType> transformedMask = getTransformedMask(sectionInfo.mask, sectionInfo.sourceToDisplayTransform); final RandomAccessibleInterval<UnsignedLongType> transformedMaskInterval = Views.interval(Views.raster(transformedMask), sectionInterval); return Views.hyperSlice(transformedMaskInterval, 2, 0l); }
Example #28
Source File: MaskedSource.java From paintera with GNU General Public License v2.0 | 5 votes |
@Override public RealRandomAccessible<T> getInterpolatedSource(final int t, final int level, final Interpolation method) { final RealRandomAccessible<T> sourceToExtend; // ignore interpolation method because we cannot use linear interpolation on LabelMultisetType final RealRandomAccessible<T> interpolatedSource = this.source.getInterpolatedSource(t, level, Interpolation.NEARESTNEIGHBOR); if (!this.showCanvasOverBackground.get() || this.affectedBlocks.size() == 0 && this.currentMask == null) { LOG.debug("Hide canvas or no mask/canvas data present -- delegate to underlying source"); sourceToExtend = interpolatedSource; } else { final RealRandomAccessible<VolatileUnsignedLongType> canvas = interpolateNearestNeighbor(Views.extendValue(this.canvases[level].getRai(), new VolatileUnsignedLongType(Label.INVALID))); final RealRandomAccessible<VolatileUnsignedLongType> mask = this.tMasks[level]; final RealRandomAccessibleTriple<T, VolatileUnsignedLongType, VolatileUnsignedLongType> composed = new RealRandomAccessibleTriple<>( interpolatedSource, canvas, mask ); sourceToExtend = new PickOne<>(composed, pacT.copyWithDifferentNumOccurences(numContainedVoxels(level))); } // extend the interpolated source with the specified out of bounds value final RealInterval bounds = new FinalRealInterval(source.getSource(t, level)); final RealRandomAccessibleRealInterval<T> boundedSource = new FinalRealRandomAccessibleRealInterval<>(sourceToExtend, bounds); return new ExtendedRealRandomAccessibleRealInterval<>(boundedSource, new RealOutOfBoundsConstantValueFactory<>(extensionT.copy())); }
Example #29
Source File: ProcessSequentialPortionWeights.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
@Override public String call() throws Exception { final int numViews = imgs.size(); // make the interpolators, weights and get the transformations final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews ); final ArrayList< ArrayList< RealRandomAccess< FloatType > > > weightAccess = new ArrayList< ArrayList< RealRandomAccess< FloatType > > >(); final int[][] imgSizes = new int[ numViews ][ 3 ]; for ( int i = 0; i < numViews; ++i ) { final RandomAccessibleInterval< T > img = imgs.get( i ); imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) }; interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() ); final ArrayList< RealRandomAccess< FloatType > > list = new ArrayList< RealRandomAccess< FloatType > >(); for ( final RealRandomAccessible< FloatType > rra : weights.get( i ) ) list.add( rra.realRandomAccess() ); weightAccess.add( list ); } final Cursor< T > cursor = fusedImg.localizingCursor(); final Cursor< FloatType > cursorW = 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 ) { // move img cursor forward any get the value (saves one access) final T v = cursor.next(); cursor.localize( s ); // move weight cursor forward and get the value final FloatType w = cursorW.next(); if ( doDownSampling ) { s[ 0 ] *= downSampling; s[ 1 ] *= downSampling; s[ 2 ] *= downSampling; } s[ 0 ] += bb.min( 0 ); s[ 1 ] += bb.min( 1 ); s[ 2 ] += bb.min( 2 ); double sum = 0; double sumW = 0; for ( int i = 0; i < numViews; ++i ) { transforms[ i ].applyInverse( t, s ); if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) ) { final RealRandomAccess< T > r = interpolators.get( i ); r.setPosition( t ); double w1 = 1; for ( final RealRandomAccess< FloatType > weight : weightAccess.get( i ) ) { weight.setPosition( t ); w1 *= weight.get().get(); } sum += r.get().getRealDouble() * w1; sumW += w1; } } if ( sumW > 0 ) { v.setReal( v.getRealFloat() + sum ); w.set( w.get() + (float)sumW ); } } return portion + " finished successfully (many weights)."; }
Example #30
Source File: ProcessParalellPortionWeights.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
@Override public String call() throws Exception { final int numViews = imgs.size(); // make the interpolators, weights and get the transformations final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews ); final ArrayList< ArrayList< RealRandomAccess< FloatType > > > weightAccess = new ArrayList< ArrayList< RealRandomAccess< FloatType > > >(); final int[][] imgSizes = new int[ numViews ][ 3 ]; for ( int i = 0; i < numViews; ++i ) { final RandomAccessibleInterval< T > img = imgs.get( i ); imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) }; interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() ); final ArrayList< RealRandomAccess< FloatType > > list = new ArrayList< RealRandomAccess< FloatType > >(); for ( final RealRandomAccessible< FloatType > rra : weights.get( i ) ) list.add( rra.realRandomAccess() ); weightAccess.add( list ); } final Cursor< T > cursor = fusedImg.localizingCursor(); final float[] s = new float[ 3 ]; final float[] t = new float[ 3 ]; cursor.jumpFwd( portion.getStartPosition() ); for ( int j = 0; j < portion.getLoopSize(); ++j ) { // move img cursor forward any get the value (saves one access) final T v = cursor.next(); cursor.localize( s ); if ( doDownSampling ) { s[ 0 ] *= downSampling; s[ 1 ] *= downSampling; s[ 2 ] *= downSampling; } s[ 0 ] += bb.min( 0 ); s[ 1 ] += bb.min( 1 ); s[ 2 ] += bb.min( 2 ); double sum = 0; double sumW = 0; for ( int i = 0; i < numViews; ++i ) { transforms[ i ].applyInverse( t, s ); if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) ) { final RealRandomAccess< T > r = interpolators.get( i ); r.setPosition( t ); double w = 1; for ( final RealRandomAccess< FloatType > weight : weightAccess.get( i ) ) { weight.setPosition( t ); w *= weight.get().get(); } sum += r.get().getRealDouble() * w; sumW += w; } } if ( sumW > 0 ) v.setReal( sum / sumW ); } return portion + " finished successfully (many weights)."; }