本文整理汇总了Java中net.imglib2.Cursor类的典型用法代码示例。如果您正苦于以下问题:Java Cursor类的具体用法?Java Cursor怎么用?Java Cursor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Cursor类属于net.imglib2包,在下文中一共展示了Cursor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getLabelMap
import net.imglib2.Cursor; //导入依赖的package包/类
/**
* Relabel the label map according to the tree labeling.
* @param threshold , all pixel below threshold are set to 0
* @param percentFlooding , percent of the peak that will be flooded (percent between label maximum and the threshold)
* @return a label image corresponding to the current tree labeling, threshold, percentFlooding parameters
*/
public Img<IntType> getLabelMap( float hMin, float threshold, float percentFlooding, boolean keepOrphanPeak){
intensity = (IterableInterval<T>) intensity0;
int nDims = segmentMap0.numDimensions();
long[] dims = new long[nDims];
segmentMap0.dimensions(dims);
segmentMap = segmentMap0.factory().create(dims, segmentMap0.firstElement().createVariable() );
Cursor<IntType> cursor = segmentMap.cursor();
Cursor<IntType> cursor0 = segmentMap0.cursor();
while(cursor0.hasNext()){
cursor.next().set( cursor0.next().get() );
}
Img<IntType> labelMap = fillLabelMap2(hMin, threshold, percentFlooding, keepOrphanPeak);
return labelMap;
}
示例2: HWatershedLabeling
import net.imglib2.Cursor; //导入依赖的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;
}
示例3: setUpBeforeClass
import net.imglib2.Cursor; //导入依赖的package包/类
/**
* @throws java.lang.Exception
*/
@BeforeClass
public static void setUpBeforeClass() throws Exception {
final File testDir = new File(testDirPath);
testDir.mkdirs();
if (!(testDir.exists() && testDir.isDirectory()))
throw new IOException("Could not create benchmark directory for HDF5Utils benchmark.");
data = new short[64 * 64 * 64];
final ImagePlus imp = new Opener().openURL("https://imagej.nih.gov/ij/images/t1-head-raw.zip");
final ImagePlusImg<UnsignedShortType, ?> img = (ImagePlusImg<UnsignedShortType, ?>)(Object)ImagePlusImgs.from(imp);
final Cursor<UnsignedShortType> cursor = Views.flatIterable(Views.interval(img, new long[]{100, 100, 30}, new long[]{163, 163, 93})).cursor();
for (int i = 0; i < data.length; ++i)
data[i] = (short)cursor.next().get();
n5 = new N5FSWriter(testDirPath);
}
示例4: gradient
import net.imglib2.Cursor; //导入依赖的package包/类
/**
* Compute the partial derivative of source in a particular dimension.
*
* @param source
* source image, has to provide valid data in the interval of the
* gradient image plus a one pixel border in dimension.
* @param target
* output image, the partial derivative of source in the
* specified dimension.
* @param dimension
* along which dimension the partial derivatives are computed
* @param <T> pixel type source
* @param <S> pixel type target
*/
public static < T extends RealType< T >, S extends RealType< S > > void gradient(
final RandomAccessible< T > source,
final RandomAccessibleInterval< S > target,
final int dimension )
{
final Cursor< T > front = Views.flatIterable(
Views.interval( source,
Intervals.translate( target, 1, dimension ) ) ).cursor();
final Cursor< T > back = Views.flatIterable(
Views.interval( source,
Intervals.translate( target, -1, dimension ) ) ).cursor();
for( final S t : Views.flatIterable( target ) )
{
t.setReal( front.next().getRealDouble() - back.next().getRealDouble());
t.mul( 0.5 );
}
}
示例5: copyChannelUSST
import net.imglib2.Cursor; //导入依赖的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;
}
示例6: copyChannel
import net.imglib2.Cursor; //导入依赖的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;
}
示例7: main
import net.imglib2.Cursor; //导入依赖的package包/类
public static void main( String[] args )
{
new ImageJ();
Img< FloatType > img = ArrayImgs.floats( 500, 500 );
BlendingRealRandomAccess blend = new BlendingRealRandomAccess(
img,
new float[]{ 100, 0 },
new float[]{ 12, 150 } );
Cursor< FloatType > c = img.localizingCursor();
while ( c.hasNext() )
{
c.fwd();
blend.setPosition( c );
c.get().setReal( blend.get().getRealFloat() );
}
ImageJFunctions.show( img );
}
示例8: convertToGenericTexture
import net.imglib2.Cursor; //导入依赖的package包/类
public static GenericTexture convertToGenericTexture( Dataset d ) {
long width = d.getWidth();
long height = d.getHeight();
GLVector dims = new GLVector( width, height, 1 );
int nChannels = 3;
ByteBuffer bb = BufferUtils.BufferUtils.allocateByte((int) (width * height * nChannels));
System.out.println("Size:" + width + " " + height + " " + nChannels);
Cursor cur = d.cursor();
while( cur.hasNext() ) {
cur.fwd();
int val = ((UnsignedByteType) cur.get()).get();
//System.out.println( (byte)val );
bb.put( (byte) val );
//bb.put((byte)(Math.random()*255));
}
bb.flip();
return new GenericTexture("neverUsed", dims, nChannels, GLTypeEnum.UnsignedByte, bb, true, true, false);
}
示例9: minMax
import net.imglib2.Cursor; //导入依赖的package包/类
public double[] minMax()
{
double[] minmax = new double[ 2 ];
minmax[ 0 ] = Double.MAX_VALUE;
minmax[ 1 ] = Double.MIN_VALUE;
Cursor<T> curs = Views.iterable( this.getSource( 0,0 ) ).cursor();
while( curs.hasNext() )
{
double val = curs.next().getRealDouble();
if( val < minmax[ 0 ])
minmax[ 0 ] = val;
else if( val > minmax[ 1 ])
minmax[ 1 ] = val;
}
return minmax;
}
示例10: testListDilateFull
import net.imglib2.Cursor; //导入依赖的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());
}
示例11: moment1
import net.imglib2.Cursor; //导入依赖的package包/类
public static <T extends RealType<T>> double moment1( IterableInterval<T> img, int d ){
logger.debug("moment 1 ");
double mom = 0;
int nd = img.numDimensions();
if( d >= nd){
logger.warn("Dimension for moment must be less than image dimensionality ... returning 0");
return mom;
}
double[] loc = new double[nd];
Cursor<T> lc = img.localizingCursor();
while(lc.hasNext()){
lc.next();
lc.localize(loc);
mom += loc[d] * lc.get().getRealDouble();
}
logger.debug("result: " + mom);
return mom;
}
示例12: UnshearIntervalTest
import net.imglib2.Cursor; //导入依赖的package包/类
@Test
public void UnshearIntervalTest() {
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
.unshear(Views.shear(Views.extendZero(img), 0, 1), new FinalInterval(new long[] { 0, 0 }, new long[] { 3, 3 }), 0, 1)
.cursor();
RandomAccess<DoubleType> opr = ops.transform()
.unshearView(Views.shear(Views.extendZero(img), 0, 1), 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);
}
}
示例13: correctIllumination
import net.imglib2.Cursor; //导入依赖的package包/类
static public Img<FloatType> correctIllumination(
final Img<? extends RealType<?>> img,
final Img<? extends RealType<?>> brightfield,
final Img<? extends RealType<?>> darkfield,
final double mean) {
p("Start direct (correct illumination)...");
long t0 = System.nanoTime();
Img<FloatType> corrected = new ArrayImgFactory<FloatType>().create(img, new FloatType());
final Cursor<FloatType> c = corrected.cursor();
final Cursor<? extends RealType<?>> ci = img.cursor(),
cb = brightfield.cursor(),
cd = darkfield.cursor();
while (c.hasNext()) {
c.fwd();
ci.fwd();
cb.fwd();
cd.fwd();
c.get().setReal( ( (ci.get().getRealDouble() - cb.get().getRealDouble())
/ (cb.get().getRealDouble() - cd.get().getRealDouble()))
* mean);
}
p(" elapsed: " + (System.nanoTime() - t0)/1000000.0 + " image");
return corrected;
}
示例14: assertComplexImagesEqual
import net.imglib2.Cursor; //导入依赖的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: copyToFloatImagePlus
import net.imglib2.Cursor; //导入依赖的package包/类
/** Copy the contents from img to an ImagePlus; assumes containers are compatible. */
static public ImagePlus copyToFloatImagePlus(final Img<? extends RealType<?>> img, final String title) {
ImagePlusImgFactory<FloatType> factory = new ImagePlusImgFactory<FloatType>();
ImagePlusImg<FloatType, ?> iml = factory.create(img, new FloatType());
Cursor<FloatType> c1 = iml.cursor();
Cursor<? extends RealType<?>> c2 = img.cursor();
while (c1.hasNext()) {
c1.fwd();
c2.fwd();
c1.get().set(c2.get().getRealFloat());
}
try {
ImagePlus imp = iml.getImagePlus();
imp.setTitle(title);
return imp;
} catch (ImgLibException e) {
e.printStackTrace();
return null;
}
}