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

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

本文整理了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

  1. private void copyDataValues(final Img<? extends RealType<?>> input,
  2. final Img<? extends RealType<?>> output)
  3. {
  4. final long[] position = new long[output.numDimensions()];
  5. final Cursor<? extends RealType<?>> outputCursor =
  6. output.localizingCursor();
  7. final RandomAccess<? extends RealType<?>> inputAccessor =
  8. input.randomAccess();
  9. while (outputCursor.hasNext()) {
  10. outputCursor.next();
  11. outputCursor.localize(position);
  12. inputAccessor.setPosition(position);
  13. final double value = inputAccessor.get().getRealDouble();
  14. outputCursor.get().setReal(value);
  15. }
  16. }

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

  1. protected double getImageMean(Img<T> img) {
  2. double sum = 0;
  3. Cursor<T> cursor = img.cursor();
  4. while (cursor.hasNext()) {
  5. cursor.fwd();
  6. T type = cursor.get();
  7. sum += type.getRealDouble();
  8. }
  9. return sum / ImageStatistics.getNumPixels(img);
  10. }
  11. }

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

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

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

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

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

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

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

  1. public static final <T extends RealType<T>> void addGaussianNoiseToImage(Img<T> img, double sigma_noise) {
  2. Cursor<T> lc = img.localizingCursor();
  3. double val;
  4. T var = img.firstElement().createVariable();
  5. while (lc.hasNext()) {
  6. lc.fwd();
  7. val = Math.max(0, sigma_noise * ran.nextGaussian());
  8. var.setReal(val);
  9. lc.get().add(var);
  10. }
  11. }

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

  1. void copyWithDestIteration( final Img< IntType > srcImg, final Img< IntType > dstImg )
  2. {
  3. final long[] pos = new long[ dstImg.numDimensions() ];
  4. final Cursor< IntType > dst = dstImg.localizingCursor();
  5. final RandomAccess< IntType > src = srcImg.randomAccess();
  6. while ( dst.hasNext() )
  7. {
  8. dst.fwd();
  9. dst.localize( pos );
  10. src.setPosition( pos );
  11. dst.get().set( src.get() );
  12. }
  13. }

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

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

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

  1. final long[] tmp = new long[ img.numDimensions() ];
  2. long maxSize = 0;
  3. for ( int d = 0; d < img.numDimensions(); ++d )
  4. maxSize = Math.max( maxSize, img.dimension( d ) );
  5. for ( int d = 0; d < img.numDimensions(); ++d )
  6. tmp[ d ] = maxSize;
  7. min = Math.min( min, f.get() );
  8. final Img< FloatType > square = img.factory().create( tmp, img.firstElement() );
  9. final Cursor< FloatType > squareCursor = square.localizingCursor();
  10. final RandomAccess< FloatType > inputCursor = Views.extendValue( img, new FloatType( min ) ).randomAccess();
  11. while ( squareCursor.hasNext() )
  12. squareCursor.fwd();
  13. squareCursor.localize( tmp );
  14. for ( int d = 0; d < img.numDimensions(); ++d )
  15. tmp[ d ] = tmp[ d ] - square.dimension( d )/2 + img.dimension( d )/2;
  16. inputCursor.setPosition( tmp );
  17. squareCursor.get().set( inputCursor.get().get() );

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

  1. final Img< FloatType > img = factory.create( input, new FloatType() );
  2. final IterableInterval< T > iterableInput = Views.iterable( input );
  3. if ( img.iterationOrder().equals( iterableInput.iterationOrder() ) )
  4. final Cursor< FloatType > out = img.cursor();
  5. final Cursor< T > in = iterableInput.cursor();
  6. while ( out.hasNext() )
  7. out.fwd();
  8. in.fwd();
  9. out.get().set( in.get().getRealFloat() );
  10. final Cursor< FloatType > out = img.localizingCursor();
  11. final RandomAccess< T > in = input.randomAccess();
  12. out.fwd();
  13. in.setPosition( out );
  14. out.get().set( in.get().getRealFloat() );

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

  1. @Test
  2. public void testNormalizeScale() {
  3. ops.run(ConvertIIs.class, out, in,
  4. ops.op(NormalizeScaleRealTypes.class, out.firstElement(), in.firstElement()));
  5. final Cursor<ShortType> c = in.localizingCursor();
  6. final RandomAccess<ByteType> ra = out.randomAccess();
  7. while (c.hasNext()) {
  8. final short value = c.next().get();
  9. ra.setPosition(c);
  10. assertEquals(normalizeScale(value), ra.get().get());
  11. }
  12. }

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

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

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

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

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

  1. int[] getImgAsInts( final Img< IntType > img )
  2. {
  3. final RandomAccess< IntType > a = img.randomAccess();
  4. final int N = ( int ) img.size();
  5. final int[] data = new int[ N ];
  6. final long[] dim = new long[ img.numDimensions() ];
  7. final long[] pos = new long[ img.numDimensions() ];
  8. img.dimensions( dim );
  9. for ( int i = 0; i < N; ++i )
  10. {
  11. IntervalIndexer.indexToPosition( i, dim, pos );
  12. a.setPosition( pos );
  13. data[ i ] = a.get().get();
  14. }
  15. return data;
  16. }

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

  1. /**
  2. * Copy an interval of the specified source image on a float image.
  3. *
  4. * @param img
  5. * the source image.
  6. * @param interval
  7. * the interval in the source image to copy.
  8. * @param factory
  9. * a factory used to build the float image.
  10. * @return a new float Img. Careful: even if the specified interval does not
  11. * start at (0, 0), the new image will have its first pixel at
  12. * coordinates (0, 0).
  13. */
  14. public static final < T extends RealType< T >> Img< FloatType > copyToFloatImg( final RandomAccessible< T > img, final Interval interval, final ImgFactory< FloatType > factory )
  15. {
  16. final Img< FloatType > output = factory.create( interval, new FloatType() );
  17. final long[] min = new long[ interval.numDimensions() ];
  18. interval.min( min );
  19. final RandomAccess< T > in = Views.offset( img, min ).randomAccess();
  20. final Cursor< FloatType > out = output.cursor();
  21. final RealFloatConverter< T > c = new RealFloatConverter< >();
  22. while ( out.hasNext() )
  23. {
  24. out.fwd();
  25. in.setPosition( out );
  26. c.convert( in.get(), out.get() );
  27. }
  28. return output;
  29. }

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

  1. private void copy(ShuffledView<T> shuffled, Img<T> buffer) {
  2. Cursor<T> cursor = buffer.localizingCursor();
  3. RandomAccess<T> ra = shuffled.randomAccess();
  4. while (cursor.hasNext()) {
  5. T v = cursor.next();
  6. ra.setPosition(cursor);
  7. v.set(ra.get());
  8. }
  9. }

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

  1. @Test
  2. public void copyArrayImgWithOutputTest() {
  3. final Img<UnsignedByteType> output = input.factory().create(input,
  4. input.firstElement());
  5. ops.run(CopyArrayImg.class, output, input);
  6. final Cursor<UnsignedByteType> inc = input.cursor();
  7. final Cursor<UnsignedByteType> outc = output.cursor();
  8. while (inc.hasNext()) {
  9. assertTrue(outc.next().equals(inc.next()));
  10. }
  11. }
  12. }

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

  1. public double DotProduct(final Img<T> image1, final Img<T> image2) {
  2. final Cursor<T> cursorImage1 = image1.cursor();
  3. final Cursor<T> cursorImage2 = image2.cursor();
  4. double dotProduct = 0.0d;
  5. while (cursorImage1.hasNext()) {
  6. cursorImage1.fwd();
  7. cursorImage2.fwd();
  8. float val1 = cursorImage1.get().getRealFloat();
  9. float val2 = cursorImage2.get().getRealFloat();
  10. dotProduct += val1 * val2;
  11. }
  12. return dotProduct;
  13. }

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

  1. @Override
  2. public RandomAccessibleInterval< UnsignedShortType > getImage( final ViewId view )
  3. {
  4. final long[] dim = new long[ sb.getImgs().get( view.getViewSetupId() ).numDimensions() ];
  5. for ( int d = 0; d < dim.length; ++d )
  6. dim[ d ] = sb.getImgs().get( view.getViewSetupId() ).dimension( d );
  7. final Img< UnsignedShortType > img = ArrayImgs.unsignedShorts( dim );
  8. final Cursor< FloatType > in = sb.getImgs().get( view.getViewSetupId() ).cursor();
  9. final Cursor< UnsignedShortType > out = img.cursor();
  10. while ( in.hasNext() )
  11. out.next().set( Math.round( in.next().get() ) );
  12. return img;
  13. }

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

  1. private static < O extends RealType< O >> void fillImage( Img< O > img )
  2. {
  3. Random rng = new Random();
  4. Cursor< O > cursor = img.cursor();
  5. while ( cursor.hasNext() )
  6. {
  7. double value = 256 * rng.nextDouble();
  8. cursor.next().setReal( value );
  9. }
  10. }
  11. }

相关文章