本文整理汇总了Java中net.imglib2.Cursor.localize方法的典型用法代码示例。如果您正苦于以下问题:Java Cursor.localize方法的具体用法?Java Cursor.localize怎么用?Java Cursor.localize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.imglib2.Cursor
的用法示例。
在下文中一共展示了Cursor.localize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: testIntegralHistogram2d
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Test
public <R extends IntegerType<R> & NativeType<R>> void testIntegralHistogram2d() {
// Create a 2d image with values 0-9 in every dimension, so bottom right is 81.
Img<UnsignedByteType> img =
new UnsignedByteType().createSuitableNativeImg(
new ArrayImgFactory<UnsignedByteType>(),
new long[]{10, 10});
long[] p = new long[2];
Cursor<UnsignedByteType> c = img.cursor();
while (c.hasNext()) {
c.fwd();
c.localize(p);
c.get().setInteger(p[0] * p[1]);
}
// Create integral histogram with 10 bins
LinearHistogram<UnsignedByteType> lh = new LinearHistogram<UnsignedByteType>(10, 2, new UnsignedByteType(0), new UnsignedByteType(81));
Img<R> ih = IntegralHistogram.create(img, lh);
new ImageJ();
try {
ImgLib.wrap((Img)ih, "histogram").show();
} catch (ImgLibException e) {
e.printStackTrace();
}
}
示例3: moment1
import net.imglib2.Cursor; //导入方法依赖的package包/类
public static <T extends RealType<T>> double[] moment1( IterableInterval<T> img ){
logger.debug("moments 1 all ");
int nd = img.numDimensions();
double[] mom = new double[nd];
double[] loc = new double[nd];
Cursor<T> lc = img.localizingCursor();
while(lc.hasNext()){
lc.next();
lc.localize(loc);
for(int d=0; d<nd; d++){
mom[d] += loc[d] * lc.get().getRealDouble();
}
}
logger.debug("result: " + ArrayUtil.printArray(mom));
return mom;
}
示例4: createCheckerImg
import net.imglib2.Cursor; //导入方法依赖的package包/类
public static <T extends NativeType<T> & RealType<T>> Img<T> createCheckerImg(int[] sz, T t, int numLevels ){
if( numLevels < 2 )
{
logger.error("a checkered image can only be created with two or more levels - returning null");
return null;
}
ArrayImgFactory<T> factory = new ArrayImgFactory<T>();
Img<T> out = factory.create( sz, t);
Cursor<T> c = out.cursor();
int[] pos = new int[sz.length];
while ( c.hasNext() )
{
c.fwd();
c.localize(pos);
int sum = ArrayUtil.sum(pos);
c.get().setReal(
( sum % numLevels)
);
}
return out;
}
示例5: createGradientImg
import net.imglib2.Cursor; //导入方法依赖的package包/类
public static <T extends NativeType<T> & RealType<T>> Img<T> createGradientImg(int[] sz, double[] w, T t){
ArrayImgFactory<T> factory = new ArrayImgFactory<T>();
Img<T> out = factory.create( sz, t);
Cursor<T> c = out.localizingCursor();
int[] pos = new int[3];
while(c.hasNext()){
T val = c.next();
c.localize(pos);
double[] res = ArrayUtil.multiply( w , ArrayUtil.toDouble(pos));
val.setReal(
ArrayUtil.sum(res)
);
}
return out;
}
示例6: calculate
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Override
public RealLocalizable calculate(final IterableInterval<?> input) {
int numDimensions = input.numDimensions();
double[] output = new double[numDimensions];
Cursor<?> c = input.localizingCursor();
double[] pos = new double[numDimensions];
while (c.hasNext()) {
c.fwd();
c.localize(pos);
for (int i = 0; i < output.length; i++) {
output[i] += pos[i];
}
}
for (int i = 0; i < output.length; i++) {
output[i] = output[i] / input.size();
}
return new RealPoint(output);
}
示例7: createProbabilityImage
import net.imglib2.Cursor; //导入方法依赖的package包/类
private void createProbabilityImage(final int classCount,
final float[][] probValues, final int patchHeight, final int patchWidth)
{
final int patchesInX = (int) originalImage.dimension(0) / patchWidth;
final int patchesInY = (int) originalImage.dimension(1) / patchHeight;
// Create probability image.
final long width = patchWidth * patchesInX;
final long height = patchHeight * patchesInY;
final long[] dims = { width, height, classCount };
final AxisType[] axes = { Axes.X, Axes.Y, Axes.CHANNEL };
final FloatType type = new FloatType();
probDataset = datasetService.create(type, dims, "Probabilities", axes,
false);
// Set the probability image to grayscale.
probDataset.initializeColorTables(classCount);
for (int c = 0; c < classCount; c++) {
probDataset.setColorTable(ColorTables.GRAYS, c);
}
// Populate the probability image's sample values.
final ImgPlus<FloatType> probImg = probDataset.typedImg(type);
final Cursor<FloatType> cursor = probImg.localizingCursor();
final int[] pos = new int[dims.length];
while (cursor.hasNext()) {
cursor.next();
cursor.localize(pos);
final int x = pos[0], y = pos[1], c = pos[2];
final int patchIndexX = x / patchWidth, patchIndexY = y / patchHeight;
final int p = patchesInX * patchIndexY + patchIndexX;
cursor.get().set(probValues[p][c]);
}
}
示例8: populate1
import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
* Integral histogram of a 1d {@link Img}.
*
* @param integralHistogram
* @param img
* @param nBins
*/
static private final <T extends RealType<T>, R extends RealType<R> & NativeType<R>> void populate1(
final Img<R> integralHistogram,
final Img<T> img,
final Histogram<T> histogram)
{
final Cursor<T> c = img.cursor();
final RandomAccess<R> rh = integralHistogram.randomAccess();
final long[] position = new long[ integralHistogram.numDimensions() ];
// 1. For each pixel in the original image, add 1 to its corresponding bin in the histogram at that pixel
while (c.hasNext()) {
c.fwd();
c.localize(position);
// Compute the bin to add to
// (First element is empty in the integral, so displace by 1)
position[0] += 1;
position[1] = histogram.computeBin(c.get());
rh.setPosition(position);
rh.get().inc();
}
// 2. Integrate the histograms
final R sum = integralHistogram.firstElement().createVariable();
// Start at 1; first value is the one extra and always zero
// For every bin of the histogram:
for (long bin = 0; bin < integralHistogram.dimension(1); ++bin) {
rh.setPosition(bin, 1);
sum.setZero();
// For every value in the original image
for (long pos0 = 1; pos0 < integralHistogram.dimension(0); ++pos0) {
rh.setPosition(pos0, 0);
sum.add(rh.get());
rh.get().set(sum);
}
}
}
示例9: createGradientImgY
import net.imglib2.Cursor; //导入方法依赖的package包/类
public static <T extends NativeType<T> & RealType<T>> Img<T> createGradientImgY( int[] sz, T t){
ArrayImgFactory<T> factory = new ArrayImgFactory<T>();
Img<T> out = factory.create(sz, t);
Cursor<T> c = out.localizingCursor();
int[] pos = new int[3];
while(c.hasNext()){
T val = c.next();
c.localize(pos);
val.setReal(pos[1]);
}
return out;
}
示例10: createMask
import net.imglib2.Cursor; //导入方法依赖的package包/类
/**
* Create a new mask image with a defined size and preset content.
* @throws MissingPreconditionException
*/
public static RandomAccessibleInterval<BitType> createMask(long[] dim, long[] roiOffset, long[] roiDim)
throws MissingPreconditionException {
if (dim.length != roiOffset.length || dim.length != roiDim.length) {
throw new MissingPreconditionException("The dimensions of the mask as well as the ROIs and his offset must be the same.");
}
final RandomAccessibleInterval<BitType> mask = createMask(dim);
final int dims = mask.numDimensions();
final long[] pos = new long[dims];
// create an array with the max corner of the ROI
final long[] roiOffsetMax = new long[dims];
for (int i=0; i<dims; ++i)
roiOffsetMax[i] = roiOffset[i] + roiDim[i];
// go through the mask and mask points as valid that are in the ROI
Cursor<BitType> cursor = Views.iterable(mask).localizingCursor();
while ( cursor.hasNext() ) {
cursor.fwd();
cursor.localize(pos);
boolean valid = true;
// test if the current position is contained in the ROI
for(int i=0; i<dims; ++i)
valid &= pos[i] >= roiOffset[i] && pos[i] < roiOffsetMax[i];
cursor.get().set(valid);
}
return mask;
}
示例11: loop
import net.imglib2.Cursor; //导入方法依赖的package包/类
private static final void loop(
final Cursor< FloatType > cursor,
final Cursor< FloatType > cursorW,
final RealRandomAccess< FloatType > ir,
final RealRandomAccess< FloatType > wr,
final AffineTransform3D transform,
final float[] s, final float[] t,
final int offsetX, final int offsetY, final int offsetZ,
final int imgSizeX, final int imgSizeY, final int imgSizeZ )
{
// move img cursor forward any get the value (saves one access)
final FloatType v = cursor.next();
cursor.localize( s );
// move weight cursor forward and get the value
final FloatType w = cursorW.next();
s[ 0 ] += offsetX;
s[ 1 ] += offsetY;
s[ 2 ] += offsetZ;
transform.applyInverse( t, s );
if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizeX, imgSizeY, imgSizeZ ) )
{
ir.setPosition( t );
// do not accept 0 values in the data where image data is present, 0 means no image data is available
// (used in MVDeconvolution.computeQuotient)
v.set( Math.max( MVDeconvolution.minValue, ir.get().get() ) );
}
// compute weights in any case (the border can be negative!)
wr.setPosition( t );
w.set( wr.get() );
}
示例12: loop
import net.imglib2.Cursor; //导入方法依赖的package包/类
private static final void loop(
final Cursor< FloatType > cursor,
final RealRandomAccess< FloatType > ir,
final AffineTransform3D transform,
final float[] s, final float[] t,
final int offsetX, final int offsetY, final int offsetZ,
final int imgSizeX, final int imgSizeY, final int imgSizeZ )
{
// move img cursor forward any get the value (saves one access)
final FloatType v = cursor.next();
cursor.localize( s );
s[ 0 ] += offsetX;
s[ 1 ] += offsetY;
s[ 2 ] += offsetZ;
transform.applyInverse( t, s );
if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizeX, imgSizeY, imgSizeZ ) )
{
ir.setPosition( t );
// do not accept 0 values in the data where image data is present, 0 means no image data is available
// (used in MVDeconvolution.computeQuotient)
v.set( Math.max( MVDeconvolution.minValue, ir.get().get() ) );
}
}
示例13: printCoordNonZero
import net.imglib2.Cursor; //导入方法依赖的package包/类
public static <S extends RealType<S>> void printCoordNonZero(Img<S> img){
Cursor<S> c = img.cursor();
int num = 0;
int[] pos = new int[img.numDimensions()];
while(c.hasNext()){
S val = c.next();
if( val.getRealDouble() != 0 ){
c.localize(pos);
System.out.println(" val of : " + val + " at: " + ArrayUtil.printArray(pos));
num++;
}
}
System.out.println(img + " nnz: " + num );
}
示例14: toIntArray3d
import net.imglib2.Cursor; //导入方法依赖的package包/类
public static <T extends RealType<T>> int[][][] toIntArray3d(Img<T> img){
int[][][] out = new int[(int)img.dimension(0)][(int)img.dimension(1)][(int)img.dimension(2)];
Cursor<T> cursor = img.localizingCursor();
int[] pos = new int[3];
while(cursor.hasNext()){
cursor.fwd();
cursor.localize(pos);
out[pos[0]][pos[1]][pos[2]] = (int)(cursor.get().getRealDouble());
}
return out;
}
示例15: call
import net.imglib2.Cursor; //导入方法依赖的package包/类
@Override
public String call() throws Exception
{
final int numViews = imgs.size();
// make the interpolators and get the transformations
final ArrayList< RealRandomAccess< T > > interpolators = new ArrayList< RealRandomAccess< T > >( numViews );
final int[][] imgSizes = new int[ numViews ][ 3 ];
for ( int i = 0; i < numViews; ++i )
{
final RandomAccessibleInterval< T > img = imgs.get( i );
imgSizes[ i ] = new int[]{ (int)img.dimension( 0 ), (int)img.dimension( 1 ), (int)img.dimension( 2 ) };
interpolators.add( Views.interpolate( Views.extendMirrorSingle( img ), interpolatorFactory ).realRandomAccess() );
}
final Cursor< T > cursor = fusedImg.localizingCursor();
final Cursor< FloatType > cursorW = weightImg.cursor();
final float[] s = new float[ 3 ];
final float[] t = new float[ 3 ];
cursor.jumpFwd( portion.getStartPosition() );
cursorW.jumpFwd( portion.getStartPosition() );
for ( int j = 0; j < portion.getLoopSize(); ++j )
{
// move img cursor forward any get the value (saves one access)
final T v = cursor.next();
cursor.localize( s );
// move weight cursor forward and get the value
final FloatType w = cursorW.next();
if ( doDownSampling )
{
s[ 0 ] *= downSampling;
s[ 1 ] *= downSampling;
s[ 2 ] *= downSampling;
}
s[ 0 ] += bb.min( 0 );
s[ 1 ] += bb.min( 1 );
s[ 2 ] += bb.min( 2 );
double sum = 0;
int sumW = 0;
for ( int i = 0; i < numViews; ++i )
{
transforms[ i ].applyInverse( t, s );
if ( FusionHelper.intersects( t[ 0 ], t[ 1 ], t[ 2 ], imgSizes[ i ][ 0 ], imgSizes[ i ][ 1 ], imgSizes[ i ][ 2 ] ) )
{
final RealRandomAccess< T > r = interpolators.get( i );
r.setPosition( t );
sum += r.get().getRealDouble();
++sumW;
}
}
if ( sumW > 0 )
{
v.setReal( v.getRealFloat() + sum );
w.set( w.get() + sumW );
}
}
return portion + " finished successfully (no weights).";
}