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


Java Cursor.get方法代码示例

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


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

示例1: calculatePearson

import net.imglib2.Cursor; //导入方法依赖的package包/类
protected double calculatePearson(Cursor<T> cursor1, double mean1, Cursor<T> cursor2, double mean2) {
double pearsonDenominator = 0;
double ch1diffSquaredSum = 0;
double ch2diffSquaredSum = 0;
while (cursor1.hasNext() && cursor2.hasNext()) {
	cursor1.fwd();
	cursor2.fwd();
	T type1 = cursor1.get();
	double ch1diff = type1.getRealDouble() - mean1;
	T type2 = cursor2.get();
	double ch2diff = type2.getRealDouble() - mean2;
	pearsonDenominator += ch1diff*ch2diff;
	ch1diffSquaredSum += (ch1diff*ch1diff);
	ch2diffSquaredSum += (ch2diff*ch2diff);
}
double pearsonNumerator = Math.sqrt(ch1diffSquaredSum * ch2diffSquaredSum);
return pearsonDenominator / pearsonNumerator;
 }
 
开发者ID:fiji,项目名称:Colocalisation_Analysis,代码行数:19,代码来源:ColocImgLibGadgets.java

示例2: 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;
 }
 
开发者ID:fiji,项目名称:Colocalisation_Analysis,代码行数:27,代码来源:ImageStatistics.java

示例3: getImageMax

import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
 * Calculates the max of an image.
 *
 * @param img The image to calculate the max of
 * @return The max of the image passed
 */
final public static <T extends Type<T> & Comparable<T>> T getImageMax(
		final RandomAccessibleInterval<T> img ) {

	final Cursor<T> cursor = Views.iterable(img).localizingCursor();
	cursor.fwd();
	// copy first element as current maximum
	final T max = cursor.get().copy();

	while ( cursor.hasNext() )
	{
		cursor.fwd();

		final T currValue = cursor.get();

		if ( currValue.compareTo( max ) > 0 )
			max.set( currValue );
	}

       return max;
}
 
开发者ID:fiji,项目名称:Colocalisation_Analysis,代码行数:27,代码来源:ImageStatistics.java

示例4: LoopThroughHyperSlicesTest

import net.imglib2.Cursor; //导入方法依赖的package包/类
@Test
public void LoopThroughHyperSlicesTest() {
	final int xSize = 40;
	final int ySize = 50;
	final int numChannels = 3;
	final int numSlices = 25;
	final int numTimePoints = 5;

	final Img<UnsignedByteType> testImage = generateUnsignedByteArrayTestImg(true, xSize, ySize, numChannels,
			numSlices, numTimePoints);

	final int[] axisIndices = new int[3];

	// set up the axis so the resulting hyperslices are x,y,z and
	// we loop through channels and time
	axisIndices[0] = 0;
	axisIndices[1] = 1;
	axisIndices[2] = 3;

	final SlicesII<UnsignedByteType> hyperSlices = new SlicesII<>(testImage, axisIndices, true);

	final Cursor<RandomAccessibleInterval<UnsignedByteType>> c = hyperSlices.cursor();

	int numHyperSlices = 0;
	while (c.hasNext()) {
		c.fwd();
		numHyperSlices++;
		final RandomAccessibleInterval<UnsignedByteType> hyperSlice = c.get();
		assertEquals(3, hyperSlice.numDimensions());
		assertEquals(hyperSlice.dimension(0), xSize);
		assertEquals(hyperSlice.dimension(1), ySize);
		assertEquals(hyperSlice.dimension(2), numSlices);
	}

	assertEquals(numChannels * numTimePoints, numHyperSlices);

}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:38,代码来源:SliceTest.java

示例5: testIntegralCursor

import net.imglib2.Cursor; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testIntegralCursor() {
	Shape rectangleShape = new RectangleShape(1, false);
	IterableInterval<Neighborhood<ByteType>> ii = rectangleShape
		.neighborhoodsSafe(img);
	Cursor<Neighborhood<ByteType>> cursor = ii.cursor();

	// Manually select the neighborhood that is centered on the image
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();

	IntegralCursor<ByteType> integralCursor = new IntegralCursor<>(
		(RectangleNeighborhood) cursor.get());

	assertEquals(integralCursor.next(), new ByteType((byte) 1));
	assertEquals(integralCursor.next(), new ByteType((byte) 2));
	assertEquals(integralCursor.next(), new ByteType((byte) 5));
	assertEquals(integralCursor.next(), new ByteType((byte) 4));
	assertFalse(integralCursor.hasNext());

	integralCursor.reset();

	assertEquals(integralCursor.next(), new ByteType((byte) 1));
	assertEquals(integralCursor.next(), new ByteType((byte) 2));
	assertEquals(integralCursor.next(), new ByteType((byte) 5));
	assertEquals(integralCursor.next(), new ByteType((byte) 4));
	assertFalse(integralCursor.hasNext());
}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:33,代码来源:IntegralCursorTest.java

示例6: testIntegralCursorCopyConstructor

import net.imglib2.Cursor; //导入方法依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testIntegralCursorCopyConstructor() {
	Shape rectangleShape = new RectangleShape(1, false);
	IterableInterval<Neighborhood<ByteType>> ii = rectangleShape
		.neighborhoodsSafe(img);
	Cursor<Neighborhood<ByteType>> cursor = ii.cursor();

	// Manually select the neighborhood that is centered on the image
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();
	cursor.fwd();

	IntegralCursor<ByteType> integralCursor = new IntegralCursor<>(
		(RectangleNeighborhood) cursor.get());
	assertEquals(integralCursor.next(), new ByteType((byte) 1));
	assertEquals(integralCursor.next(), new ByteType((byte) 2));

	IntegralCursor<ByteType> integralCursor2 = new IntegralCursor<>(
		integralCursor);
	assertEquals(integralCursor2.next(), new ByteType((byte) 5));
	assertEquals(integralCursor2.next(), new ByteType((byte) 4));

	assertFalse(integralCursor2.hasNext());
}
 
开发者ID:imagej,项目名称:imagej-ops,代码行数:28,代码来源:IntegralCursorTest.java

示例7: printCursorOutput

import net.imglib2.Cursor; //导入方法依赖的package包/类
public static <T> String printCursorOutput(IterableInterval<T> itvl){
	Cursor<T> c = itvl.cursor();
	String str = "";
	while( c.hasNext() ){
		c.fwd();
		str += " " + c.get();
	}
	str += "\n";
	return str;
}
 
开发者ID:bogovicj,项目名称:hhmi-exp,代码行数:11,代码来源:ImgOps.java

示例8: generateRandomImageStack

import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
  * To randomize blockwise we enumerate the blocks, shuffle that list and
  * write the data to their new position based on the shuffled list.
  */
 protected Img<T> generateRandomImageStack(Img<T> img, int[] blockDimensions) {
int numberOfDimensions = Math.min(img.numDimensions(), blockDimensions.length);
int numberOfBlocks = 0;
long[] numberOfBlocksPerDimension = new long[numberOfDimensions];

for (int i = 0 ; i<numberOfDimensions; i++){
	if (img.dimension(i) % blockDimensions[i] != 0){
		System.out.println("sorry, for now image dims must be divisable by block size");
		return null;
	}
	numberOfBlocksPerDimension[i] = img.dimension(i) / blockDimensions[i];
	numberOfBlocks *= numberOfBlocksPerDimension[i];
}
List<Integer> allTheBlocks = new ArrayList<Integer>(numberOfBlocks);
for (int i = 0; i<numberOfBlocks; i++){
	allTheBlocks.add(new Integer(i));
}
Collections.shuffle(allTheBlocks, new Random());
Cursor<T> cursor = img.cursor();

// create factories for new image stack
//ContainerFactory containerFactory = new ImagePlusContainerFactory();
ImgFactory<T> imgFactory = new ArrayImgFactory<T>();
//new ImageFactory<T>(cursor.getType(), containerFactory);

// create a new stack for the random images
final long[] dim = new long[ img.numDimensions() ];
img.dimensions(dim);
Img<T> randomStack = imgFactory.create(dim, img.firstElement().createVariable());

// iterate over image data
while (cursor.hasNext()) {
	cursor.fwd();
	T type = cursor.get();
	// type.getRealDouble();
}

return randomStack;
 }
 
开发者ID:fiji,项目名称:Colocalisation_Analysis,代码行数:44,代码来源:ColocImgLibGadgets.java

示例9: getImageMean

import net.imglib2.Cursor; //导入方法依赖的package包/类
protected double getImageMean(Img<T> img) {
 double sum = 0;
 Cursor<T> cursor = img.cursor();
 while (cursor.hasNext()) {
  cursor.fwd();
  T type = cursor.get();
  sum += type.getRealDouble();
 }
 return sum / ImageStatistics.getNumPixels(img);
}
 
开发者ID:fiji,项目名称:Colocalisation_Analysis,代码行数:11,代码来源:ColocImgLibGadgets.java

示例10: createMask

import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
 * Create a new mask based on a threshold condition for two images.
 */
public static<T extends RealType< T >> RandomAccessibleInterval<BitType> createMask(
		RandomAccessibleInterval<T> ch1, RandomAccessibleInterval<T> ch2,
		T threshold1, T threshold2, ThresholdMode tMode, CombinationMode cMode) {
	
	final long[] dims = new long[ ch1.numDimensions() ];
	ch1.dimensions(dims);
	RandomAccessibleInterval<BitType> mask = createMask(dims);
	Cursor<T> cursor1 = Views.iterable(ch1).cursor();
	Cursor<T> cursor2 = Views.iterable(ch2).cursor();
	Cursor<BitType> maskCursor = Views.iterable(mask).cursor();
	
	while (cursor1.hasNext() && cursor2.hasNext() && maskCursor.hasNext()) {
		cursor1.fwd();
		cursor2.fwd();
		maskCursor.fwd();
		
		boolean ch1Valid, ch2Valid;
		
		T data1 = cursor1.get();
		T data2 = cursor2.get();
		
		// get relation to threshold
		if (tMode == ThresholdMode.Above) {
			ch1Valid = data1.compareTo(threshold1) > 0;
			ch2Valid = data2.compareTo(threshold2) > 0;
		} else if (tMode == ThresholdMode.Below) {
			ch1Valid = data1.compareTo(threshold1) < 0;
			ch2Valid = data2.compareTo(threshold2) < 0;
		} else {
			throw new UnsupportedOperationException();
		}
		
		BitType maskData = maskCursor.get();
		
		// combine the results into mask
		if (cMode == CombinationMode.AND) {
			maskData.set( ch1Valid && ch2Valid );
		} else if (cMode == CombinationMode.OR) {
			maskData.set( ch1Valid || ch2Valid );
		} else if (cMode == CombinationMode.NONE) {
			maskData.set( !(ch1Valid || ch2Valid) );
		} else {
			throw new UnsupportedOperationException();
		}
	}
	
	return mask;
}
 
开发者ID:fiji,项目名称:Colocalisation_Analysis,代码行数:52,代码来源:MaskFactory.java

示例11: getBoundingBoxOfMask

import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
 * A method to get the bounding box from the data in the given image that is
 * above zero. Those values are interpreted as a mask. It will return null if
 * no mask information was found.
 *
 * @param mask The image to look for "on" values in
 * @return a new MaskInfo object or null
 */
protected MaskInfo getBoundingBoxOfMask(final Img<T> mask) {
	final Cursor<T> cursor = mask.localizingCursor();

	final int numMaskDims = mask.numDimensions();
	// the "off type" of the mask
	final T offType = mask.firstElement().createVariable();
	offType.setZero();
	// the corners of the bounding box
	final long[][] minMax = new long[2][];
	// indicates if mask data has been found
	boolean maskFound = false;
	// a container for temporary position information
	final long[] pos = new long[numMaskDims];
	// walk over the mask
	while (cursor.hasNext()) {
		cursor.fwd();
		final T data = cursor.get();
		// test if the current mask data represents on or off
		if (data.compareTo(offType) > 0) {
			// get current position
			cursor.localize(pos);
			if (!maskFound) {
				// we found mask data, first time
				maskFound = true;
				// init min and max with the current position
				minMax[0] = Arrays.copyOf(pos, numMaskDims);
				minMax[1] = Arrays.copyOf(pos, numMaskDims);
			}
			else {
				/* Is is at least second hit, compare if it
				 * has new "extreme" positions, i.e. does
				 * is make the BB bigger?
				 */
				for (int d = 0; d < numMaskDims; d++) {
					if (pos[d] < minMax[0][d]) {
						// is it smaller than min
						minMax[0][d] = pos[d];
					}
					else if (pos[d] > minMax[1][d]) {
						// is it larger than max
						minMax[1][d] = pos[d];
					}
				}
			}
		}
	}
	if (!maskFound) return null;

	// calculate size
	final long[] size = new long[numMaskDims];
	for (int d = 0; d < numMaskDims; d++)
		size[d] = minMax[1][d] - minMax[0][d] + 1;
	// create and add bounding box
	final BoundingBox bb = new BoundingBox(minMax[0], size);
	return new MaskInfo(bb, mask);
}
 
开发者ID:fiji,项目名称:Colocalisation_Analysis,代码行数:65,代码来源:Coloc_2.java

示例12: irregularRoiDimensionTest

import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
 * This test makes sure that a mask that is based on a lower dimension
 * image has the correct dimensionality.
 */
@Test
public void irregularRoiDimensionTest() {
	// load a 3D test image
	RandomAccessibleInterval<UnsignedByteType> img = positiveCorrelationImageCh1;
	final long width = img.dimension(0);
	final long height = img.dimension(1);
	final long slices = img.dimension(2);
	final long[] dimImg = new long[ img.numDimensions() ];
	img.dimensions(dimImg);
	// create a random noise 2D image -- set roiWidh/roiSize accordingly
	RandomAccessibleInterval<UnsignedByteType> maskSlice =
		TestImageAccessor.produceSticksNoiseImage( (int) width, (int) height, 50, 2, 10);
	RandomAccessibleInterval<BitType> mask =
			MaskFactory.createMask(dimImg, maskSlice);
	final long[] dimMask = new long[ mask.numDimensions() ];
	mask.dimensions(dimMask);
	// check the dimensions of the mask
	org.junit.Assert.assertArrayEquals(dimImg, dimMask);
	// make sure the mask actually got the same content on every slice
	final double[] offset = new double[ mask.numDimensions() ];
	Arrays.fill(offset, 0);
	double[] size = new double[ mask.numDimensions() ];
	size[0] = width;
	size[1] = height;
	size[2] = 1;
	RandomAccess<BitType> maskCursor = mask.randomAccess();
	RectangleRegionOfInterest roi = new RectangleRegionOfInterest( offset, size);
	Cursor<BitType> firstSliceCursor = roi.getIterableIntervalOverROI(mask).cursor();
	
	final long[] pos = new long[ mask.numDimensions() ];
	while (firstSliceCursor.hasNext()) {
		firstSliceCursor.fwd();
		firstSliceCursor.localize(pos);
		BitType maskValue = firstSliceCursor.get();
		// go through all slices
		for (int i=1; i<slices; ++i) {
			pos[2] = i;
			maskCursor.setPosition(pos);
			// compare the values and assume they are the same
			int cmp = maskCursor.get().compareTo(maskValue);
			assertEquals(0, cmp);
		}
	}
}
 
开发者ID:fiji,项目名称:Colocalisation_Analysis,代码行数:49,代码来源:MaskAndRoiTest.java


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