net.imglib2.util.Util类的使用及代码示例

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

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

Util介绍

[英]A collection of general-purpose utility methods for working with ImgLib2 data structures.
[中]用于处理ImgLib2数据结构的通用实用方法集合。

代码示例

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

public void setKernel( final RandomAccessibleInterval< R > kernel )
{
  this.kernel = Views.extendValue( kernel, Util.getTypeFromInterval( kernel ).createVariable() );
  this.kernelInterval = kernel;
  this.fftKernel = null;
}

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

@Override
  public String toString()
  {
    if ( originalInvPCMPosition == null)
      return Util.printCoordinates( position ) + ", phaseCorrelationPeak = " + phaseCorrelationPeak + ", crossCorrelationPeak = " + crossCorrelationPeak;
    return Util.printCoordinates( position ) + " [" + Util.printCoordinates( originalInvPCMPosition ) + "], phaseCorrelationPeak = " + phaseCorrelationPeak + ", crossCorrelationPeak = " + crossCorrelationPeak; 
  }
}

代码示例来源:origin: net.preibisch/multiview-reconstruction

public void fuseGroups()
{
  this.downsampledBB = fuseGroups(
      spimData,
      images,
      unnormalizedWeights,
      models,
      groups,
      bb,
      downsampling,
      useWeightsFusion ? Util.getArrayFromValue( blendingRangeFusion, 3 ) : null,
      useWeightsFusion ? Util.getArrayFromValue( blendingBorderFusion, 3 ) : null,
      useWeightsDecon ? Util.getArrayFromValue( blendingRangeDeconvolution, 3 ) : null,
      useWeightsDecon ? Util.getArrayFromValue( blendingBorderDeconvolution, 3 ) : null,
      intensityAdjustments );
}

代码示例来源:origin: sc.fiji/TrackMate_

protected double computeAlternativeCosts()
{
  if ( percentile == 1 ) { return alternativeCostFactor * Util.max( costs ); }
  return alternativeCostFactor * Util.percentile( costs, percentile );
}

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

private <T> ImgFactory<T> imgFactory(
    final RandomAccessibleInterval<T> rai)
  {
    final T type = Util.getTypeFromInterval(rai);
    return Util.getSuitableImgFactory(rai, type);
  }
}

代码示例来源:origin: net.preibisch/multiview-reconstruction

final private static Img< FloatType > createGaussianKernel( final double[] sigmas )
{
  final int numDimensions = sigmas.length;
  final long[] imageSize = new long[ numDimensions ];
  final double[][] kernel = new double[ numDimensions ][];
  for ( int d = 0; d < numDimensions; ++d )
  {
    kernel[ d ] = Util.createGaussianKernel1DDouble( sigmas[ d ], true );
    imageSize[ d ] = kernel[ d ].length;
  }
  final Img< FloatType > kernelImg = ArrayImgs.floats( imageSize );
  final Cursor< FloatType > cursor = kernelImg.localizingCursor();
  final int[] position = new int[ numDimensions ];
  while ( cursor.hasNext() )
  {
    cursor.fwd();
    cursor.localize( position );
    double value = 1;
    for ( int d = 0; d < numDimensions; ++d )
      value *= kernel[ d ][ position[ d ] ];
    cursor.get().set( ( float ) value );
  }
  return kernelImg;
}

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

protected void compute( final long startPos, final long loopSize, final T min, final T max )
{
  final Cursor< T > cursor = image.cursor();
  // init min and max
  cursor.fwd();
  min.set( cursor.get() );
  max.set( cursor.get() );
  cursor.reset();
  // move to the starting position of the current thread
  cursor.jumpFwd( startPos );
  // do as many pixels as wanted by this thread
  for ( long j = 0; j < loopSize; ++j )
  {
    cursor.fwd();
    final T value = cursor.get();
    if ( Util.min( min, value ) == value )
      min.set( value );
    if ( Util.max( max, value ) == value )
      max.set( value );
  }
}

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

/**
 * performs update step of the Richardson Lucy with Total Variation Algorithm
 */
@Override
public void compute(I correction, I estimate) {
  if (variation == null) {
    Type<T> type = Util.getTypeFromInterval(correction);
    variation = ops().create().img(correction, type.createVariable());
  }
  divUnitGradFastThread(estimate);
  final Cursor<T> cursorCorrection = Views.iterable(correction).cursor();
  final Cursor<T> cursorVariation = Views.iterable(variation).cursor();
  final Cursor<T> cursorEstimate = Views.iterable(estimate).cursor();
  while (cursorEstimate.hasNext()) {
    cursorCorrection.fwd();
    cursorVariation.fwd();
    cursorEstimate.fwd();
    cursorEstimate.get().mul(cursorCorrection.get());
    cursorEstimate.get().mul(1f / (1f - regularizationFactor * cursorVariation
      .get().getRealFloat()));
  }
}

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

@Override
public RandomAccessibleInterval<T> calculate(double[] input) {
  final double[] sigmaPixels = new double[input.length];
  final long[] dims = new long[input.length];
  final double[][] kernelArrays = new double[input.length][];
  for (int d = 0; d < input.length; d++) {
    sigmaPixels[d] = input[d];
    dims[d] = Math.max(3, (2 * (int) (3 * sigmaPixels[d] + 0.5) + 1));
    kernelArrays[d] = Util.createGaussianKernel1DDouble(sigmaPixels[d], true);
  }
  final RandomAccessibleInterval<T> out = createOp.calculate(new FinalInterval(
    dims));
  final Cursor<T> cursor = Views.iterable(out).cursor();
  while (cursor.hasNext()) {
    cursor.fwd();
    double result = 1.0f;
    for (int d = 0; d < input.length; d++) {
      result *= kernelArrays[d][cursor.getIntPosition(d)];
    }
    cursor.get().setReal(result);
  }
  return out;
}

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

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize() {
  maxVal = Util.getTypeFromInterval(in()).createVariable();
  maxVal.setReal(maxVal.getMaxValue());
  if (f == null) {
    f = new OutOfBoundsConstantValueFactory<>(maxVal);
  }
  imgCreator = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class,
    Img.class, in(), maxVal.createVariable());
  if (out() == null) setOutput(createOutput(in()));
}

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

IntervalView<FloatType> incropped = Views.interval(in, new long[] {
  size[0] / 2, size[1] / 2 }, new long[] { size[0] - 1, size[1] - 1 });
incropped = Views.zeroMin(incropped);
  (RandomAccessibleInterval<FloatType>) ops.run(RichardsonLucyF.class,
    convolved, kernel, null, new OutOfBoundsConstantValueFactory<>(Util
      .getTypeFromInterval(in).createVariable()), 10);
  (RandomAccessibleInterval<FloatType>) ops.run(RichardsonLucyF.class,
    convolved, kernel, null, new OutOfBoundsConstantValueFactory<>(Util
      .getTypeFromInterval(in).createVariable()), null, null, null, 10,
    true, true);
assertEquals(incropped.dimension(1), deconvolved2.dimension(1));
final Cursor<FloatType> deconvolvedCursor = Views.iterable(deconvolved)
  .cursor();
  assertEquals(deconvolvedValues[i], deconvolvedCursor.next().get(), 0.0f);
  assertEquals(deconvolvedValues2[i], deconvolvedCursor2.next().get(), 0.0f);

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

/** Tests the Gaussian. */
@Test
public void gaussRegressionTest() {
  final Img<ByteType> in = generateByteArrayTestImg(true, new long[] { 10, 10 });
  final Img<ByteType> out1 =
    ops.create().img(in, Util.getTypeFromInterval(in));
  final double sigma = 5;
  final Img<ByteType> out2 =
    ops.create().img(in, Util.getTypeFromInterval(in));
  ops.run(GaussRAISingleSigma.class, out1, in, sigma);
  try {
    Gauss3.gauss(sigma, Views.extendMirrorSingle(in), out2);
  }
  catch (IncompatibleTypeException e) {
    throw new RuntimeException(e);
  }
  // compare outputs
  final Cursor<ByteType> c1 = out1.cursor();
  final Cursor<ByteType> c2 = out2.cursor();
  while (c1.hasNext()) {
    org.junit.Assert.assertEquals(c1.next().getRealDouble(), c2.next()
      .getRealDouble(), 0);
  }
}

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

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void initialize() {
  minVal = Util.getTypeFromInterval(in()).createVariable();
  minVal.setReal(minVal.getMinValue());
  imgCreator = (UnaryFunctionOp) Functions.unary(ops(), Ops.Create.Img.class,
    Img.class, in(), minVal.createVariable());
  erodeComputer = Hybrids.binaryCF(ops(), Ops.Morphology.Erode.class, out(),
    in1(), in2(), false);
  dilateComputer = Hybrids.binaryCF(ops(), Ops.Morphology.Dilate.class, out(),
    in1(), in2(), false);
}

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

minVal.setReal( minVal.getMinValue() );
final ExtendedRandomAccessibleInterval< T, RandomAccessibleInterval< T >> extended = Views.extendValue( source, minVal );
final ImgFactory< T > factory = Util.getSuitableImgFactory( interval, minVal );
final Img< T > img = factory.create( interval );
final long[] min = new long[ interval.numDimensions() ];
interval.min( min );
final IntervalView< T > translated = Views.translate( img, min );

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

int counterX = 0;
int counterY = 0;
while (cursorImg.hasNext()) {
  if (counterX > 8 && counterX < 12 || counterY > 8 && counterY < 12) {
    cursorImg.next().setOne();
  } else {
    cursorImg.next().setZero();
FloatType type = Util.getTypeFromInterval(out).createVariable();
type.set(4.0f);
assertEquals(type, outRA.get());

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

@Override
  @SuppressWarnings("unchecked")
  public O calculate(final I input) {

    if (obf == null) {
      obf = new OutOfBoundsConstantValueFactory<>(
        Util.getTypeFromInterval(input).createVariable());
    }

    Interval inputInterval = paddingIntervalCentered.calculate(input,
      paddedDimensions);

    return (O) Views.interval(Views.extend(input, obf), inputInterval);
  }
}

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

/**
 * Randomizes the content of the given image.
 * @return Reference to the given image
 */
public < I extends RandomAccessibleInterval< T >, T >
I randomize( final I image )
{
  final T type = Util.getTypeFromInterval( image );
  Views.iterable( image ).forEach( randomSetter( type ) );
  return image;
}

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

/**
 * 
 * @param nBins The desired number of bins.
 * @param numDimensions The dimensions of the image region from which the histogram is computed.
 * @param min The minimum value, from which the first bin starts; all values under min will be added to the first bin.
 * @param max The maximum value, at which the last bin ends; all values over max will be added to the last bin.
 * @param op The type in which operations will be computed.
 */
public Histogram(
    final int nBins,
    final int numDimensions,
    final T min,
    final T max)
{
  this.bins = new long[nBins];
  this.maxPositions = new long[numDimensions];
  this.minPositions = new long[numDimensions];
  this.min = min;
  this.max = max;
  //
  this.range = min.createVariable();
  this.range.set(max);
  this.range.sub(min);
  //
  final Dimensions dims = new FinalDimensions( nBins );
  this.binValues = Util.getSuitableImgFactory( dims, min ).create( dims );
  this.accessBinValues = this.binValues.randomAccess();
}

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

@SuppressWarnings( "unchecked" )
public DogComputationType(
    final RandomAccessible< ? > input,
    final Interval interval )
{
  final Object t = Util.getTypeFromInterval( Views.interval( input, interval ) );
  if ( t instanceof DoubleType )
    type = ( F ) new DoubleType();
  else
    type = ( F ) new FloatType();
}

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

@Override
public void initialize() {
  // if no OBF was passed in set default OBF for convolve to be constant value
  // of zero (zero-pad)
  if (this.getOBFInput() == null) {
    setOBFInput(new OutOfBoundsConstantValueFactory<>(Util
      .getTypeFromInterval(in()).createVariable()));
  }
  super.initialize();
}

相关文章