本文整理汇总了Java中net.imglib2.img.Img.cursor方法的典型用法代码示例。如果您正苦于以下问题:Java Img.cursor方法的具体用法?Java Img.cursor怎么用?Java Img.cursor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.img.Img
的用法示例。
在下文中一共展示了Img.cursor方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: HWatershedLabeling
import net.imglib2.img.Img; //导入方法依赖的package包/类
public HWatershedLabeling(Img<T> input, float threshold, Connectivity connectivity)
{
int nDims = input.numDimensions();
long[] dims = new long[nDims];
input.dimensions(dims);
ImgFactory<IntType> imgFactoryIntType=null;
try {
imgFactoryIntType = input.factory().imgFactory( new IntType() );
} catch (IncompatibleTypeException e) {
e.printStackTrace();
}
if ( imgFactoryIntType != null )
{
this.labelMapMaxTree = imgFactoryIntType.create(dims, new IntType(0));
Cursor<IntType> c_label = labelMapMaxTree.cursor();
Cursor<T> c_input = input.cursor();
while( c_input.hasNext() )
{
c_label.next().setInteger( (int) c_input.next().getRealFloat() );
}
}
this.threshold = threshold;
this.connectivity = connectivity;
}
示例2: copyChannelUSST
import net.imglib2.img.Img; //导入方法依赖的package包/类
public static Img< UnsignedShortType > copyChannelUSST( final ImagePlus imp, final int channel )
{
final int w, h, d;
Img< UnsignedShortType > img = ArrayImgs.unsignedShorts( w = imp.getWidth(), h = imp.getHeight(), d = imp.getNSlices() );
final Cursor< UnsignedShortType > c = img.cursor();
for ( int z = 0; z < d; ++z )
{
final int[] pixels = (int[])imp.getStack().getProcessor( z + 1 ).getPixels();
for ( int i = 0; i < w*h; ++i )
{
if ( channel == 0 )
c.next().set( ( pixels[ i ] & 0xff0000) >> 16 );
else if ( channel == 1 )
c.next().set( ( pixels[ i ] & 0xff00 ) >> 8 );
else
c.next().set( pixels[ i ] & 0xff );
}
}
return img;
}
示例3: copyChannel
import net.imglib2.img.Img; //导入方法依赖的package包/类
public static Img< FloatType > copyChannel( final ImagePlus imp, final int channel )
{
final int w, h, d;
Img< FloatType > img = ArrayImgs.floats( w = imp.getWidth(), h = imp.getHeight(), d = imp.getNSlices() );
final Cursor< FloatType > c = img.cursor();
for ( int z = 0; z < d; ++z )
{
final int[] pixels = (int[])imp.getStack().getProcessor( z + 1 ).getPixels();
for ( int i = 0; i < w*h; ++i )
{
if ( channel == 0 )
c.next().set( ( pixels[ i ] & 0xff0000) >> 16 );
else if ( channel == 1 )
c.next().set( ( pixels[ i ] & 0xff00 ) >> 8 );
else
c.next().set( pixels[ i ] & 0xff );
}
}
return img;
}
示例4: testMean
import net.imglib2.img.Img; //导入方法依赖的package包/类
@Test
public void testMean() {
final Img<ByteType> image = generateByteArrayTestImg(true, 40, 50);
final DoubleType mean = new DoubleType();
ops.run(IterableMean.class, mean, image);
assertEquals(1.0 / 15.625, mean.get(), 0.0);
Cursor<ByteType> c = image.cursor();
// this time lets just make every value 100
while (c.hasNext()) {
c.fwd();
c.get().setReal(100.0);
}
ops.run(IterableMean.class, mean, image);
// the mean should be 100
assertEquals(100.0, mean.get(), 0.0);
}
示例5: testListDilateFull
import net.imglib2.img.Img; //导入方法依赖的package包/类
@Test
public void testListDilateFull() {
final List<Shape> shapes = new ArrayList<>();
shapes.add(new DiamondShape(1));
shapes.add(new DiamondShape(1));
shapes.add(new RectangleShape(1, false));
shapes.add(new HorizontalLineShape(2, 1, false));
@SuppressWarnings("unchecked")
final IterableInterval<ByteType> out1 = (IterableInterval<ByteType>) ops
.run(ListDilate.class, IterableInterval.class, in, shapes, true);
final Img<ByteType> out2 = Dilation.dilateFull(in, shapes, 1);
final Cursor<ByteType> c1 = out1.cursor();
final Cursor<ByteType> c2 = out2.cursor();
while (c1.hasNext())
assertEquals(c1.next().get(), c2.next().get());
}
示例6: testIntervalPermuteInverseDimensionCoordinates
import net.imglib2.img.Img; //导入方法依赖的package包/类
@Test
public void testIntervalPermuteInverseDimensionCoordinates() {
Img<DoubleType> img = ArrayImgs.doubles(2, 2);
Cursor<DoubleType> c = img.cursor();
Random r = new Random();
while (c.hasNext()) {
c.next().set(r.nextDouble());
}
IntervalView<DoubleType> expected = Views.permuteCoordinateInverse(img, new int[]{0, 1}, 1);
Cursor<DoubleType> e = expected.cursor();
RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}, 1);
RandomAccess<DoubleType> actualRA = actual.randomAccess();
while (e.hasNext()) {
e.next();
actualRA.setPosition(e);
assertEquals(e.get().get(), actualRA.get().get(), 1e-10);
}
assertTrue(Intervals.equals(expected, actual));
}
示例7: DotProduct
import net.imglib2.img.Img; //导入方法依赖的package包/类
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;
}
示例8: ShearIntervalTest
import net.imglib2.img.Img; //导入方法依赖的package包/类
/** Tests {@link ShearViewInterval}. */
@Test
public void ShearIntervalTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 2, 2 }, new DoubleType());
Cursor<DoubleType> imgC = img.cursor();
while (imgC.hasNext()) {
imgC.next().set(1);
}
Cursor<DoubleType> il2 = Views
.shear(Views.extendZero(img), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1)
.cursor();
RandomAccess<DoubleType> opr = ops.transform()
.shearView(Views.extendZero(img), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1)
.randomAccess();
while (il2.hasNext()) {
il2.next();
opr.setPosition(il2);
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
}
示例9: copyToImageProcessor3dFloat
import net.imglib2.img.Img; //导入方法依赖的package包/类
public static <T extends RealType<T> & NativeType<T>> void copyToImageProcessor3dFloat(Img<T> img, ImagePlus ip) throws Exception {
Cursor<T> c_in = img.cursor();
logger.debug("copying to float 3d");
int i = 0;
while(c_in.hasNext()){
c_in.fwd();
// if ( i%1000 == 0 ) {logger.debug(" c_in " + (i++) ); }
// else{ i++; }
ImageProcessor fp = ip.getStack().getProcessor(c_in.getIntPosition(2)+1);
fp.setf(c_in.getIntPosition(0), c_in.getIntPosition(1),
c_in.get().getRealFloat());
}
logger.debug("done copying");
}
示例10: testNormalize
import net.imglib2.img.Img; //导入方法依赖的package包/类
@Test
public void testNormalize() {
Img<ByteType> in = generateByteArrayTestImg(true, 5, 5);
Img<ByteType> out = in.factory().create(in, new ByteType());
ops.run(NormalizeIIComputer.class, out, in);
final Pair<ByteType, ByteType> minMax2 = ops.stats().minMax(out);
assertEquals(minMax2.getA().get(), Byte.MIN_VALUE);
assertEquals(minMax2.getB().get(), Byte.MAX_VALUE);
final IterableInterval<ByteType> lazyOut = ops.image().normalize(in);
final IterableInterval<ByteType> notLazyOut = ops.image().normalize(in,
null, null, null, null, false);
final Cursor<ByteType> outCursor = out.cursor();
final Cursor<ByteType> lazyCursor = lazyOut.cursor();
final Cursor<ByteType> notLazyCursor = notLazyOut.cursor();
while (outCursor.hasNext()) {
assertEquals(outCursor.next().get(), lazyCursor.next().get());
assertEquals(outCursor.get().get(), notLazyCursor.next().get());
}
}
示例11: testNegatives
import net.imglib2.img.Img; //导入方法依赖的package包/类
@Test
public void testNegatives() {
final byte[] data = { -7, -8, -9, -1, -2, -3, -7, -9, -8, -1, -3, -2, -8, -7, -9, -2, -1, -3, -8, -9, -7, -2,
-3, -1, -9, -7, -8, -3, -1, -2, -9, -8, -7, -3, -2, -1 };
final Img<ByteType> in = ArrayImgs.bytes(data, 6, 6);
final Img<ByteType> out = generateByteArrayTestImg(false, 6, 6);
ops.run(DefaultBilateral.class, out, in, 15, 5, 2);
final byte[] expected = { -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6,
-4, -3, -2, -8, -7, -6, -4, -3, -2, -8, -7, -6, -4, -3, -2 };
Cursor<ByteType> cout = out.cursor();
for (int i = 0; i < expected.length; i++) {
assertEquals(cout.next().get(), expected[i]);
}
}
示例12: getOutlinePixels
import net.imglib2.img.Img; //导入方法依赖的package包/类
public < T extends RealType< T > & NativeType< T > > ArrayList<int[]> getOutlinePixels(Img<T> img)
{
ArrayList<int[]> outlinePixelsIndices = new ArrayList<int[]>();
Cursor<T> c = img.cursor();
while (c.hasNext())
{
IntegerType t = (IntegerType)c.next();
int[] position = new int[2];
if(t.getInteger()==255)
{
c.localize(position);
outlinePixelsIndices.add(position);
}
}
//IJ.log("" + ((int[])outlinePixelsIndices.get(12))[0]);
return outlinePixelsIndices;
}
示例13: testIntervalPermuteInverseCoordinates
import net.imglib2.img.Img; //导入方法依赖的package包/类
@Test
public void testIntervalPermuteInverseCoordinates() {
Img<DoubleType> img = ArrayImgs.doubles(2, 2);
Cursor<DoubleType> c = img.cursor();
Random r = new Random();
while (c.hasNext()) {
c.next().set(r.nextDouble());
}
IntervalView<DoubleType> expected = Views.permuteCoordinatesInverse(img, new int[]{0, 1});
Cursor<DoubleType> e = expected.cursor();
RandomAccessibleInterval<DoubleType> actual = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1});
RandomAccess<DoubleType> actualRA = actual.randomAccess();
while (e.hasNext()) {
e.next();
actualRA.setPosition(e);
assertEquals(e.get().get(), actualRA.get().get(), 1e-10);
}
assertTrue(Intervals.equals(expected, actual));
}
示例14: assertComplexImagesEqual
import net.imglib2.img.Img; //导入方法依赖的package包/类
protected void assertComplexImagesEqual(final Img<ComplexFloatType> img1,
final Img<ComplexFloatType> img2, final float delta)
{
final Cursor<ComplexFloatType> c1 = img1.cursor();
final Cursor<ComplexFloatType> c2 = img2.cursor();
while (c1.hasNext()) {
c1.fwd();
c2.fwd();
// assert that the inverse = the input within the error delta
assertEquals(c1.get().getRealFloat(), c2.get().getRealFloat(), delta);
// assert that the inverse = the input within the error delta
assertEquals(c1.get().getImaginaryFloat(), c2.get().getImaginaryFloat(),
delta);
}
}
示例15: permuteCoordinatesOfDimensionTest
import net.imglib2.img.Img; //导入方法依赖的package包/类
@Test
public void permuteCoordinatesOfDimensionTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[]{2, 2}, new DoubleType());
Cursor<DoubleType> c = img.cursor();
Random r = new Random();
while (c.hasNext()) {
c.next().set(r.nextDouble());
}
Cursor<DoubleType> il2 = Views.permuteCoordinates(img, new int[]{0, 1}, 1).cursor();
RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}, 1).randomAccess();
while (il2.hasNext()) {
il2.next();
opr.setPosition(il2);
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
}