本文整理汇总了Java中net.imglib2.view.Views.offsetInterval方法的典型用法代码示例。如果您正苦于以下问题:Java Views.offsetInterval方法的具体用法?Java Views.offsetInterval怎么用?Java Views.offsetInterval使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.view.Views
的用法示例。
在下文中一共展示了Views.offsetInterval方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import net.imglib2.view.Views; //导入方法依赖的package包/类
@Override
public RandomAccessibleInterval< T > get()
{
long[] lower = position.clone();
long[] upper = new long[ lower.length ];
for ( int d = 0; d < lower.length; d++ )
{
long m = min[ d ];
long s = stepSize[ d ];
long val = ( lower[ d ] - m ) * s + m;
lower[ d ] = val;
upper[ d ] = val + s - 1; // -1 if not offsetInterval
// if offsetInterval, use stepSize instead of upper
}
// use offsetInterval?
return Views.offsetInterval( extendedSource, lower, stepSize );
// return Views.interval( extendedSource, lower, upper );
}
示例2: calculate
import net.imglib2.view.Views; //导入方法依赖的package包/类
@Override
public RandomAccessibleInterval<T> calculate(final RandomAccessibleInterval<T> input, final Interval interval) {
boolean oneSizedDims = false;
if (dropSingleDimensions) {
for (int d = 0; d < interval.numDimensions(); d++) {
if (interval.dimension(d) == 1) {
oneSizedDims = true;
break;
}
}
}
if (Intervals.equals(input, interval) && !oneSizedDims)
return input;
if (!Intervals.contains(input, interval))
throw new RuntimeException("Intervals don't match!");
IntervalView<T> res = Views.offsetInterval(input, interval);
return oneSizedDims ? Views.dropSingletonDimensions(res) : res;
}
示例3: getIntegralImage
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Computes integral images of a given order and extends them such that
* {@link IntegralMean} et al work with them.
*
* @param input The RAI for which an integral image is computed
* @param order
* @return An extended integral image for the input RAI
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private RandomAccessibleInterval<RealType> getIntegralImage(
final RandomAccessibleInterval<I> input, final int order)
{
ExtendedRandomAccessibleInterval<I, RandomAccessibleInterval<I>> extendedInput =
Views.extend(input, outOfBoundsFactory);
FinalInterval expandedInterval = Intervals.expand(input, shape.getSpan()-1);
IntervalView<I> offsetInterval2 = Views.offsetInterval(extendedInput, expandedInterval);
RandomAccessibleInterval<RealType> img = null;
switch (order) {
case 1:
img = (RandomAccessibleInterval) integralImgOp.calculate(offsetInterval2);
break;
case 2:
img = (RandomAccessibleInterval) squareIntegralImgOp.calculate(offsetInterval2);
break;
}
img = addLeadingZeros(img);
return img;
}
示例4: removeLeadingZeros
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Removes leading 0s from integral image after composite creation.
*
* @param input Input RAI (can be a RAI of Composite)
* @return An extended and cropped version of input
*/
private <T> RandomAccessibleInterval<T> removeLeadingZeros(
final RandomAccessibleInterval<T> input)
{
// Remove 0s from integralImg by shifting its interval by +1
final long[] min = Intervals.minAsLongArray(input);
final long[] max = Intervals.maxAsLongArray(input);
for (int d = 0; d < input.numDimensions(); ++d) {
int correctedSpan = getShape().getSpan() - 1;
min[d] += (1 + correctedSpan);
max[d] -= correctedSpan;
}
// Define the Interval on the infinite random accessibles
final FinalInterval interval = new FinalInterval(min, max);
final RandomAccessibleInterval<T> extendedImg = Views.offsetInterval(Views
.extendBorder(input), interval);
return extendedImg;
}
示例5: sectionView
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Creates a {@link net.imglib2.View} of the given grid section in the
* interval
* <p>
* Fits the view inside the bounds of the interval.
* </p>
*
* @param interval An n-dimensional interval with binary elements
* @param sizes Sizes of the interval's dimensions
* @param coordinates Starting coordinates of the section
* @param sectionSize Size of the section (n * n * ... n)
* @return A view of the interval spanning n pixels in each dimension from the
* coordinates. Null if view couldn't be set inside the interval
*/
private static <B extends BooleanType<B>> IntervalView<B> sectionView(
final RandomAccessibleInterval<B> interval, final long[] sizes,
final long[] coordinates, final long sectionSize)
{
final int n = sizes.length;
final long[] startPosition = IntStream.range(0, n).mapToLong(i -> Math.max(
0, coordinates[i])).toArray();
final long[] endPosition = IntStream.range(0, n).mapToLong(i -> Math.min(
(sizes[i] - 1), (coordinates[i] + sectionSize - 1))).toArray();
final boolean badBox = IntStream.range(0, n).anyMatch(
d -> (startPosition[d] >= sizes[d]) || (endPosition[d] < 0) ||
(endPosition[d] < startPosition[d]));
if (badBox) {
return null;
}
final BoundingBox box = new BoundingBox(n);
box.update(startPosition);
box.update(endPosition);
return Views.offsetInterval(interval, box);
}
示例6: testSquare
import net.imglib2.view.Views; //导入方法依赖的package包/类
/** Test the op with a 2x2 square. The square is in the middle of a 4x4 img */
@Test
public void testSquare() throws Exception {
// SETUP
final Img<BitType> img = ArrayImgs.bits(4, 4);
final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
1, 1 }, new long[] { 2, 2 });
square.cursor().forEachRemaining(BitType::setOne);
// EXECUTE
final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
Boolean.TRUE);
// VERIFY
assertEquals("Wrong number of foreground elements in interval", 4,
countForeground(result));
final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
new long[] { 1, 1 }, new long[] { 2, 2 });
assertTrue("Wrong number of foreground elements in object", allForeground(
resultSquare));
}
示例7: testOutlineSquare
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Test the op with a 3x3 square with a hole in the middle. The square is in
* the middle of a 5x5 img
*/
@Test
public void testOutlineSquare() throws Exception {
// SETUP
final Img<BitType> img = ArrayImgs.bits(5, 5);
final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
1, 1 }, new long[] { 3, 3 });
square.cursor().forEachRemaining(BitType::setOne);
final RandomAccess<BitType> access = square.randomAccess();
access.setPosition(new long[] { 1, 1 });
access.get().setZero();
// EXECUTION
final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
Boolean.TRUE);
// VERIFY
assertEquals("Wrong number of foreground elements in interval", 8,
countForeground(result));
final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
new long[] { 1, 1 }, new long[] { 3, 3 });
assertEquals("Wrong number of foreground elements in object", 8,
countForeground(resultSquare));
assertPositionBackground(result, new long[] { 2, 2 });
}
示例8: testEdgeSquare
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Test the op with a 3x3 square starting from (0,1) in a 5x5 img
*
* @see Outline#compute(RandomAccessibleInterval, Boolean,
* RandomAccessibleInterval)
* @see #testEdgeSquare()
*/
@Test
public void testEdgeSquare() throws Exception {
// SETUP
final Img<BitType> img = ArrayImgs.bits(5, 5);
final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
0, 1 }, new long[] { 3, 3 });
square.cursor().forEachRemaining(BitType::setOne);
// EXECUTION
final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
Boolean.TRUE);
// VERIFY
assertEquals("Wrong number of foreground elements in interval", 7,
countForeground(result));
final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
new long[] { 0, 1 }, new long[] { 3, 3 });
assertEquals("Wrong number of foreground elements in object", 7,
countForeground(resultSquare));
assertPositionBackground(result, new long[] { 0, 2 });
assertPositionBackground(result, new long[] { 1, 2 });
}
示例9: testEdgeSquareExcludeEdgesFalse
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Test the op with a 3x3 square starting from (0,1) in a 5x5 img without
* excluding edges
*
* @see Outline#compute(RandomAccessibleInterval, Boolean,
* RandomAccessibleInterval)
* @see #testEdgeSquare()
*/
@Test
public void testEdgeSquareExcludeEdgesFalse() throws Exception {
// SETUP
final Img<BitType> img = ArrayImgs.bits(5, 5);
final IntervalView<BitType> square = Views.offsetInterval(img, new long[] {
0, 1 }, new long[] { 3, 3 });
square.cursor().forEachRemaining(BitType::setOne);
final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
Boolean.FALSE);
assertEquals("Wrong number of foreground elements in interval", 8,
countForeground(result));
final IntervalView<BitType> resultSquare = Views.offsetInterval(result,
new long[] { 0, 1 }, new long[] { 3, 3 });
assertEquals("Wrong number of foreground elements in object", 8,
countForeground(resultSquare));
assertPositionBackground(result, new long[] { 1, 2 });
}
示例10: testHyperCube
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Test the op with a 3x3x3x3 hypercube. The cube is in the middle of a
* 5x5x5x5 img
*/
@Test
public void testHyperCube() throws Exception {
// SETUP
final Img<BitType> img = ArrayImgs.bits(5, 5, 5, 5);
final IntervalView<BitType> hyperCube = Views.offsetInterval(img,
new long[] { 1, 1, 1, 1 }, new long[] { 3, 3, 3, 3 });
hyperCube.cursor().forEachRemaining(BitType::setOne);
// EXECUTE
final Img<BitType> result = (Img<BitType>) ops.morphology().outline(img,
Boolean.TRUE);
// VERIFY
assertEquals("Wrong number of foreground elements in interval", 80,
countForeground(result));
final IntervalView<BitType> resultHyperCube = Views.offsetInterval(result,
new long[] { 1, 1, 1, 1 }, new long[] { 3, 3, 3, 3 });
assertEquals("Wrong number of foreground elements in object", 80,
countForeground(resultHyperCube));
assertPositionBackground(result, new long[] { 2, 2, 2, 2 });
}
示例11: testHyperCube
import net.imglib2.view.Views; //导入方法依赖的package包/类
@Test
public void testHyperCube() {
// SETUP
final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log(
i)).toArray();
final double[] expectedCounts = DoubleStream.of(1, 16, 16).map(Math::log)
.toArray();
final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4);
final IntervalView<BitType> hyperView = Views.offsetInterval(img,
new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 });
hyperView.forEach(BitType::setOne);
// EXECUTE
final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
.boxCount(img, 4L, 1L, 2.0);
// VERIFY
for (int i = 0; i < expectedSizes.length; i++) {
assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12);
assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
}
}
示例12: testHyperCubeTranslations
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Test box counting with a hyper cube and one grid translation (should find a
* better fit than in @see {@link #testHyperCube()})
*/
@Test
public void testHyperCubeTranslations() {
final double[] expectedSizes = DoubleStream.of(4, 2, 1).map(i -> -Math.log(
i)).toArray();
final double[] expectedCounts = DoubleStream.of(1, 1, 16).map(Math::log)
.toArray();
final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 4);
final IntervalView<BitType> hyperView = Views.offsetInterval(img,
new long[] { 1, 1, 1, 1 }, new long[] { 2, 2, 2, 2 });
hyperView.forEach(BitType::setOne);
// EXECUTE
final List<ValuePair<DoubleType, DoubleType>> points = ops.topology()
.boxCount(img, 4L, 1L, 2.0, 1L);
// VERIFY
for (int i = 0; i < expectedSizes.length; i++) {
assertEquals(expectedSizes[i], points.get(i).a.get(), 1e-12);
assertEquals(expectedCounts[i], points.get(i).b.get(), 1e-12);
}
}
示例13: createTestHyperStack
import net.imglib2.view.Views; //导入方法依赖的package包/类
/** Create a hyperstack with a cuboid in two subspaces */
private ImgPlus<BitType> createTestHyperStack(final String imageName) {
final Img<BitType> img = ArrayImgs.bits(4, 4, 4, 2, 2);
IntervalView<BitType> cubeView = Views.offsetInterval(img, new long[] { 1,
1, 1, 1, 0 }, new long[] { 2, 2, 2, 1, 1 });
cubeView.forEach(BitType::setOne);
cubeView = Views.offsetInterval(img, new long[] { 1, 1, 1, 0, 1 },
new long[] { 2, 2, 2, 1, 1 });
cubeView.forEach(BitType::setOne);
final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, imageName,
new DefaultLinearAxis(Axes.X), new DefaultLinearAxis(Axes.Y),
new DefaultLinearAxis(Axes.Z), new DefaultLinearAxis(Axes.CHANNEL),
new DefaultLinearAxis(Axes.TIME));
return imgPlus;
}
示例14: loadFloat
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Load an HDF5 float32 dataset into a {@link CellImg} of {@link FloatType}.
*
* @param reader
* @param dataset
* @param cellDimensions
*/
static public CellImg< FloatType, ? > loadFloat(
final IHDF5Reader reader,
final String dataset,
final int[] cellDimensions )
{
final IHDF5FloatReader float32Reader = reader.float32();
final long[] dimensions = reorder( reader.object().getDimensions( dataset ) );
final int n = dimensions.length;
final CellImg< FloatType, ? > target = new CellImgFactory< FloatType >( cellDimensions ).create( dimensions, new FloatType() );
final long[] offset = new long[ n ];
final long[] targetCellDimensions = new long[ n ];
for ( int d = 0; d < n; )
{
cropCellDimensions( target, offset, cellDimensions, targetCellDimensions );
final RandomAccessibleInterval< FloatType > targetBlock = Views.offsetInterval( target, offset, targetCellDimensions );
final MDFloatArray targetCell = float32Reader.readMDArrayBlockWithOffset(
dataset,
Util.long2int( reorder( targetCellDimensions ) ),
reorder( offset ) );
int i = 0;
for ( final FloatType t : Views.flatIterable( targetBlock ) )
t.set( targetCell.get( i++ ) );
for ( d = 0; d < n; ++d )
{
offset[ d ] += cellDimensions[ d ];
if ( offset[ d ] < dimensions[ d ] )
break;
else
offset[ d ] = 0;
}
}
return target;
}
示例15: loadDouble
import net.imglib2.view.Views; //导入方法依赖的package包/类
/**
* Load an HDF5 float64 dataset into a {@link CellImg} of {@link DoubleType}.
*
* @param reader
* @param dataset
* @param cellDimensions
*/
static public CellImg< DoubleType, ? > loadDouble(
final IHDF5Reader reader,
final String dataset,
final int[] cellDimensions )
{
final IHDF5DoubleReader float64Reader = reader.float64();
final long[] dimensions = reorder( reader.object().getDimensions( dataset ) );
final int n = dimensions.length;
final CellImg< DoubleType, ? > target = new CellImgFactory< DoubleType >( cellDimensions ).create( dimensions, new DoubleType() );
final long[] offset = new long[ n ];
final long[] targetCellDimensions = new long[ n ];
for ( int d = 0; d < n; )
{
cropCellDimensions( target, offset, cellDimensions, targetCellDimensions );
final RandomAccessibleInterval< DoubleType > targetBlock = Views.offsetInterval( target, offset, targetCellDimensions );
final MDDoubleArray targetCell = float64Reader.readMDArrayBlockWithOffset(
dataset,
Util.long2int( reorder( targetCellDimensions ) ),
reorder( offset ) );
int i = 0;
for ( final DoubleType t : Views.flatIterable( targetBlock ) )
t.set( targetCell.get( i++ ) );
for ( d = 0; d < n; ++d )
{
offset[ d ] += cellDimensions[ d ];
if ( offset[ d ] < dimensions[ d ] )
break;
else
offset[ d ] = 0;
}
}
return target;
}