本文整理汇总了Java中net.imglib2.RealRandomAccess类的典型用法代码示例。如果您正苦于以下问题:Java RealRandomAccess类的具体用法?Java RealRandomAccess怎么用?Java RealRandomAccess使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RealRandomAccess类属于net.imglib2包,在下文中一共展示了RealRandomAccess类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: debug
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
public void debug( double[] pt )
{
RealRandomAccess<T> rra = warpMagImg.realRandomAccess();
rra.setPosition( pt );
System.out.println("at ( 0 0 0 ): ");
System.out.println( "get val: " + rra.get());
double[] baseRes = warpMagImg.ra.base.apply( pt );
double[] warpRes = new double[ warpMagImg.ra.warp.numTargetDimensions() ];
warpMagImg.ra.warp.apply( pt, warpRes );
System.out.println( "base res: " + baseRes[0] + " " + baseRes[1]);
System.out.println( "warp res: " + warpRes[0] + " " + warpRes[1]);
}
示例2: render
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
public static < T extends Type< T > > void render( final RealRandomAccessible< T > source, final RandomAccessibleInterval< T > target, final RealTransform transform, final double dx )
{
final RealRandomAccessible< T > interpolant = Views.interpolate( Views.extendBorder( target ), new NearestNeighborInterpolatorFactory< T >() );
final RealRandomAccess< T > a = source.realRandomAccess();
final RealRandomAccess< T > b = interpolant.realRandomAccess();
for ( double y = 0; y < target.dimension( 1 ); y += dx )
{
a.setPosition( y, 1 );
for ( double x = 0; x < target.dimension( 0 ); x += dx )
{
a.setPosition( x, 0 );
transform.apply( a, b );
b.get().set( a.get() );
}
}
}
示例3: TileProcessor
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
public TileProcessor(int threadNumber,
List<ArrayList<RealRandomAccess<? extends RealType<?>>>> interpolators,
ArrayList<? extends ImageInterpolation<? extends RealType<?>>> input,
Vector<Chunk> threadChunks, int numImages, Img<T> output,
PixelFusion fusion, ClassifiedRegion[] currentTile,
ArrayList<InvertibleBoundable> transform, ImagePlus[] fusionImp,
int[] count, double positionsPerThread, double[] offset, int[] loopDim)
{
this.threadNumber = threadNumber;
this.threadChunks = threadChunks;
this.currentTile = currentTile;
this.transform = transform;
this.fusionImp = fusionImp;
this.count = count;
this.positionsPerThread = positionsPerThread;
this.offset = offset;
this.loopDim = loopDim;
in = getThreadInterpolators(interpolators, threadNumber, input, numImages);
inPos = new double[numImages][output.numDimensions()];
myFusion = fusion.copy();
out = output.randomAccess();
}
示例4:
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
/**
* Helper method to lazily initialize the input image interpolators,
* creating one list per thread.
*/
private
ArrayList<RealRandomAccess<? extends RealType<?>>>
getThreadInterpolators(
List<ArrayList<RealRandomAccess<? extends RealType<?>>>> interpolators,
int threadNumber,
ArrayList<? extends ImageInterpolation<? extends RealType<?>>> input,
int numImages)
{
ArrayList<RealRandomAccess<? extends RealType<?>>> in = null;
if (threadNumber >= interpolators.size()) {
in = new ArrayList<RealRandomAccess<? extends RealType<?>>>();
for (int i = 0; i < numImages; ++i) {
in.add(input.get(i).createInterpolator());
}
interpolators.add(in);
}
else {
in = interpolators.get(threadNumber);
}
return in;
}
示例5: copyInterpolatedGeneric
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
public static <T extends NumericType< T > > void copyInterpolatedGeneric( RandomAccessible< T > from, IterableInterval< T > to, double[] offset, double scale, InterpolatorFactory< T, RandomAccessible< T > > interpolatorFactory )
{
final int n = to.numDimensions();
final double[] fromPosition = new double[ n ];
Cursor< T > cursor = to.localizingCursor();
RealRandomAccess< T > interpolator = interpolatorFactory.create( from );
while ( cursor.hasNext() )
{
final T t = cursor.next();
for ( int d = 0; d < n; ++d )
{
fromPosition[ d ] = scale * cursor.getDoublePosition( d ) + offset[ d ];
}
interpolator.setPosition( fromPosition );
t.set( interpolator.get() );
}
}
示例6: getAccessor
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
/**
* 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();
}
示例7: defaultInterpolateTest
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
@Test
public void defaultInterpolateTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{10, 10}, new DoubleType());
Random r = new Random();
for (DoubleType d : img) {
d.set(r.nextDouble());
}
RealRandomAccess<DoubleType> il2 = Views.interpolate(img, new FloorInterpolatorFactory<DoubleType>()).realRandomAccess();
RealRandomAccess<DoubleType> opr = ops.transform().interpolateView(img, new FloorInterpolatorFactory<DoubleType>()).realRandomAccess();
il2.setPosition(new double[]{1.75, 5.34});
opr.setPosition(new double[]{1.75, 5.34});
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
il2.setPosition(new double[]{3, 7});
opr.setPosition(new double[]{3, 7});
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
il2.setPosition(new double[]{8.37, 3.97});
opr.setPosition(new double[]{8.37, 3.97});
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
示例8: mapInterval
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
public final static <T extends NumericType<T>> void mapInterval(
final KernelTransformFloatSeparable xfm,
final Img<T> src, final Img<T> tgt )
{
NLinearInterpolatorFactory<T> interp = new NLinearInterpolatorFactory<T>();
RealRandomAccess<T> sara = Views.interpolate( Views.extendZero(src), interp ).realRandomAccess();
Cursor<T> tc = tgt.cursor();
float[] pos = new float[src.numDimensions()];
while( tc.hasNext() ){
tc.fwd();
tc.localize(pos);
float[] srcPt = xfm.transformPoint( pos );
sara.setPosition( srcPt );
tc.get().set( sara.get() );
}
}
示例9: call
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
@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).";
}
示例10: call
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
@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 Cursor< FloatType > cursor = Views.iterable( transformedImg ).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 )
loop( cursor, ir, transform, s, t, offsetX, offsetY, offsetZ, imgSizeX, imgSizeY, imgSizeZ );
return portion + " finished successfully (transform input & no weights).";
}
示例11: upsample
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
public static <T extends RealType<T> & NativeType<T>> Img<T> upsample(Img<T> input, long[] out_size, Interpolator interpType){
int nDim = input.numDimensions();
if(nDim != out_size.length){
return input;
}
long[] in_size = new long[nDim];
input.dimensions(in_size);
float[] upfactor = new float[nDim];
for(int i=0; i<nDim; i++){
upfactor[i] = (float)out_size[i]/in_size[i];
}
RealRandomAccess< T > interpolant;
switch(interpType){
case Linear:
NLinearInterpolatorFactory<T> NLinterp_factory = new NLinearInterpolatorFactory<T>();
interpolant = Views.interpolate( Views.extendBorder( input ), NLinterp_factory ).realRandomAccess();
break;
case Lanczos:
LanczosInterpolatorFactory<T> LanczosInterp_factory = new LanczosInterpolatorFactory<T>();
interpolant = Views.interpolate( Views.extendBorder( input ), LanczosInterp_factory ).realRandomAccess();
break;
default: // NearestNeighbor:
NearestNeighborInterpolatorFactory<T> NNInterp_factory = new NearestNeighborInterpolatorFactory<T>();
interpolant = Views.interpolate( Views.extendBorder( input ), NNInterp_factory ).realRandomAccess();
break;
}
final ImgFactory< T > imgFactory = new ArrayImgFactory< T >();
final Img< T > output = imgFactory.create( out_size , input.firstElement().createVariable() );
Cursor< T > out_cursor = output.localizingCursor();
float[] tmp = new float[2];
while(out_cursor.hasNext()){
out_cursor.fwd();
for ( int d = 0; d < nDim; ++d )
tmp[ d ] = out_cursor.getFloatPosition(d) /upfactor[d];
interpolant.setPosition(tmp);
out_cursor.get().setReal( Math.round( interpolant.get().getRealFloat() ) );
}
return output;
}
示例12: copyRealRandomAccess
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
@Override
public RealRandomAccess<FloatType> copyRealRandomAccess()
{
final BlendingRealRandomAccess r = new BlendingRealRandomAccess( interval, border, blending );
r.setPosition( this );
return r;
}
示例13: copyToImageStack
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
public static < T extends NumericType< T > & NativeType< T > > ImagePlus copyToImageStack( final RealRandomAccessible< T > rai, final Interval itvl )
{
final long[] dimensions = new long[ itvl.numDimensions() ];
itvl.dimensions( dimensions );
// create the image plus image
final T t = rai.realRandomAccess().get();
final ImagePlusImgFactory< T > factory = new ImagePlusImgFactory< T >();
final ImagePlusImg< T, ? > target = factory.create( itvl, t );
double k = 0;
final long N = dimensions[ 0 ] * dimensions[ 1 ] * dimensions[ 2 ];
final net.imglib2.Cursor< T > c = target.cursor();
final RealRandomAccess< T > ra = rai.realRandomAccess();
while ( c.hasNext() )
{
c.fwd();
ra.setPosition( c );
c.get().set( ra.get() );
if ( k % 10000 == 0 )
{
IJ.showProgress( k / N );
}
k++;
}
IJ.showProgress( 1.1 );
try
{
return target.getImagePlus();
}
catch ( final ImgLibException e )
{
e.printStackTrace();
}
return null;
}
示例14: processTile
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
/**
* Intermediate helper method to delegate to
* {@link #processTile(ClassifiedRegion, int[], int, PixelFusion, ArrayList, ArrayList, LocalizableByDimCursor, float[], int[], int, int[], long[], ImagePlus)}
*/
private void processTile(ClassifiedRegion r, int depth,
PixelFusion myFusion, ArrayList<InvertibleBoundable> transform,
ArrayList<RealRandomAccess<? extends RealType<?>>> in,
RandomAccess<T> out, double[][] inPos,
int threadNumber, int[] count, long[] lastDraw, ImagePlus fusionImp)
throws NoninvertibleModelException
{
processTile(r, r.classArray(), depth, myFusion, transform, in, out,
inPos, threadNumber, count, lastDraw, fusionImp);
}
示例15: processReal
import net.imglib2.RealRandomAccess; //导入依赖的package包/类
static private final <T extends RealType<T>> Img<T> processReal(final Img<T> img, final long[] dim, final Mode mode) throws Exception {
final Img<T> res = img.factory().create(dim, img.firstElement().createVariable());
InterpolatorFactory<T,RandomAccessible<T>> ifac;
switch (mode) {
case LINEAR:
ifac = new NLinearInterpolatorFactory<T>();
break;
case NEAREST_NEIGHBOR:
ifac = new NearestNeighborInterpolatorFactory<T>();
break;
default:
throw new Exception("Resample: unknown mode!");
}
final RealRandomAccess<T> inter = ifac.create(Views.extend(img, new OutOfBoundsMirrorFactory<T,Img<T>>(OutOfBoundsMirrorFactory.Boundary.SINGLE)));
final Cursor<T> c2 = res.localizingCursor();
final float[] s = new float[dim.length];
for (int i=0; i<s.length; i++) s[i] = (float)img.dimension(i) / dim[i];
final long[] d = new long[dim.length];
final float[] p = new float[dim.length];
while (c2.hasNext()) {
c2.fwd();
c2.localize(d); // TODO "localize" seems to indicate the opposite of what it does
for (int i=0; i<d.length; i++) p[i] = d[i] * s[i];
inter.move(p);
c2.get().set(inter.get());
}
return res;
}