本文整理汇总了Java中net.imglib2.Cursor.hasNext方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.hasNext方法的具体用法?Java Cursor.hasNext怎么用?Java Cursor.hasNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.Cursor
的用法示例。
在下文中一共展示了Cursor.hasNext方法的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: 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 );
}
示例4: 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);
}
示例5: 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;
}
示例6: invertImage
import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
* Inverts an image.
*
* @param <T> The images data type.
* @param image The image to convert.
* @return The inverted image.
*/
public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> invertImage(
RandomAccessibleInterval<T> image) {
Cursor<T> imgCursor = Views.iterable(image).localizingCursor();
// invert the image
long[] dim = new long[ image.numDimensions() ];
image.dimensions(dim);
ArrayImgFactory<T> imgFactory = new ArrayImgFactory<T>();
RandomAccessibleInterval<T> invImg = imgFactory.create(
dim, image.randomAccess().get().createVariable() ); // "Inverted " + image.getName());
RandomAccess<T> invCursor = invImg.randomAccess();
while (imgCursor.hasNext()) {
imgCursor.fwd();
invCursor.setPosition(imgCursor);
invCursor.get().setReal( imgCursor.get().getMaxValue() - imgCursor.get().getRealDouble() );
}
return invImg;
}
示例7: defaultPermuteCoordinatesInverseTest
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Test
public void defaultPermuteCoordinatesInverseTest() {
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.permuteCoordinatesInverse(img, new int[]{0, 1}).cursor();
RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesInverseView(img, new int[]{0, 1}).randomAccess();
while (il2.hasNext()) {
il2.next();
opr.setPosition(il2);
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
}
示例8: ShearIntervalTest
import net.imglib2.Cursor; //导入方法依赖的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: getImageMin
import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
* Calculates the min of an image.
*
* @param img The image to calculate the min of
* @return The min of the image passed
*/
final public static <T extends Type<T> & Comparable<T>> T getImageMin(
final RandomAccessibleInterval<T> img )
{
final Cursor<T> cursor = Views.iterable(img).cursor();
cursor.fwd();
// copy first element as current maximum
final T min = cursor.get().copy();
while ( cursor.hasNext() )
{
cursor.fwd();
final T currValue = cursor.get();
if ( currValue.compareTo( min ) < 0 )
min.set( currValue );
}
return min;
}
示例10: createData
import net.imglib2.Cursor; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Before
public void createData() {
input = (ImgLabeling<String, IntType>) ops.run(
DefaultCreateImgLabeling.class, new long[] { 10, 10 }, new IntType());
final Cursor<LabelingType<String>> inc = input.cursor();
while (inc.hasNext()) {
inc.next().add(Math.random() > 0.5 ? "A" : "B");
}
// and another loop to construct some ABs
while (inc.hasNext()) {
inc.next().add(Math.random() > 0.5 ? "A" : "B");
}
}
示例11: 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;
}
}
示例12: testIntervalSubsample
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Test
public void testIntervalSubsample() {
Img<DoubleType> img = ArrayImgs.doubles(10, 10);
Random r = new Random();
for (DoubleType d : img) {
d.set(r.nextDouble());
}
SubsampleIntervalView<DoubleType> expected = Views.subsample((RandomAccessibleInterval<DoubleType>) img, 2);
SubsampleIntervalView<DoubleType> actual = (SubsampleIntervalView<DoubleType>) ops.transform().subsampleView((RandomAccessibleInterval<DoubleType>)img, 2);
Cursor<DoubleType> il2C = Views.interval(expected, new long[] { 0, 0 }, new long[] { 4, 4 }).localizingCursor();
RandomAccess<DoubleType> oprRA = actual.randomAccess();
while (il2C.hasNext()) {
il2C.next();
oprRA.setPosition(il2C);
assertEquals(il2C.get().get(), oprRA.get().get(), 1e-10);
}
assertTrue(Intervals.equals(expected, actual));
}
示例13: centralMoment2
import net.imglib2.Cursor; //导入方法依赖的package包/类
public static <T extends RealType<T>> double centralMoment2( Img<T> img, int d ){
double c = moment1(img,d);
int nd = img.numDimensions();
logger.debug("moment 2 central for " + nd + " dims");
double mom = 0;
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] - c) * (loc[d] - c) * lc.get().getRealDouble();
}
return mom;
}
示例14: defaultPermuteCoordinatesTest
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Test
public void defaultPermuteCoordinatesTest() {
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}).cursor();
RandomAccess<DoubleType> opr = ops.transform().permuteCoordinatesView(img, new int[]{0, 1}).randomAccess();
while (il2.hasNext()) {
il2.next();
opr.setPosition(il2);
assertEquals(il2.get().get(), opr.get().get(), 1e-10);
}
}
示例15: fillLabelMap2
import net.imglib2.Cursor; //导入方法依赖的package包/类
protected Img<IntType> fillLabelMap2( float hMin, float threshold, float percentFlooding, boolean keepOrphanPeak ){
int nNodes = segmentTree0.getNumNodes();
int[] nodeIdToLabel = new int[nNodes];
int[] nodeIdToLabelRoot = new int[nNodes];
double[] peakThresholds = new double[nNodes];
this.nLabels = treeLabeler.getLabeling(hMin, threshold, percentFlooding, keepOrphanPeak, nodeIdToLabel, nodeIdToLabelRoot, peakThresholds);
Cursor<IntType> cursor = segmentMap.cursor();
Cursor<T> cursorImg = intensity.cursor();
while( cursor.hasNext() )
{
T imgPixel = cursorImg.next();
float val =imgPixel.getRealFloat();
IntType pixel = cursor.next();
if( val >= threshold )
{
final int nodeId = (int)pixel.getRealFloat();
final int labelRoot = nodeIdToLabelRoot[nodeId];
if( val >= peakThresholds[labelRoot] )
{
final int label = nodeIdToLabel[nodeId];
pixel.setReal( (float)label );
}
else
pixel.setReal( 0.0 );
}
else
pixel.setReal( 0.0 );
}
return segmentMap;
}