本文整理汇总了Java中net.imglib2.Cursor.getIntPosition方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.getIntPosition方法的具体用法?Java Cursor.getIntPosition怎么用?Java Cursor.getIntPosition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.Cursor
的用法示例。
在下文中一共展示了Cursor.getIntPosition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: calculate
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Override
public RandomAccessibleInterval<T> calculate(double[] input) {
final double[] sigmaPixels = new double[input.length];
final long[] dims = new long[input.length];
final double[][] kernelArrays = new double[input.length][];
for (int d = 0; d < input.length; d++) {
sigmaPixels[d] = input[d];
dims[d] = Math.max(3, (2 * (int) (3 * sigmaPixels[d] + 0.5) + 1));
kernelArrays[d] = Util.createGaussianKernel1DDouble(sigmaPixels[d], true);
}
final RandomAccessibleInterval<T> out = createOp.calculate(new FinalInterval(
dims));
final Cursor<T> cursor = Views.iterable(out).cursor();
while (cursor.hasNext()) {
cursor.fwd();
double result = 1.0f;
for (int d = 0; d < input.length; d++) {
result *= kernelArrays[d][cursor.getIntPosition(d)];
}
cursor.get().setReal(result);
}
return out;
}
示例2: writeImage
import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
* @param image
* Image to be stored in dvid server.
* @param iterationAxis
* Along which axis to iterate.
* @param steps
* Step sizes along each axis.
* @param offset
* Offset target position by offset.
* @param borderExtension
* Extend border with this value.
*
* Write image into data set. The image will be divided into
* blocks as defined by steps. The target coordinates will be the
* image coordinates shifted by offset.
*/
public void writeImage(
RandomAccessibleInterval< UnsignedLongType > image,
final int iterationAxis,
final int[] steps,
final int[] offset,
UnsignedLongType borderExtension )
{
// realX ensures that realX[i] is integer multiple of blockSize
long[] realDim = new long[ image.numDimensions() ];
image.dimensions( realDim );
adaptToBlockSize( realDim, this.blockSize );
int[] realSteps = adaptToBlockSize( steps.clone(), this.blockSize );
int[] realOffset = adaptToBlockSize( offset.clone(), this.blockSize );
// For now, assume always that data is in [0,1,2] == "xyz" format.
// Do we need flexibility to allow for different orderings?
int[] dims = new int[ image.numDimensions() ];
for ( int d = 0; d < image.numDimensions(); ++d )
dims[ d ] = d;
// stepSize as long[], needed for BlockedInterval
long[] stepSize = new long[ image.numDimensions() ];
for ( int i = 0; i < stepSize.length; i++ )
stepSize[ i ] = realSteps[ i ];
// Create BlockedInterval that allows for flat iteration and intuitive
// hyperslicing.
// Go along iterationAxis and hyperslice, then iterate over each
// hyperslice.
BlockedInterval< UnsignedLongType > blockedImage = BlockedInterval.createZeroExtended( image, stepSize );
for ( int a = 0, aUnitIncrement = 0; a < image.dimension( iterationAxis ); ++aUnitIncrement, a += realSteps[ iterationAxis ] )
{
IntervalView< RandomAccessibleInterval< UnsignedLongType >> hs =
Views.hyperSlice( blockedImage, iterationAxis, aUnitIncrement );
Cursor< RandomAccessibleInterval< UnsignedLongType >> cursor = Views.flatIterable( hs ).cursor();
while ( cursor.hasNext() )
{
RandomAccessibleInterval< UnsignedLongType > block = cursor.next();
int[] localOffset = realOffset.clone();
localOffset[ iterationAxis ] = a;
for ( int i = 0, k = 0; i < localOffset.length; i++ )
{
if ( i == iterationAxis )
continue;
localOffset[ i ] += cursor.getIntPosition( k++ ) * stepSize[ i ];
}
try
{
this.writeBlock( block, dims, localOffset );
}
catch ( IOException e )
{
System.err.println( "Failed to write block: " + dataset.getRequestString( DatasetBlkLabel.getIntervalRequestString( image, realSteps ) ) );
e.printStackTrace();
}
}
}
return;
}
示例3: calculate
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Override
public ZernikeMoment calculate(final IterableInterval<T> ii) {
final double width2 = (ii.dimension(0) - 1) / 2.0;
final double height2 = (ii.dimension(1) - 1) / 2.0;
final double centerX = width2 + ii.min(0);
final double centerY = height2 + ii.min(1);
final double radius = Math.sqrt(width2 * width2 + height2 * height2);
// Compute pascal's triangle for binomal coefficients: d[x][y] equals (x
// over y)
final double[][] d = computePascalsTriangle(order);
// initialize zernike moment
final ZernikeMoment moment = initZernikeMoment(order, repetition, d);
// get the cursor of the iterable interval
final Cursor<? extends RealType<?>> cur = ii.localizingCursor();
// run over iterable interval
while (cur.hasNext()) {
cur.fwd();
// get 2d centered coordinates
final int x = (int) (cur.getIntPosition(0) - ii.min(0));
final int y = (int) (cur.getIntPosition(1) - ii.min(1));
final double xm = (x - centerX) / radius;
final double ym = (y - centerY) / radius;
final double r = Math.sqrt(xm * xm + ym * ym);
if (r <= 1 && cur.get().getRealDouble() != 0.0) {
// calculate theta for this position
final double theta = Math.atan2(xm, ym);
moment.getZm().add(multiplyExp(1, moment.getP().evaluate(r), theta, moment.getM()));
}
}
// normalization
normalize(moment.getZm(), moment.getN(), getNumberOfPixelsInUnitDisk(radius));
return moment;
}
示例4: calculate
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Override
public double[][] calculate(final IterableInterval<T> input) {
double[][] matrix = new double[nrGreyLevels][nrGreyLevels];
final Cursor<T> cursor = input.localizingCursor();
final Pair<T, T> minMax = minmax.calculate(input);
double localMin = minMax.getA().getRealDouble();
double localMax = minMax.getB().getRealDouble();
final int[][][] pixels = new int[(int) input.dimension(2)][(int) input
.dimension(1)][(int) input.dimension(0)];
final int minimumX = (int) input.min(0);
final int minimumY = (int) input.min(1);
final int minimumZ = (int) input.min(2);
final double diff = localMax - localMin;
while (cursor.hasNext()) {
cursor.fwd();
pixels[cursor.getIntPosition(2) - minimumZ][cursor
.getIntPosition(1) - minimumY][cursor
.getIntPosition(0) - minimumX] = (int) (((cursor
.get().getRealDouble() - localMin) / diff) * (nrGreyLevels - 1));
}
final double orientationAtX = orientation.getValueAtDim(0) * distance;
final double orientationAtY = orientation.getValueAtDim(1) * distance;
final double orientationAtZ = orientation.getValueAtDim(2) * distance;
int nrPairs = 0;
for (int z = 0; z < pixels.length; z++) {
for (int y = 0; y < pixels[z].length; y++) {
for (int x = 0; x < pixels[z][y].length; x++) {
// ignore pixels not in mask
if (pixels[z][y][x] == Integer.MAX_VALUE) {
continue;
}
// get second pixel
final int sx = (int) (x + orientationAtX);
final int sy = (int) (y + orientationAtY);
final int sz = (int) (z + orientationAtZ);
// second pixel in interval and mask
if (sx >= 0 && sy >= 0 && sz >= 0 && sz < pixels.length
&& sy < pixels[sz].length
&& sx < pixels[sz][sy].length
&& pixels[sz][sy][sx] != Integer.MAX_VALUE) {
matrix[pixels[z][y][x]][pixels[sz][sy][sx]]++;
nrPairs++;
}
}
}
}
// normalize matrix
if (nrPairs > 0) {
double divisor = 1.0 / nrPairs;
for (int row = 0; row < matrix.length; row++) {
for (int col = 0; col < matrix[row].length; col++) {
matrix[row][col] *= divisor;
}
}
}
return matrix;
}
示例5: calculate
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Override
public double[][] calculate(final IterableInterval<T> input) {
final double[][] output = new double[nrGreyLevels][nrGreyLevels];
final Cursor<? extends RealType<?>> cursor = input.localizingCursor();
final Pair<T, T> minMax = minmax.calculate(input);
final double localMin = minMax.getA().getRealDouble();
final double localMax = minMax.getB().getRealDouble();
final int[][] pixels = new int[(int) input.dimension(1)][(int) input
.dimension(0)];
for (int i = 0; i < pixels.length; i++) {
Arrays.fill(pixels[i], Integer.MAX_VALUE);
}
final int minimumX = (int) input.min(0);
final int minimumY = (int) input.min(1);
final double diff = localMax - localMin;
while (cursor.hasNext()) {
cursor.fwd();
final int bin = (int) (((cursor.get().getRealDouble() - localMin) / diff) *
(nrGreyLevels));
pixels[cursor.getIntPosition(1) - minimumY][cursor.getIntPosition(0) -
minimumX] = bin < nrGreyLevels - 1 ? bin : nrGreyLevels - 1;
}
int nrPairs = 0;
final int orientationAtX = orientation.getValueAtDim(0) * distance;
final int orientationAtY = orientation.getValueAtDim(1) * distance;
for (int y = 0; y < pixels.length; y++) {
for (int x = 0; x < pixels[y].length; x++) {
// ignore pixels not in mask
if (pixels[y][x] == Integer.MAX_VALUE) {
continue;
}
// // get second pixel
final int sx = x + orientationAtX;
final int sy = y + orientationAtY;
// second pixel in interval and mask
if (sx >= 0 && sy >= 0 && sy < pixels.length
&& sx < pixels[sy].length
&& pixels[sy][sx] != Integer.MAX_VALUE) {
output[pixels[y][x]][pixels[sy][sx]]++;
nrPairs++;
}
}
}
if (nrPairs > 0) {
double divisor = 1.0 / nrPairs;
for (int row = 0; row < output.length; row++) {
for (int col = 0; col < output[row].length; col++) {
output[row][col] *= divisor;
}
}
}
return output;
}
示例6: computeMaxProjection
import net.imglib2.Cursor; //导入方法依赖的package包/类
public static < S extends RealType< S > > Img< S > computeMaxProjection( final RandomAccessibleInterval< S > avgPSF, final ImgFactory< S > factory, int minDim )
{
final long[] dimensions = new long[ avgPSF.numDimensions() ];
avgPSF.dimensions( dimensions );
if ( minDim < 0 )
{
long minSize = dimensions[ 0 ];
minDim = 0;
for ( int d = 0; d < dimensions.length; ++d )
{
if ( avgPSF.dimension( d ) < minSize )
{
minSize = avgPSF.dimension( d );
minDim = d;
}
}
}
final long[] projDim = new long[ dimensions.length - 1 ];
int dim = 0;
long sizeProjection = 0;
// the new dimensions
for ( int d = 0; d < dimensions.length; ++d )
if ( d != minDim )
projDim[ dim++ ] = dimensions[ d ];
else
sizeProjection = dimensions[ d ];
final Img< S > proj = factory.create( projDim, Views.iterable( avgPSF ).firstElement() );
final RandomAccess< S > psfIterator = avgPSF.randomAccess();
final Cursor< S > projIterator = proj.localizingCursor();
final int[] tmp = new int[ avgPSF.numDimensions() ];
while ( projIterator.hasNext() )
{
projIterator.fwd();
dim = 0;
for ( int d = 0; d < dimensions.length; ++d )
if ( d != minDim )
tmp[ d ] = projIterator.getIntPosition( dim++ );
tmp[ minDim ] = -1;
double maxValue = -Double.MAX_VALUE;
psfIterator.setPosition( tmp );
for ( int i = 0; i < sizeProjection; ++i )
{
psfIterator.fwd( minDim );
final double value = psfIterator.get().getRealDouble();
if ( value > maxValue )
maxValue = value;
}
projIterator.get().setReal( maxValue );
}
return proj;
}