net.imglib2.view.Views.translate()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(98)

本文整理了Java中net.imglib2.view.Views.translate()方法的一些代码示例,展示了Views.translate()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Views.translate()方法的具体详情如下:
包路径:net.imglib2.view.Views
类名称:Views
方法名:translate

Views.translate介绍

[英]Translate the source view by the given translation vector. Pixel x in the source view has coordinates (x + translation) in the resulting view.
[中]按给定的转换向量转换源代码视图。源视图中的像素x在结果视图中具有坐标*(x+平移)*。

代码示例

代码示例来源:origin: imagej/imagej-ops

@Override
public IntervalView<T> calculate(final RandomAccessibleInterval<T> input) {
  return Views.translate(input, translation);
}

代码示例来源:origin: imagej/imagej-ops

@Override
public MixedTransformView<T> calculate(RandomAccessible<T> input) {
  return Views.translate(input, translation);
}

代码示例来源: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: imglib/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: 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 void compute(final RandomAccessibleInterval<T> in1, final Shape in2,
    final IterableInterval<T> output)
  {
    final RandomAccessibleInterval<T> shifted;
    if (isFull) {
      final long[] offset = MorphologyUtils
        .computeTargetImageDimensionsAndOffset(in1, in2)[1];
      shifted = Views.translate(in1, offset);
    }
    else {
      shifted = in1;
    }
    final ExtendedRandomAccessibleInterval<T, RandomAccessibleInterval<T>> extended =
      Views.extend(shifted, f);
    Dilation.dilate(extended, output, in2, minVal, Runtime.getRuntime()
      .availableProcessors());
  }
}

代码示例来源:origin: imagej/imagej-ops

@Override
  public void compute(final RandomAccessibleInterval<T> in1, final Shape in2,
    final IterableInterval<T> output)
  {
    final RandomAccessibleInterval<T> shifted;
    if (isFull) {
      final long[] offset = MorphologyUtils
        .computeTargetImageDimensionsAndOffset(in1, in2)[1];
      shifted = Views.translate(in1, offset);
    }
    else {
      shifted = in1;
    }
    final ExtendedRandomAccessibleInterval<T, RandomAccessibleInterval<T>> extended =
      Views.extend(shifted, f);
    Erosion.erode(extended, output, in2, maxVal, Runtime.getRuntime()
      .availableProcessors());
  }
}

代码示例来源:origin: imglib/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: net.preibisch/multiview-reconstruction

public static < T > RandomAccessibleInterval< T > translateIfNecessary( final Interval original, final RandomAccessibleInterval< T > copy )
{
  if ( Views.isZeroMin( original ) )
  {
    return copy;
  }
  else
  {
    final long[] min = new long[ original.numDimensions() ];
    original.min( min );
    return Views.translate( copy, min );
  }
}

代码示例来源:origin: net.imglib2/imglib2-algorithm

private static < T extends NativeType< T > > RandomAccessibleInterval< T > createImage( final T targetType, final Interval targetInterval )
{
  final long[] dimensions = Intervals.dimensionsAsLongArray( targetInterval );
  final Img< T > ts = Util.getArrayOrCellImgFactory( targetInterval, targetType ).create( dimensions );
  return Views.translate( ts, Intervals.minAsLongArray( targetInterval ) );
}

代码示例来源:origin: imglib/imglib2

private RandomAccessibleInterval< IntType > randomImage( final int randomSeed )
{
  final Img< IntType > result = ArrayImgs.ints( 3, 2, 5 );
  final Random random = new Random( randomSeed );
  result.forEach( x -> x.set( random.nextInt() ) );
  return Views.translate( result, random.nextInt(), random.nextInt(), random.nextInt() );
}

代码示例来源:origin: imagej/imagej-ops

@Override
  public void compute(final RandomAccessibleInterval<T> in1,
    final List<Shape> in2, final IterableInterval<T> out)
  {
    final long[][] minSize = Morphologies.computeMinSize(in1, in2);
    final Interval interval = new FinalInterval(minSize[1]);
    Img<T> upstream = imgCreator.calculate(interval);
    Img<T> downstream = imgCreator.calculate(interval);
    Img<T> tmp;

    dilateComputer.compute(in1, in2.get(0), Views.translate(downstream,
      minSize[0]));
    for (int i = 1; i < in2.size(); i++) {
      // Ping-ponging intermediate results between upstream and downstream to
      // avoid repetitively creating new Imgs.
      tmp = downstream;
      downstream = upstream;
      upstream = tmp;
      dilateComputer.compute(upstream, in2.get(i), downstream);
    }
    if (isFull) copyImg.compute(downstream, out);
    else copyImg.compute(Views.interval(Views.translate(downstream,
      minSize[0]), out), out);
  }
}

代码示例来源:origin: imagej/imagej-ops

@Override
  public void compute(final RandomAccessibleInterval<T> in1,
    final List<Shape> in2, final IterableInterval<T> out)
  {
    final long[][] minSize = Morphologies.computeMinSize(in1, in2);
    final Interval interval = new FinalInterval(minSize[1]);
    Img<T> upstream = imgCreator.calculate(interval);
    Img<T> downstream = imgCreator.calculate(interval);
    Img<T> tmp;

    erodeComputer.compute(in1, in2.get(0), Views.translate(downstream,
      minSize[0]));
    for (int i = 1; i < in2.size(); i++) {
      // Ping-ponging intermediate results between upstream and downstream to
      // avoid repetitively creating new Imgs.
      tmp = downstream;
      downstream = upstream;
      upstream = tmp;
      erodeComputer.compute(Views.interval(Views.extendValue(upstream, maxVal),
        interval), in2.get(i), downstream);
    }
    if (isFull) copyImg.compute(downstream, out);
    else copyImg.compute(Views.interval(Views.translate(downstream,
      minSize[0]), out), out);
  }
}

代码示例来源:origin: imagej/imagej-ops

/**
 * Adjusts the given {@link Img} to match the bounds of the specified
 * {@link Interval}.
 * 
 * @param img An image whose min/max bounds might need adjustment.
 * @param minMax An {@link Interval} whose min/max bounds to use when
 *          adjusting the image. If the provided {@code minMax} object is not
 *          an {@link Interval}, no adjustment is performed.
 * @return A wrapped version of the input {@link Img} with bounds adjusted to
 *         match the provided {@link Interval}, if any; or the input image
 *         itself if no adjustment was needed/possible.
 */
public static <T extends Type<T>> Img<T> adjustMinMax(final Img<T> img,
  final Object minMax)
{
  if (!(minMax instanceof Interval)) return img;
  final Interval interval = (Interval) minMax;
  final long[] min = new long[interval.numDimensions()];
  interval.min(min);
  for (int d = 0; d < min.length; d++) {
    if (min[d] != 0) {
      return ImgView.wrap(Views.translate(img, min), img.factory());
    }
  }
  return img;
}

代码示例来源:origin: imagej/imagej-ops

@Override
public void compute(final RandomAccessibleInterval<T> input,
  final RandomAccessibleInterval<T> output)
{
  // input may potentially be translated
  final long[] translation = new long[input.numDimensions()];
  input.min(translation);
  final IntervalView<T> tmpInterval = Views.interval(Views.translate(
    (RandomAccessible<T>) tmpCreator.calculate(input), translation), output);
  gauss1.compute(input, tmpInterval);
  gauss2.compute(input, output);
  // TODO: Match the Subtract Op in initialize() once we have BinaryOp
  ops().run(Ops.Math.Subtract.class, output, output, tmpInterval);
}

代码示例来源:origin: net.imagej/imagej-legacy

@Override
public ImageRoi convert(final RealMaskRealInterval mask) {
  // Wrap mask as RRARI
  final RealRandomAccessibleRealInterval<BoolType> rrari = Masks
    .toRealRandomAccessibleRealInterval(mask);
  // Convert the RRARI to a RAI whose min is (0, 0), this will ensure it
  // displays properly
  final RandomAccessible<BoolType> raster = Views.raster(rrari);
  final RandomAccessible<BoolType> translate = Views.translate(raster,
    new long[] { (long) -mask.realMin(0), (long) -mask.realMin(1) });
  final RandomAccessibleInterval<BoolType> rai = Views.interval(translate,
    new long[] { 0, 0 }, new long[] { (long) (mask.realMax(0) - mask.realMin(
      0)), (long) (mask.realMax(1) - mask.realMin(1)) });
  // Convert RAI to ImagePlus
  final Dataset d = datasetService.create(rai);
  final ImagePlus ip = convertService.convert(d, ImagePlus.class);
  return new ImageRoi((int) mask.realMin(0), (int) mask.realMin(1), ip
    .getBufferedImage());
}

代码示例来源:origin: imagej/imagej-ops

@Test
  public void defaultZeroMinTest() {
    Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());

    IntervalView<DoubleType> imgTranslated = Views.interval(
        Views.translate((RandomAccessible<DoubleType>) img, 2, 5), new long[] { 2, 5 }, new long[] { 12, 15 });

    IntervalView<DoubleType> il2 = Views.zeroMin(imgTranslated);
    IntervalView<DoubleType> opr = ops.transform().zeroMinView(imgTranslated);

    assertTrue(Views.isZeroMin(il2) == Views.isZeroMin(opr));
  }
}

代码示例来源:origin: imagej/imagej-ops

@Test
public void defaultTranslateTest() {
  Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
  MixedTransformView<DoubleType> il2 = Views.translate( deinterval(img), 2, 5);
  MixedTransformView<DoubleType> opr = ops.transform().translateView( deinterval(img), 2, 5);
  for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) {
    for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) {
      assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j],
          1e-10);
    }
  }
}

代码示例来源:origin: imagej/imagej-ops

@Test
  public void testIntervalTranslate() {
    Img<DoubleType> img = ArrayImgs.doubles(10,10);

    IntervalView<DoubleType> expected = Views.translate(img, 2, 5);
    IntervalView<DoubleType> actual = ops.transform().translateView(img, 2, 5);

    for (int i = 0; i < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix().length; i++) {
      for (int j = 0; j < ((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i].length; j++) {
        assertEquals(((MixedTransformView<DoubleType>) expected.getSource()).getTransformToSource().getMatrix()[i][j], ((MixedTransformView<DoubleType>) actual.getSource()).getTransformToSource().getMatrix()[i][j],
            1e-10);
      }
    }
    
    assertTrue(Intervals.equals(expected, actual));
  }
}

代码示例来源:origin: imglib/imglib2

protected void testCursorIteration( Cursor< IntType > cursor, Interval i )
{
  long[] position = new long[ cursor.numDimensions() ];
  long[] min = new long[ cursor.numDimensions() ];
  i.min( min );
  cursor.fwd();
  cursor.localize( position );
  cursor.reset();
  int ctr = 0;
  long sum = 0;
  final RandomAccess< BitType > check = Views.translate( new ArrayImgFactory<>( new BitType() ).create( i ), min ).randomAccess();
  while ( cursor.hasNext() )
  {
    cursor.fwd();
    cursor.localize( position );
    check.setPosition( position );
    assertFalse( check.get().get() );
    check.get().set( true );
    sum += cursor.get().get();
    ctr++;
  }
  assertEquals( "wrong number of elements accessed.", getIntervalSize( i ), ctr );
  assertEquals( "sum of elements incorrect.", sum, getSum( i ) );
}

相关文章