当前位置: 首页>>代码示例>>Java>>正文


Java Img.randomAccess方法代码示例

本文整理汇总了Java中net.imglib2.img.Img.randomAccess方法的典型用法代码示例。如果您正苦于以下问题:Java Img.randomAccess方法的具体用法?Java Img.randomAccess怎么用?Java Img.randomAccess使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.imglib2.img.Img的用法示例。


在下文中一共展示了Img.randomAccess方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sample

import net.imglib2.img.Img; //导入方法依赖的package包/类
private static void sample(final Img<FloatType> img, final Section section,
	final double increment, final Random random)
{
	final Vector3d startOffset = new Vector3d(section.direction);
	// Add a random offset so that sampling doesn't always start from the same
	// plane
	final double offsetScale = random.nextDouble() * increment;
	startOffset.scale(offsetScale);
	final Vector3d samplePoint = new Vector3d(section.direction);
	samplePoint.scale(section.tMin);
	samplePoint.add(section.origin);
	samplePoint.add(startOffset);
	final Vector3d sampleGap = new Vector3d(section.direction);
	sampleGap.scale(increment);
	final double[] coordinates = new double[4];
	final RandomAccess<FloatType> access = img.randomAccess();
	for (double t = section.tMin + offsetScale; t <= section.tMax; t +=
		increment)
	{
		samplePoint.get(coordinates);
		addOrientation(access, samplePoint, section.direction);
		samplePoint.add(sampleGap);
	}
}
 
开发者ID:bonej-org,项目名称:BoneJ2,代码行数:25,代码来源:MILPOCDirectionComponents.java

示例2: integrateN

import net.imglib2.img.Img; //导入方法依赖的package包/类
/** In place; assumes iimg already contains the information of the image to integrate. */
static private final <T extends NumericType<T>> void integrateN(
		final Img<T> iimg,
		final T sum)
{
	final RandomAccess<T> r2 = iimg.randomAccess();
	final int numDimensions = iimg.numDimensions();
	// Integrate iimg by summing over all possible kinds of rows
	final int[] rowDims = new int[numDimensions -1];
	for (int rowDimension = 0; rowDimension < numDimensions; ++rowDimension) {
		// Reset position
		for (int i=0; i<numDimensions; ++i) {
			r2.setPosition(1L, i);
		}
		
		// Prepare the set of dimensions to iterate over
		for (int i=0, k=0; i<rowDims.length; ++i, ++k) {
			if (i == rowDimension) ++k;
			rowDims[i] = k;
		}

		// Iterate over all dimensions other than rowDimension
		integrateRows(rowDimension, iimg, r2, sum, rowDims);
	}
}
 
开发者ID:imglib,项目名称:imglib2-script,代码行数:26,代码来源:FastIntegralImg.java

示例3: sum

import net.imglib2.img.Img; //导入方法依赖的package包/类
static public Img<FloatType> sum(
		final Img<? extends RealType<?>> img) throws Exception {
	RandomAccess<? extends RealType<?>> c = img.randomAccess();
	int[] pos = new int[img.numDimensions()];
	pos[0] = 348;
	pos[1] = 95;
	c.setPosition(pos);
	System.out.println("Original pixel at 348,95: " + c.get().getRealDouble());

	Img<FloatType> result = Compute.inFloats(new Add(img, img, img, img));

	RandomAccess<? extends RealType<?>> r = result.randomAccess();
	r.setPosition(pos);
	System.out.println("After varargs addition, pixel at 348,95: " + r.get().getRealDouble()
			+ " which is 4 * val: " + (c.get().getRealDouble() * 4 == r.get().getRealDouble()));
	
	return result;
}
 
开发者ID:imglib,项目名称:imglib2-script,代码行数:19,代码来源:Benchmark.java

示例4: makeEdgelClusterImg

import net.imglib2.img.Img; //导入方法依赖的package包/类
public void makeEdgelClusterImg( Img<T> clusterImg ){
	
	RandomAccess<T> ra = clusterImg.randomAccess();
	
	int N = edgels.size();
	for ( int i = 0; i < N; i++ )
	{
		Edgel e = edgels.get(i);
		for( int d=0; d<clusterImg.numDimensions(); d++){
			ra.setPosition( (int)(Math.round( e.getDoublePosition(d) )), d);
		}
		if( labels[i] == CLASSA ){
			ra.get().setReal( 1 );
		}else if( labels[i] == CLASSB ){
			ra.get().setReal( 2 );
		}else if( labels[i] == CONFLICT ){
			ra.get().setReal( 3 );
		}
		
	}
}
 
开发者ID:bogovicj,项目名称:hhmi-exp,代码行数:22,代码来源:EdgelClustering.java

示例5: genGradient

import net.imglib2.img.Img; //导入方法依赖的package包/类
public static Img<FloatType> genGradient( ArrayImgFactory<FloatType> factory, FloatType val,  long nx, long ny, double stdDev){
	
	Img<FloatType> img = factory.create(new long[]{nx, ny}, val);
	
	boolean a = true;
	RandomAccess<FloatType> ra = img.randomAccess();
	for(long x=0; x<nx; x++){
		for(long y=0; y<ny; y++){
	
		ra.setPosition(new long[]{x, y});
		if(a){
			ra.get().set((float)x + 1.2f + (float)(stdDev*Math.random()));
		}else{
			ra.get().set((float)x + 0.8f + (float)(stdDev*Math.random()));	
		}
		
		}
		a = !a;
	}
	
	return img;
}
 
开发者ID:bogovicj,项目名称:hhmi-exp,代码行数:23,代码来源:PartialDerivativeDirectional.java

示例6: thresholdMap

import net.imglib2.img.Img; //导入方法依赖的package包/类
public static < T extends RealType< T >> Img<T> thresholdMap(Img<T> img, double thresh, boolean greaterThan){
   
   Img<T> out = img.factory().create(img, img.firstElement());
   RandomAccess<T> ra = out.randomAccess();
   Cursor<T> c = img.cursor();
   
   while(c.hasNext()){
      T t = c.next();
      ra.setPosition(c);
      
      if( greaterThan && t.getRealDouble() > thresh)
      {
         ra.get().setOne();
      }
      else if( !greaterThan && t.getRealDouble() < thresh )
      {
         ra.get().setOne();
      }
   }
   return out;
}
 
开发者ID:bogovicj,项目名称:hhmi-exp,代码行数:22,代码来源:ImgOps.java

示例7: markPoints

import net.imglib2.img.Img; //导入方法依赖的package包/类
/** Marks a list of points in an image */
private <T extends RealType<T>> void markPoints(final Img<T> img, final List<Point> points) {
	for (int i = 0; i < points.size(); i++) {
		RandomAccess<T> randomAccess = img.randomAccess();
		randomAccess.setPosition(points.get(i));
		randomAccess.get().setReal(i + 1);
	}
}
 
开发者ID:imagej,项目名称:imagej-tensorflow,代码行数:9,代码来源:TensorsTest.java

示例8: checkPoints

import net.imglib2.img.Img; //导入方法依赖的package包/类
/** Checks if points in an image are set to the right value */
private <T extends RealType<T>> void checkPoints(final Img<T> img, List<Point> points) {
	for (int i = 0; i < points.size(); i++) {
		RandomAccess<T> randomAccess = img.randomAccess();
		randomAccess.setPosition(points.get(i));
		assertEquals(i + 1, randomAccess.get().getRealFloat(), 0.001);
	}
}
 
开发者ID:imagej,项目名称:imagej-tensorflow,代码行数:9,代码来源:TensorsTest.java

示例9: sample

import net.imglib2.img.Img; //导入方法依赖的package包/类
/**
 * Adds one the value of each image element accessed during sampling.
 * <p>
 * Proceeds along the given section in the image from Section#tMin to
 * Section#tMax. After each increment the section coordinates are floored to
 * the voxel grid.
 * </p>
 * 
 * @param img a 3D image.
 * @param section a section of a line inside the image.
 * @param increment the scalar step between the sample positions. For example,
 *          an increment of 1.0 adds a vector of length 1.0 to the position.
 *          More formally, this is the value added to <em>t</em> in the line.
 * @param random a random generator.
 */
private static void sample(final Img<FloatType> img, final Section section,
	final double increment, final Random random)
{
	final Vector3d startOffset = new Vector3d(section.direction);
	// Add a random offset so that sampling doesn't always start from the same
	// plane
	final double offsetScale = random.nextDouble() * increment;
	startOffset.scale(offsetScale);
	final Vector3d samplePoint = new Vector3d(section.direction);
	samplePoint.scale(section.tMin);
	samplePoint.add(section.origin);
	samplePoint.add(startOffset);
	final Vector3d sampleGap = new Vector3d(section.direction);
	sampleGap.scale(increment);
	final double[] coordinates = new double[3];
	final RandomAccess<FloatType> access = img.randomAccess();
	for (double t = section.tMin + offsetScale; t <= section.tMax; t +=
		increment)
	{
		samplePoint.get(coordinates);
		// Assuming that coordinates are always non-negative
		final long[] voxelCoordinates = Arrays.stream(coordinates).mapToLong(
			c -> (long) c).toArray();
		access.setPosition(voxelCoordinates);
		access.get().setReal(access.get().getRealDouble() + 1.0);
		samplePoint.add(sampleGap);
	}
}
 
开发者ID:bonej-org,项目名称:BoneJ2,代码行数:44,代码来源:MILPOCSampling.java

示例10: testHollowCube

import net.imglib2.img.Img; //导入方法依赖的package包/类
/**
 * Test with a cube that has a cavity inside
 * <p>
 * Here χ = β_0 - β_1 + β_2 = 1 - 0 + 1 = 2
 * </p>
 */
@Test
public void testHollowCube() throws Exception {
    final Img<BitType> img = drawCube(3, 3, 3, 1);
    final RandomAccess<BitType> access = img.randomAccess();

    // Add a cavity
    access.setPosition(new long[]{2, 2, 2});
    access.get().setZero();

    final double result = ops.topology().eulerCharacteristic26N(img).get();

    assertEquals("Euler characteristic (χ) is incorrect", 2.0, result, 1e-12);
}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:20,代码来源:EulerCharacteristic26NTest.java

示例11: makeLapEdgeImg

import net.imglib2.img.Img; //导入方法依赖的package包/类
public static <T extends RealType<T> & NativeType<T>> void makeLapEdgeImg( CrackCorrection<T> cc, int dsFactor){
	
	ArrayList<Edgel> eList = cc.getEdgels();
	
	Img<T> edgeImg = cc.getImg().factory().create(cc.getImg(), cc.getImg().firstElement());
	RandomAccess<T> ra = edgeImg.randomAccess();
	
	double[] pos = new double[ cc.getImg().numDimensions() ];
	int[] posi = null;
	
	int i = 0;
	for( Edgel e : eList )
	{
		double depth = cc.computeDepthLap( e );
		e.localize( pos );

		double[] grd = ArrayUtil.clone(e.getGradient());
		ArrayUtil.normalizeLengthInPlace(grd);
		ArrayUtil.multiply(grd, depth);
		
		ArrayUtil.addInPlace( pos, grd );
	
		posi = ArrayUtil.toIntRound( pos );
		ra.setPosition( posi );
		ra.get().setOne();
		
		i++;
		if( i % 10 == 0 ){
			System.out.println(" edgel " + i + " of " + eList.size() );
		}
	}
	
	ImgOps.writeFloat( edgeImg, "/data-ssd1/john/projects/crackPatching/closeup/lapEdgeImg.tif" );
}
 
开发者ID:bogovicj,项目名称:hhmi-exp,代码行数:35,代码来源:EdgelMatchingExps.java

示例12: testMaskDeriv2

import net.imglib2.img.Img; //导入方法依赖的package包/类
public static <T extends RealType<T>> void testMaskDeriv2 ( Img<T> img, Img<T> grad ){
	ArrayImgFactory<BitType> factory = new ArrayImgFactory<BitType>();
	long nx = img.dimension(0);
	long ny = img.dimension(1);
	
	int fixedy = 1;
	int cx     = 1;
	Img<BitType> mask = factory.create(new long[]{nx, ny}, new BitType(true));
	ImgOps.fill(mask, new BitType(true));
	RandomAccess<BitType> maskRa = mask.randomAccess();
	maskRa.setPosition(new int[]{cx, fixedy});
	
	int d = 0;
	PartialDerivativeDirectional.gradientMask(img, mask, grad, d, maskRa, true);
}
 
开发者ID:bogovicj,项目名称:hhmi-exp,代码行数:16,代码来源:PartialDerivativeDirectional.java

示例13: error

import net.imglib2.img.Img; //导入方法依赖的package包/类
private static double[] error( final Img< UnsignedByteType > out, final Img< UnsignedByteType > ref )
{
	final Cursor< UnsignedByteType > cursor = ref.cursor();
	final RandomAccess< UnsignedByteType > ra = out.randomAccess();
	long iterated = 0;
	long mismatch = 0;
	long mismatchFP = 0;
	long mismatchFN = 0;
	while ( cursor.hasNext() )
	{
		cursor.fwd();
		ra.setPosition( cursor );

		final int refVal = cursor.get().get();
		final int outVal = ra.get().get();

		if ( refVal > 0 )
		{
			iterated++;
			if ( outVal == 0 )
			{
				mismatch++;
				mismatchFN++;
			}
		}
		else
		{
			if ( outVal > 0 )
			{
				mismatch++;
				mismatchFP++;
			}
		}

	}
	return new double[] { ( double ) mismatch / ( double ) iterated, ( double ) mismatchFN / ( double ) iterated, ( double ) mismatchFP / ( double ) iterated };
}
 
开发者ID:imglib,项目名称:imglib2-tests,代码行数:38,代码来源:DiscStrelTest.java

示例14: test1

import net.imglib2.img.Img; //导入方法依赖的package包/类
public static void test1()
	{
		int[] sz = new int[]{ 21, 21, 21 };
		double[] dsFactors = new double[]{ 1, 1, 2 };
		
		Img<FloatType> img = ImgOps.createGradientImgX(sz, new FloatType());
		double[] sigmas = new double[]{ 0, 0, 0.5};
//		double[] sigmas = new double[]{ 2, 2, 0.5};
		
//		RandomAccessibleInterval<FloatType> view = Views.interval( 
//				Views.extendZero(img),
//				img);
		
		Img<FloatType> out = Resampling.resampleGaussian(
				img, 
				img.factory(), 
				dsFactors, sigmas, sigmas);
		
		System.out.println("out: " + out );
		
		int x = 11;
		int y = 11;
		
		RandomAccess<FloatType> ra = out.randomAccess();
		
		for( int z = 0; z < 11; z++ )
		{
			ra.setPosition(x, 0);
			ra.setPosition(y, 1);
			ra.setPosition(z, 2);
			
			System.out.println( " z " + z + "  " + ra.get());
		}
		
		ImgOps.writeFloat( out,  "/groups/saalfeld/home/bogovicj/tmp/grad_ds2.tif");
//		ImageJFunctions.show( out );
		
	}
 
开发者ID:bogovicj,项目名称:hhmi-exp,代码行数:39,代码来源:ResamplingTests.java

示例15: print

import net.imglib2.img.Img; //导入方法依赖的package包/类
public static <T> void print(Img<T> ra, int dim){
	RandomAccess<T> cevRa = ra.randomAccess();
	
	for( int i=0; i < ra.dimension(dim); i++){
		cevRa.setPosition( i , dim );
		System.out.println(" " + cevRa.get());	
	}
}
 
开发者ID:bogovicj,项目名称:hhmi-exp,代码行数:9,代码来源:EdgelToolsTest.java


注:本文中的net.imglib2.img.Img.randomAccess方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。