本文整理汇总了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);
}
}
示例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);
}
}
示例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;
}
示例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 );
}
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
示例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" );
}
示例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);
}
示例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 };
}
示例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 );
}
示例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());
}
}