net.imglib2.img.Img类的使用及代码示例

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

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

Img介绍

[英]An Img is a RandomAccessibleInterval that has its min at 0n and its max positive. Imgs store pixels and thus are the basis for conventional image processing.
[中]Img是一个可随机访问的区间,其最小值为0n,最大值为正值。IMG存储像素,因此是常规图像处理的基础。

代码示例

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

private void copyDataValues(final Img<? extends RealType<?>> input,
  final Img<? extends RealType<?>> output)
{
  final long[] position = new long[output.numDimensions()];
  final Cursor<? extends RealType<?>> outputCursor =
    output.localizingCursor();
  final RandomAccess<? extends RealType<?>> inputAccessor =
    input.randomAccess();
  while (outputCursor.hasNext()) {
    outputCursor.next();
    outputCursor.localize(position);
    inputAccessor.setPosition(position);
    final double value = inputAccessor.get().getRealDouble();
    outputCursor.get().setReal(value);
  }
}

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

protected double getImageMean(Img<T> img) {
   double sum = 0;
   Cursor<T> cursor = img.cursor();
   while (cursor.hasNext()) {
     cursor.fwd();
     T type = cursor.get();
     sum += type.getRealDouble();
   }
   return sum / ImageStatistics.getNumPixels(img);
 }
}

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

public static FloatProcessor toProcessor( final Img< ? extends RealType< ? > > img )
{
  final FloatProcessor fp = new FloatProcessor( (int)img.dimension( 0 ), (int)img.dimension( 1 ) );
  final float[] array = (float[])fp.getPixels();
  final Cursor< ? extends RealType< ? > > c = img.cursor();
  
  for ( int i = 0; i < array.length; ++ i)
    array[ i ] = c.next().getRealFloat();
  return fp;
}

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

/** The dimensions of the integral image are always +1 from the integrated image. */
protected static final boolean isIntegerDivision(Img<?> integralImg, Img<?> scaled) {
  for ( int d = 0; d < scaled.numDimensions(); ++d )
    if ( 0 != (integralImg.dimension( d ) -1) % scaled.dimension( d ) )
      return false;
  
  return true;
}

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

/**
 * Computes a Gaussian convolution with any precision on an entire {@link Img} using the {@link OutOfBoundsMirrorFactory} with single boundary
 * 
 * @param sigma - the sigma for the convolution
 * @param input - the input {@link Img}
 */
public GaussNativeType( final double[] sigma, final Img<T> input, final OutOfBoundsFactory< T, Img<T> > outOfBounds )
{
  this( sigma, Views.extend( input, outOfBounds ), input, input.factory(), input.firstElement().createVariable() );
}

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

public static final <T extends RealType<T>> void addGaussianNoiseToImage(Img<T> img, double sigma_noise) {
  Cursor<T> lc = img.localizingCursor();
  double val;
  T var = img.firstElement().createVariable();
  while (lc.hasNext()) {
    lc.fwd();
    val = Math.max(0, sigma_noise * ran.nextGaussian());
    var.setReal(val);
    lc.get().add(var);
  }
}

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

void copyWithDestIteration( final Img< IntType > srcImg, final Img< IntType > dstImg )
{
  final long[] pos = new long[ dstImg.numDimensions() ];
  final Cursor< IntType > dst = dstImg.localizingCursor();
  final RandomAccess< IntType > src = srcImg.randomAccess();
  while ( dst.hasNext() )
  {
    dst.fwd();
    dst.localize( pos );
    src.setPosition( pos );
    dst.get().set( src.get() );
  }
}

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

min = Math.min( min, f.getRealDouble() );
final Img< T > square = img.factory().create( size, img.firstElement() );
final Cursor< T > squareCursor = square.localizingCursor();
final T minT = img.firstElement().createVariable();
minT.setReal( min );
final RandomAccess< T > inputCursor = Views.extendValue( img, minT ).randomAccess();
while ( squareCursor.hasNext() )
  squareCursor.fwd();
  squareCursor.localize( size );
  for ( int d = 0; d < img.numDimensions(); ++d )
    size[ d ] =  size[ d ] - square.dimension( d )/2 + img.dimension( d )/2;
  inputCursor.setPosition( size );
  squareCursor.get().set( inputCursor.get() );

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

final long[] tmp = new long[ img.numDimensions() ];
long maxSize = 0;
for ( int d = 0; d < img.numDimensions(); ++d )
  maxSize = Math.max( maxSize, img.dimension( d ) );
for ( int d = 0; d < img.numDimensions(); ++d )
  tmp[ d ] = maxSize;
  min = Math.min( min, f.get() );
final Img< FloatType > square = img.factory().create( tmp, img.firstElement() );
final Cursor< FloatType > squareCursor = square.localizingCursor();
final RandomAccess< FloatType > inputCursor = Views.extendValue( img, new FloatType( min ) ).randomAccess(); 
while ( squareCursor.hasNext() )
  squareCursor.fwd();
  squareCursor.localize( tmp );
  for ( int d = 0; d < img.numDimensions(); ++d )
    tmp[ d ] =  tmp[ d ] - square.dimension( d )/2 + img.dimension( d )/2;
  inputCursor.setPosition( tmp );
  squareCursor.get().set( inputCursor.get().get() );

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

final Img< FloatType > img = factory.create( input, new FloatType() );
final IterableInterval< T > iterableInput = Views.iterable( input );
if ( img.iterationOrder().equals( iterableInput.iterationOrder() ) )
  final Cursor< FloatType > out = img.cursor();
  final Cursor< T > in = iterableInput.cursor();
  while ( out.hasNext() )
    out.fwd();
    in.fwd();
    out.get().set( in.get().getRealFloat() );
  final Cursor< FloatType > out = img.localizingCursor();
  final RandomAccess< T > in = input.randomAccess();
    out.fwd();
    in.setPosition( out );
    out.get().set( in.get().getRealFloat() );

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

@Test
public void testNormalizeScale() {
  ops.run(ConvertIIs.class, out, in,
    ops.op(NormalizeScaleRealTypes.class, out.firstElement(), in.firstElement()));
  final Cursor<ShortType> c = in.localizingCursor();
  final RandomAccess<ByteType> ra = out.randomAccess();
  while (c.hasNext()) {
    final short value = c.next().get();
    ra.setPosition(c);
    assertEquals(normalizeScale(value), ra.get().get());
  }
}

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

final int numDimensions = input.numDimensions();
final double[] sigma = new double[ numDimensions ];
downSampled = input.factory().create( newSize, input.firstElement() );
final RealRandomAccessible< T > interpolated = Views.interpolate( Views.extendMirrorSingle( gaussConvolved ), new NearestNeighborInterpolatorFactory<T>() );
final RealRandomAccess< T > interpolator = interpolated.realRandomAccess();
final Cursor<T> cursor = downSampled.localizingCursor();
final float[] scalingDim = scaling.clone();
while ( cursor.hasNext() )
  cursor.fwd();
  cursor.localize( pos );
  cursor.get().set( interpolator.get() );

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

static private final <T extends RealType<T>> Img<T> processReal(final Img<T> img, final long[] dim, final Mode mode) throws Exception {
  final Img< T > res = img.factory().create( dim );
  final RealRandomAccess<T> inter = ifac.create(Views.extend(img, new OutOfBoundsMirrorFactory<T,Img<T>>(OutOfBoundsMirrorFactory.Boundary.SINGLE)));
  final Cursor<T> c2 = res.localizingCursor();
  final float[] s = new float[dim.length];
  for (int i=0; i<s.length; i++) s[i] = (float)img.dimension(i) / dim[i];
  final long[] d = new long[dim.length];
  final float[] p = new float[dim.length];
  while (c2.hasNext()) {
    c2.fwd();
    c2.localize(d); // TODO "localize" seems to indicate the opposite of what it does
    for (int i=0; i<d.length; i++) p[i] = d[i] * s[i];
    inter.move(p);
    c2.get().set(inter.get());

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

int[] getImgAsInts( final Img< IntType > img )
{
  final RandomAccess< IntType > a = img.randomAccess();
  final int N = ( int ) img.size();
  final int[] data = new int[ N ];
  final long[] dim = new long[ img.numDimensions() ];
  final long[] pos = new long[ img.numDimensions() ];
  img.dimensions( dim );
  for ( int i = 0; i < N; ++i )
  {
    IntervalIndexer.indexToPosition( i, dim, pos );
    a.setPosition( pos );
    data[ i ] = a.get().get();
  }
  return data;
}

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

/**
 * Copy an interval of the specified source image on a float image.
 *
 * @param img
 *            the source image.
 * @param interval
 *            the interval in the source image to copy.
 * @param factory
 *            a factory used to build the float image.
 * @return a new float Img. Careful: even if the specified interval does not
 *         start at (0, 0), the new image will have its first pixel at
 *         coordinates (0, 0).
 */
public static final < T extends RealType< T >> Img< FloatType > copyToFloatImg( final RandomAccessible< T > img, final Interval interval, final ImgFactory< FloatType > factory )
{
  final Img< FloatType > output = factory.create( interval, new FloatType() );
  final long[] min = new long[ interval.numDimensions() ];
  interval.min( min );
  final RandomAccess< T > in = Views.offset( img, min ).randomAccess();
  final Cursor< FloatType > out = output.cursor();
  final RealFloatConverter< T > c = new RealFloatConverter< >();
  while ( out.hasNext() )
  {
    out.fwd();
    in.setPosition( out );
    c.convert( in.get(), out.get() );
  }
  return output;
}

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

private void copy(ShuffledView<T> shuffled, Img<T> buffer) {
  Cursor<T> cursor = buffer.localizingCursor();
  RandomAccess<T> ra = shuffled.randomAccess();
  while (cursor.hasNext()) {
    T v = cursor.next();
    ra.setPosition(cursor);
    v.set(ra.get());
  }
}

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

@Test
  public void copyArrayImgWithOutputTest() {
    final Img<UnsignedByteType> output = input.factory().create(input,
        input.firstElement());

    ops.run(CopyArrayImg.class, output, input);

    final Cursor<UnsignedByteType> inc = input.cursor();
    final Cursor<UnsignedByteType> outc = output.cursor();

    while (inc.hasNext()) {
      assertTrue(outc.next().equals(inc.next()));
    }
  }
}

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

public double DotProduct(final Img<T> image1, final Img<T> image2) {
  final Cursor<T> cursorImage1 = image1.cursor();
  final Cursor<T> cursorImage2 = image2.cursor();
  double dotProduct = 0.0d;
  while (cursorImage1.hasNext()) {
    cursorImage1.fwd();
    cursorImage2.fwd();
    float val1 = cursorImage1.get().getRealFloat();
    float val2 = cursorImage2.get().getRealFloat();
    dotProduct += val1 * val2;
  }
  return dotProduct;
}

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

@Override
public RandomAccessibleInterval< UnsignedShortType > getImage( final ViewId view )
{
  final long[] dim = new long[ sb.getImgs().get( view.getViewSetupId() ).numDimensions() ];
  for ( int d = 0; d < dim.length; ++d )
    dim[ d ] = sb.getImgs().get( view.getViewSetupId() ).dimension( d );
  final Img< UnsignedShortType > img = ArrayImgs.unsignedShorts( dim );
  final Cursor< FloatType > in = sb.getImgs().get( view.getViewSetupId() ).cursor();
  final Cursor< UnsignedShortType > out = img.cursor();
  while ( in.hasNext() )
    out.next().set( Math.round( in.next().get() ) );
  return img;
}

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

private static < O extends RealType< O >> void fillImage( Img< O > img )
  {
    Random rng = new Random();
    Cursor< O > cursor = img.cursor();
    while ( cursor.hasNext() )
    {
      double value = 256 * rng.nextDouble();
      cursor.next().setReal( value );
    }
  }
}

相关文章