本文整理汇总了Java中net.imglib2.RealRandomAccess.setPosition方法的典型用法代码示例。如果您正苦于以下问题:Java RealRandomAccess.setPosition方法的具体用法?Java RealRandomAccess.setPosition怎么用?Java RealRandomAccess.setPosition使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.RealRandomAccess
的用法示例。
在下文中一共展示了RealRandomAccess.setPosition方法的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: 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() );
}
}
示例4: 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);
}
示例5: 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() );
}
}
示例6: 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;
}
示例7: 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;
}
示例8: call
import net.imglib2.RealRandomAccess; //导入方法依赖的package包/类
@Override
public String call() throws Exception
{
// make the blending and get the transformations
final RealRandomAccess< FloatType > wr = blending.realRandomAccess();
final Cursor< FloatType > cursorO = Views.iterable( overlapImg ).localizingCursor();
final Cursor< FloatType > cursorB = Views.iterable( blendingImg ).cursor();
final float[] s = new float[ 3 ];
final float[] t = new float[ 3 ];
cursorO.jumpFwd( portion.getStartPosition() );
cursorB.jumpFwd( portion.getStartPosition() );
for ( int j = 0; j < portion.getLoopSize(); ++j )
{
// move img cursor forward any get the value (saves one access)
final FloatType o = cursorO.next();
cursorO.localize( s );
// move weight cursor forward and get the value
final FloatType b = cursorB.next();
s[ 0 ] += offsetX;
s[ 1 ] += offsetY;
s[ 2 ] += offsetZ;
transform.applyInverse( t, s );
// compute weights in any part of the image (the border can be negative!)
wr.setPosition( t );
o.set( o.get() + 1 );
b.set( wr.get() );
}
return portion + " finished successfully (visualize weights).";
}
示例9: loop
import net.imglib2.RealRandomAccess; //导入方法依赖的package包/类
private static final void loop(
final Cursor< FloatType > cursor,
final Cursor< FloatType > cursorW,
final RealRandomAccess< FloatType > ir,
final RealRandomAccess< FloatType > wr,
final AffineTransform3D transform,
final float[] s, final float[] t,
final int offsetX, final int offsetY, final int offsetZ,
final int imgSizeX, final int imgSizeY, final int imgSizeZ )
{
// move img cursor forward any get the value (saves one access)
final FloatType v = cursor.next();
cursor.localize( s );
// move weight cursor forward and get the value
final FloatType w = cursorW.next();
s[ 0 ] += offsetX;
s[ 1 ] += offsetY;
s[ 2 ] += offsetZ;
transform.applyInverse( t, s );
if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizeX, imgSizeY, imgSizeZ ) )
{
ir.setPosition( t );
// do not accept 0 values in the data where image data is present, 0 means no image data is available
// (used in MVDeconvolution.computeQuotient)
v.set( Math.max( MVDeconvolution.minValue, ir.get().get() ) );
}
// compute weights in any case (the border can be negative!)
wr.setPosition( t );
w.set( wr.get() );
}
示例10: loop
import net.imglib2.RealRandomAccess; //导入方法依赖的package包/类
private static final void loop(
final Cursor< FloatType > cursor,
final RealRandomAccess< FloatType > ir,
final AffineTransform3D transform,
final float[] s, final float[] t,
final int offsetX, final int offsetY, final int offsetZ,
final int imgSizeX, final int imgSizeY, final int imgSizeZ )
{
// move img cursor forward any get the value (saves one access)
final FloatType v = cursor.next();
cursor.localize( s );
s[ 0 ] += offsetX;
s[ 1 ] += offsetY;
s[ 2 ] += offsetZ;
transform.applyInverse( t, s );
if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizeX, imgSizeY, imgSizeZ ) )
{
ir.setPosition( t );
// do not accept 0 values in the data where image data is present, 0 means no image data is available
// (used in MVDeconvolution.computeQuotient)
v.set( Math.max( MVDeconvolution.minValue, ir.get().get() ) );
}
}
示例11: estimateFromMatrix
import net.imglib2.RealRandomAccess; //导入方法依赖的package包/类
public < T extends RealType< T >, W extends RealType< W > > RandomAccessibleInterval< double[] > estimateFromMatrix(
final RandomAccessibleInterval< T > correlations,
final double[] coordinates,
final AbstractLUTRealTransform transform,
final RandomAccessibleInterval< W > estimateWeightMatrix,
final Options options )
{
final int range = options.comparisonRange;
final boolean forceMonotonicity = options.forceMonotonicity;
final T correlationsNaNExtension = correlations.randomAccess().get().copy();
correlationsNaNExtension.setReal( Double.NaN );
final RealRandomAccessible< T > extendedInterpolatedCorrelations = Views.interpolate( Views.extendValue( correlations, correlationsNaNExtension ), new NLinearInterpolatorFactory<>() );
final RealTransformRealRandomAccessible< T, InverseRealTransform > transformedCorrelations = RealViews.transformReal( extendedInterpolatedCorrelations, transform );
// TODO extend border or value (nan)?
final RealRandomAccessible< W > extendedInterpolatedWeights = Views.interpolate( Views.extendBorder( estimateWeightMatrix ), new NLinearInterpolatorFactory<>() );
final RealTransformRealRandomAccessible< W, InverseRealTransform > transformedWeights = RealViews.transformReal( extendedInterpolatedWeights, transform );
final RealRandomAccess< T > access1 = transformedCorrelations.realRandomAccess();
final RealRandomAccess< T > access2 = transformedCorrelations.realRandomAccess();
final RealRandomAccess< W > wAccess1 = transformedWeights.realRandomAccess();
final RealRandomAccess< W > wAccess2 = transformedWeights.realRandomAccess();
init( range );
for ( int z = 0; z < coordinates.length; ++z )
{
access1.setPosition( z, 1 );
access1.setPosition( z, 0 );
transform.apply( access1, access1 );
access2.setPosition( access1 );
wAccess1.setPosition( access1 );
wAccess2.setPosition( access1 );
double currentMin1 = Double.MAX_VALUE;
double currentMin2 = Double.MAX_VALUE;
// should w go in pairwise?
for ( int k = 0; k <= range; ++k, access1.fwd( 0 ), access2.bck( 0 ), wAccess1.fwd( 0 ), wAccess2.bck( 0 ) )
{
final double a1 = access1.get().getRealDouble();
final double a2 = access2.get().getRealDouble();
if ( !Double.isNaN( a1 ) && a1 > 0.0 && ( !forceMonotonicity || a1 < currentMin1 ) )
{
currentMin1 = a1;
add( z, k, a1, wAccess1.get().getRealDouble() );
}
if ( !Double.isNaN( a2 ) && a2 > 0.0 && ( !forceMonotonicity || a2 < currentMin2 ) )
{
currentMin2 = a2;
add( z, k, a2, wAccess2.get().getRealDouble() );
}
}
}
return estimate( coordinates.length );
}
示例12: estimateQuadraticFromMatrix
import net.imglib2.RealRandomAccess; //导入方法依赖的package包/类
public static < T extends RealType< T >, W extends RealType< W > > void estimateQuadraticFromMatrix(
final RandomAccessibleInterval< T > correlations,
final double[] scalingFactors,
final double[] coordinates,
final RandomAccessibleInterval< double[] > localFits,
final double regularizerWeight,
final int comparisonRange,
final int nIterations,
final RandomAccessibleInterval< W > pairwiseWeights )
{
final double inverseRegularizerWeight = 1 - regularizerWeight;
final RandomAccess< T > corrAccess = correlations.randomAccess();
final RandomAccess< W > wAccess = pairwiseWeights.randomAccess();
for ( int iter = 0; iter < nIterations; ++iter )
{
final Cursor< double[] > fitCursor = Views.iterable( localFits ).cursor();
for ( int n = 0; fitCursor.hasNext(); ++n )
{
// is this allocation expensive? should this occur one loop
// further outside?
final double[] oldScalingFactors = scalingFactors.clone();
corrAccess.setPosition( n, 0 );
wAccess.setPosition( n, 0 );
final double[] lf = fitCursor.next();
final RealRandomAccessible< DoubleType > interpolatedFit = Views.interpolate( Views.extendValue( ArrayImgs.doubles( lf, lf.length ), new DoubleType( Double.NaN ) ), new NLinearInterpolatorFactory< DoubleType >() );
final RealRandomAccess< DoubleType > ra = interpolatedFit.realRandomAccess();
double enumeratorSum = 0.0;
double denominatorSum = 0.0;
final int minVal = Math.max( n - comparisonRange, 0 );
final int maxVal = Math.min( n + comparisonRange, scalingFactors.length );
for ( int i = minVal; i < maxVal; ++i )
{
if ( i == n )
continue;
corrAccess.setPosition( i, 1 );
wAccess.setPosition( i, 1 );
ra.setPosition( Math.abs( coordinates[ i ] - coordinates[ n ] ), 0 );
// fits are negative because LUTRealtransform requires
// increasing function
final double fitVal = -ra.get().get();
final double measure = corrAccess.get().getRealDouble();
if ( Double.isNaN( fitVal ) || Double.isNaN( measure ) || measure <= 0.0 )
continue;
final double w = wAccess.get().getRealDouble();
final double prod = oldScalingFactors[ i ] * measure;
final double h = w * prod;
enumeratorSum += h * fitVal;
denominatorSum += h * prod;
}
final double result = enumeratorSum / denominatorSum * inverseRegularizerWeight + regularizerWeight * oldScalingFactors[ n ];
if ( !Double.isNaN( result ) )
scalingFactors[ n ] = result;
}
}
}
示例13: extractPSFLocal
import net.imglib2.RealRandomAccess; //导入方法依赖的package包/类
/**
* Extracts the PSF by averaging the local neighborhood RANSAC correspondences
* @param size - the size in which the psf is extracted (in pixel units, z-scaling is ignored)
* @return - the psf, NOT z-scaling corrected
*/
protected static < T extends RealType< T > & NativeType< T > > ArrayImg< T, ? > extractPSFLocal(
final RandomAccessibleInterval< T > img,
final ArrayList< double[] > locations,
final long[] size )
{
final int numDimensions = size.length;
final ArrayImg< T, ? > psf = new ArrayImgFactory< T >().create( size, Views.iterable( img ).firstElement() );
// Mirror produces some artifacts ... so we use periodic
final RealRandomAccess< T > interpolator =
Views.interpolate( Views.extendPeriodic( img ), new NLinearInterpolatorFactory< T >() ).realRandomAccess();
final ArrayLocalizingCursor< T > psfCursor = psf.localizingCursor();
final long[] sizeHalf = size.clone();
for ( int d = 0; d < numDimensions; ++d )
sizeHalf[ d ] /= 2;
final int[] tmpI = new int[ size.length ];
final double[] tmpD = new double[ size.length ];
for ( final double[] position : locations )
{
psfCursor.reset();
while ( psfCursor.hasNext() )
{
psfCursor.fwd();
psfCursor.localize( tmpI );
for ( int d = 0; d < numDimensions; ++d )
tmpD[ d ] = tmpI[ d ] - sizeHalf[ d ] + position[ d ];
interpolator.setPosition( tmpD );
psfCursor.get().add( interpolator.get() );
}
}
return psf;
}
示例14: call
import net.imglib2.RealRandomAccess; //导入方法依赖的package包/类
@Override
public String call() throws Exception
{
// make the interpolators and get the transformations
final RealRandomAccess< T > r = Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess();
final int[] imgSize = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
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 );
transform.applyInverse( t, s );
if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSize[ 0 ], imgSize[ 1 ], imgSize[ 2 ] ) )
{
r.setPosition( t );
v.setReal( r.get().getRealFloat() );
}
}
return portion + " finished successfully (individual fusion, no weights).";
}
示例15: call
import net.imglib2.RealRandomAccess; //导入方法依赖的package包/类
@Override
public String call() throws Exception
{
final int numViews = imgs.size();
// make the interpolators and get the transformations
final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
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 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;
int 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 );
sum += r.get().getRealDouble();
++sumW;
}
}
if ( sumW > 0 )
{
v.setReal( v.getRealFloat() + sum );
w.set( w.get() + sumW );
}
}
return portion + " finished successfully (no weights).";
}