本文整理了Java中net.imglib2.util.Intervals
类的一些代码示例,展示了Intervals
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Intervals
类的具体详情如下:
包路径:net.imglib2.util.Intervals
类名称:Intervals
[英]Convenience methods for manipulating Interval.
[中]操作间隔的简便方法。
代码示例来源:origin: net.imglib2/imglib2
/**
* Creates an image with randomized content.
* @param type Pixel type
* @param interval Interval
*/
public < T extends NativeType< T > > RandomAccessibleInterval< T > nextImage( final T type, Interval interval )
{
long[] sizes = Intervals.dimensionsAsLongArray( interval );
long[] min = Intervals.minAsLongArray( interval );
return Views.translate( nextImage( type, sizes ), min );
}
代码示例来源:origin: imagej/imagej-ops
@Override
public boolean conforms() {
// conforms only if the kernel is sufficiently small
return Intervals.numElements(kernel) <= 9;
}
代码示例来源:origin: imagej/imagej-ops
public static <I1, I2, O> boolean compatible(
final RandomAccessibleInterval<I1> a, final IterableInterval<I2> b,
final RandomAccessibleInterval<O> c)
{
return Intervals.contains(a, b) && Intervals.contains(c, b);
}
代码示例来源:origin: imagej/imagej-ops
private static Interval slightlyEnlarge(RealInterval realInterval,
long border)
{
return Intervals.expand(Intervals.smallestContainingInterval(realInterval),
border);
}
代码示例来源:origin: net.imglib2/imglib2
static String intervalToString( Interval a )
{
return "{min=" + Arrays.toString( Intervals.minAsLongArray( a ) ) +
", max=" + Arrays.toString( Intervals.maxAsLongArray( a ) ) + "}";
}
代码示例来源:origin: imagej/imagej-ops
@Override
public RandomAccessibleInterval<T> calculate(RandomAccessibleInterval<T> input) {
final long[] newDims = Intervals.dimensionsAsLongArray(in());
for (int i = 0; i < Math.min(scaleFactors.length, in().numDimensions()); i++) {
newDims[i] = Math.round(in().dimension(i) * scaleFactors[i]);
}
IntervalView<T> interval = Views.interval(Views.raster(RealViews.affineReal(
Views.interpolate(Views.extendMirrorSingle(input), interpolator),
new Scale(scaleFactors))), new FinalInterval(newDims));
return interval;
}
代码示例来源:origin: net.imglib2/imglib2-algorithms
/**
* 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 gradient
* output image
* @param dimension
* along which dimension the partial derivatives are computed
*/
public static < T extends NumericType< T > > void gradientCentralDifference2( final RandomAccessible< T > source, final RandomAccessibleInterval< T > gradient, final int dimension )
{
final Cursor< T > front = Views.flatIterable( Views.interval( source, Intervals.translate( gradient, 1, dimension ) ) ).cursor();
final Cursor< T > back = Views.flatIterable( Views.interval( source, Intervals.translate( gradient, -1, dimension ) ) ).cursor();
for( final T t : Views.flatIterable( gradient ) )
{
t.set( front.next() );
t.sub( back.next() );
t.mul( 0.5 );
}
}
代码示例来源:origin: fiji/TrackMate
final Interval interval = Intervals.createMinSize( minsize );
final IntervalView< T > view = Views.zeroMin(Views.interval( Views.extendZero( img ), interval ) );
final RandomAccess< T > sourceRA = view.randomAccess( view );
final Cursor< T > targetCursor = crop.localizingCursor();
代码示例来源:origin: net.imglib2/imglib2
/**
* Expand a RandomAccessibleInterval as specified by border. Out of bounds
* pixels will be sampled by mirroring source. Boundary pixels are not
* repeated. Note that this requires that all dimensions of the source (F
* source) must be > 1.
*
* @param source
* the interval to expand.
* @return Expansion of the {@link RandomAccessibleInterval} source as
* specified by border.
*/
public static < T > IntervalView< T > expandMirrorSingle( final RandomAccessibleInterval< T > source, final long... border )
{
return interval( extendMirrorSingle( source ), Intervals.expand( source, border ) );
}
代码示例来源:origin: sc.fiji/bigdataviewer-core
final Interval cropBoundingBox = Intervals.smallestContainingInterval( IntervalBoundingBox.getBoundingBox( sourceCorners ) );
Interval sourceInterval = Intervals.intersect( cropBoundingBox, sourceImg );
if ( Intervals.isEmpty( sourceInterval ) )
minsize[ d ] = cropBoundingBox.min( d ) + cropBoundingBox.dimension( d ) / 2;
Arrays.fill( minsize, n, n * 2, 1 );
sourceInterval = Intervals.createMinSize( minsize );
croppedSourceImg = Views.zeroMin( Views.interval( Views.extendBorder( sourceImg ), sourceInterval ) );
croppedSourceTransform.set(
1, 0, 0, sourceInterval.min( 0 ),
代码示例来源:origin: net.imglib2/imglib2
/**
* Expand a RandomAccessibleInterval as specified by border. source will be
* extended with a periodic out-of-bounds strategy.
*
* @param source
* the interval to expand.
* @return Expansion of the {@link RandomAccessibleInterval} source as
* specified by border.
*/
public static < T > IntervalView< T > expandPeriodic( final RandomAccessibleInterval< T > source, final long... border )
{
return interval( extendPeriodic( source ), Intervals.expand( source, border ) );
}
代码示例来源:origin: net.imglib2/imglib2
/**
* Expand a RandomAccessibleInterval as specified by border. source will be
* extended with the zero-element of that data type.
*
* @param source
* the interval to expand.
* @return Expansion of the {@link RandomAccessibleInterval} source as
* specified by border.
*/
public static < T extends NumericType< T > > IntervalView< T > expandZero( final RandomAccessibleInterval< T > source, final long... border )
{
return interval( extendZero( source ), Intervals.expand( source, border ) );
}
代码示例来源:origin: net.imglib2/imglib2
/**
* Expand a RandomAccessibleInterval as specified by border. source will be
* extended with the border value.
*
* @param source
* the interval to expand.
* @return Expansion of the {@link RandomAccessibleInterval} source as
* specified by border.
*/
public static < T > IntervalView< T > expandBorder( final RandomAccessibleInterval< T > source, final long... border )
{
return interval( extendBorder( source ), Intervals.expand( source, border ) );
}
代码示例来源:origin: net.imglib2/imglib2-algorithm
/**
* Compute the partial derivative (central difference approximation) of source
* in a particular dimension:
* {@code d_f( x ) = ( f( x + e ) - f( x - e ) ) / 2},
* where {@code e} is the unit vector along that 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 result
* output image
* @param dimension
* along which dimension the partial derivatives are computed
*/
public static < T extends NumericType< T > > void gradientCentralDifference( final RandomAccessible< T > source,
final RandomAccessibleInterval< T > result, final int dimension )
{
final RandomAccessibleInterval< T > back = Views.interval( source, Intervals.translate( result, -1, dimension ) );
final RandomAccessibleInterval< T > front = Views.interval( source, Intervals.translate( result, 1, dimension ) );
LoopBuilder.setImages( result, back, front ).forEachPixel( ( r, b, f ) -> {
r.set( f );
r.sub( b );
r.mul( 0.5 );
} );
}
代码示例来源:origin: net.imglib2/imglib2
/**
* Expand a RandomAccessibleInterval as specified by border. Out of bounds
* pixels will be sampled by mirroring source. Boundary pixels are repeated.
*
* @param source
* the interval to expand.
* @return Expansion of the {@link RandomAccessibleInterval} source as
* specified by border.
*/
public static < T > IntervalView< T > expandMirrorDouble( final RandomAccessibleInterval< T > source, final long... border )
{
return interval( extendMirrorDouble( source ), Intervals.expand( source, border ) );
}
代码示例来源:origin: imagej/imagej-ops
private static <V> RandomAccessibleInterval<V> trim(
final RandomAccessibleInterval<V> image, final int[] blockSize)
{
final long[] min = Intervals.minAsLongArray(image);
final long[] max = Intervals.maxAsLongArray(image);
for (int d = 0; d < blockSize.length; d++) {
final long trimSize = image.dimension(d) % blockSize[d];
final long half = trimSize / 2;
min[d] += half;
max[d] -= trimSize - half;
}
return Views.interval(image, min, max);
}
}
代码示例来源:origin: net.imglib2/imglib2
/**
* Translate the source view by the given translation vector. Pixel
* <em>x</em> in the source view has coordinates <em>(x + translation)</em>
* in the resulting view.
*
* @param interval
* the source
* @param translation
* translation vector of the source view. The pixel at <em>x</em>
* in the source view becomes <em>(x + translation)</em> in the
* resulting view.
*/
public static < T > IntervalView< T > translate( final RandomAccessibleInterval< T > interval, final long... translation )
{
return Views.interval(
Views.translate( ( RandomAccessible< T > ) interval, translation ),
Intervals.translate( interval, translation ) );
}
代码示例来源:origin: imagej/imagej-ops
private static < T extends ValueEquals< T > > void testEqual( final RandomAccessibleInterval< T > rai1, final RandomAccessibleInterval< T > rai2 )
{
Assert.assertArrayEquals( Intervals.minAsLongArray( rai1 ), Intervals.minAsLongArray( rai2 ) );
Assert.assertArrayEquals( Intervals.maxAsLongArray( rai1 ), Intervals.maxAsLongArray( rai2 ) );
for ( final Pair< T, T > p : Views.interval( Views.pair( rai1, rai2 ), rai1 ) )
Assert.assertTrue( p.getA().valueEquals( p.getB() ) );
}
代码示例来源:origin: net.imglib2/imglib2
/**
* Checks if both images have equal intervals and content.
* A predicate must be given to check if two pixels are equal.
*/
public static < T, U > boolean imagesEqual( final RandomAccessibleInterval< ? extends T > a, final RandomAccessibleInterval< ? extends U > b, final BiPredicate< T, U > pixelEquals )
{
if ( !Intervals.equals( a, b ) )
return false;
for ( final Pair< ? extends T, ? extends U > pair : Views.interval( Views.pair( a, b ), b ) )
if ( !pixelEquals.test( pair.getA(), pair.getB() ) )
return false;
return true;
}
代码示例来源:origin: imagej/imagej-ops
@Test
public void testIntervalSubsampleSteps() {
Img<DoubleType> img = ArrayImgs.doubles(10,10);
MersenneTwisterFast r = new MersenneTwisterFast(SEED);
for (DoubleType d : img) {
d.set(r.nextDouble());
}
SubsampleIntervalView<DoubleType> expected = Views.subsample((RandomAccessibleInterval<DoubleType>) img, 2, 1);
SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2, 1);
Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 9 }).localizingCursor();
RandomAccess<DoubleType> oprRA = actual.randomAccess();
while (il2C.hasNext()) {
il2C.next();
oprRA.setPosition(il2C);
assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
}
assertTrue(Intervals.equals(expected, actual));
}
}
内容来源于网络,如有侵权,请联系作者删除!