Java Code Examples for mpicbg.imglib.cursor.LocalizableByDimCursor#setPosition()
The following examples show how to use
mpicbg.imglib.cursor.LocalizableByDimCursor#setPosition() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Block.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
private static final void copy( final long start, final long loopSize, final Image< FloatType > source, final Image< FloatType > block, final int[] offset, final boolean inside, final OutOfBoundsStrategyFactory< FloatType > strategyFactory ) { final int numDimensions = source.getNumDimensions(); final LocalizableCursor<FloatType> cursor = block.createLocalizableCursor(); final LocalizableByDimCursor<FloatType> randomAccess; if ( inside ) randomAccess = source.createLocalizableByDimCursor(); else randomAccess = source.createLocalizableByDimCursor( strategyFactory ); cursor.fwd( start ); final int[] tmp = new int[ numDimensions ]; for ( long l = 0; l < loopSize; ++l ) { cursor.fwd(); cursor.getPosition( tmp ); for ( int d = 0; d < numDimensions; ++d ) tmp[ d ] += offset[ d ]; randomAccess.setPosition( tmp ); cursor.getType().set( randomAccess.getType() ); } }
Example 2
Source File: Block.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
private static final void paste( final long start, final long loopSize, final Image< FloatType > target, final Image< FloatType > block, final int[] effectiveOffset, final int[] effectiveSize, final int[] effectiveLocalOffset ) { final int numDimensions = target.getNumDimensions(); // iterate over effective size final LocalizableCursor<?> cursor = ArrayLocalizableCursor.createLinearCursor( effectiveSize ); // read from block final LocalizableByDimCursor<FloatType> blockRandomAccess = block.createLocalizableByDimCursor(); // write to target final LocalizableByDimCursor<FloatType> targetRandomAccess = target.createLocalizableByDimCursor(); cursor.fwd( start ); final int[] tmp = new int[ numDimensions ]; for ( long l = 0; l < loopSize; ++l ) { cursor.fwd(); cursor.getPosition( tmp ); // move to the relative local offset where the real data starts for ( int d = 0; d < numDimensions; ++d ) tmp[ d ] += effectiveLocalOffset[ d ]; blockRandomAccess.setPosition( tmp ); // move to the right position in the image for ( int d = 0; d < numDimensions; ++d ) tmp[ d ] += effectiveOffset[ d ] - effectiveLocalOffset[ d ]; targetRandomAccess.setPosition( tmp ); // write the pixel targetRandomAccess.getType().set( blockRandomAccess.getType() ); } }
Example 3
Source File: ExtractPSF.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
/** * Make image the same size as defined, center it * * @param img * @return */ public static Image< FloatType > makeSameSize( final Image< FloatType > img, final int[] sizeIn ) { final int[] size = sizeIn.clone(); float min = Float.MAX_VALUE; for ( final FloatType f : img ) min = Math.min( min, f.get() ); final Image< FloatType > square = img.createNewImage( size ); final LocalizableCursor< FloatType > squareCursor = square.createLocalizableCursor(); final LocalizableByDimCursor< FloatType > inputCursor = img.createLocalizableByDimCursor( new OutOfBoundsStrategyValueFactory<FloatType>( new FloatType( min ) ) ); while ( squareCursor.hasNext() ) { squareCursor.fwd(); squareCursor.getPosition( size ); for ( int d = 0; d < img.getNumDimensions(); ++d ) size[ d ] = size[ d ] - square.getDimension( d )/2 + img.getDimension( d )/2; inputCursor.setPosition( size ); squareCursor.getType().set( inputCursor.getType().get() ); } return square; }
Example 4
Source File: DOM.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
/** * Compute the average in the area * * @param fromX - start coordinate in x (exclusive in integral image coordinates, inclusive in image coordinates) * @param fromY - start coordinate in y (exclusive in integral image coordinates, inclusive in image coordinates) * @param fromZ - start coordinate in z (exclusive in integral image coordinates, inclusive in image coordinates) * @param vX - number of pixels in x * @param vY - number of pixels in y * @param vZ - number of pixels in z * @param randomAccess - randomAccess on the integral image * @return */ final public static long computeSum( final int fromX, final int fromY, final int fromZ, final int vX, final int vY, final int vZ, final LocalizableByDimCursor< LongType > randomAccess ) { randomAccess.setPosition( fromX, 0 ); randomAccess.setPosition( fromY, 1 ); randomAccess.setPosition( fromZ, 2 ); long sum = -randomAccess.getType().get(); randomAccess.move( vX, 0 ); sum += randomAccess.getType().get(); randomAccess.move( vY, 1 ); sum += -randomAccess.getType().get(); randomAccess.move( -vX, 0 ); sum += randomAccess.getType().get(); randomAccess.move( vZ, 2 ); sum += -randomAccess.getType().get(); randomAccess.move( vX, 0 ); sum += randomAccess.getType().get(); randomAccess.move( -vY, 1 ); sum += -randomAccess.getType().get(); randomAccess.move( -vX, 0 ); sum += randomAccess.getType().get(); return sum; }
Example 5
Source File: Block.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
private static final void copy3d( final int threadIdx, final int numThreads, final Image< FloatType > source, final Image< FloatType > block, final int[] offset, final boolean inside, final OutOfBoundsStrategyFactory< FloatType > strategyFactory ) { final int w = block.getDimension( 0 ); final int h = block.getDimension( 1 ); final int d = block.getDimension( 2 ); final int offsetX = offset[ 0 ]; final int offsetY = offset[ 1 ]; final int offsetZ = offset[ 2 ]; final float[] blockArray = ((FloatArray)((Array)block.getContainer()).update( null )).getCurrentStorageArray(); final LocalizableByDimCursor<FloatType> randomAccess; if ( inside ) randomAccess = source.createLocalizableByDimCursor(); else randomAccess = source.createLocalizableByDimCursor( strategyFactory ); final int[] tmp = new int[]{ offsetX, offsetY, 0 }; for ( int z = threadIdx; z < d; z += numThreads ) { tmp[ 2 ] = z + offsetZ; randomAccess.setPosition( tmp ); int i = z * h * w; for ( int y = 0; y < h; ++y ) { randomAccess.setPosition( offsetX, 0 ); for ( int x = 0; x < w; ++x ) { blockArray[ i++ ] = randomAccess.getType().get(); randomAccess.fwd( 0 ); } randomAccess.move( -w, 0 ); randomAccess.fwd( 1 ); } } }
Example 6
Source File: ExtractPSF.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
/** * Get projection along the smallest dimension (which is usually the rotation axis) * * @return - the averaged, projected PSF */ public Image< FloatType > getMaxProjectionAveragePSF() { final int[] dimensions = avgPSF.getDimensions(); int minSize = dimensions[ 0 ]; int minDim = 0; for ( int d = 0; d < dimensions.length; ++d ) { if ( avgPSF.getDimension( d ) < minSize ) { minSize = avgPSF.getDimension( d ); minDim = d; } } final int[] projDim = new int[ dimensions.length - 1 ]; int dim = 0; int 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 Image< FloatType > proj = avgPSF.getImageFactory().createImage( projDim ); final LocalizableByDimCursor< FloatType > psfIterator = avgPSF.createLocalizableByDimCursor(); final LocalizableCursor< FloatType > projIterator = proj.createLocalizableCursor(); final int[] tmp = new int[ avgPSF.getNumDimensions() ]; while ( projIterator.hasNext() ) { projIterator.fwd(); dim = 0; for ( int d = 0; d < dimensions.length; ++d ) if ( d != minDim ) tmp[ d ] = projIterator.getPosition( dim++ ); tmp[ minDim ] = -1; float maxValue = -Float.MAX_VALUE; psfIterator.setPosition( tmp ); for ( int i = 0; i < sizeProjection; ++i ) { psfIterator.fwd( minDim ); final float value = psfIterator.getType().get(); if ( value > maxValue ) maxValue = value; } projIterator.getType().set( maxValue ); } proj.setName( "MIP of PSF's of " + viewStructure.getID() ); return proj; }
Example 7
Source File: Entropy.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
public Entropy(final float stepSize, final Image<FloatType> img, final LocalizableByDimCursor<FloatType> cursor, final int histogramBins, final int windowSizeX, final int windowSizeY, final int windowSizeZ, int x, int y, int z) { absFreq = new int[histogramBins]; this.img = img; this.histogramBins = histogramBins; if (windowSizeX %2 == 0) this.windowSizeX = windowSizeX + 1; else this.windowSizeX = windowSizeX; if (windowSizeY %2 == 0) this.windowSizeY = windowSizeY + 1; else this.windowSizeY = windowSizeY; if (windowSizeZ %2 == 0) this.windowSizeZ = windowSizeZ + 1; else this.windowSizeZ = windowSizeZ; size = this.windowSizeX * this.windowSizeY * this.windowSizeZ; windowSizeXHalf = this.windowSizeX/2; windowSizeYHalf = this.windowSizeY/2; windowSizeZHalf = this.windowSizeZ/2; if (z - windowSizeZHalf >= 0 && z + windowSizeZHalf < img.getDimension( 2 ) ) outOfImageZ = false; else outOfImageZ = true; if (y - windowSizeYHalf >= 0 && y + windowSizeYHalf < img.getDimension( 1 ) ) outOfImageY = false; else outOfImageY = true; if (x - windowSizeXHalf >= 0 && x + windowSizeXHalf < img.getDimension( 0 ) ) outOfImageX = false; else outOfImageX = true; preComputed = preComputeProbabilities(stepSize); this.x = x; this.y = y; this.z = z; this.cursor = cursor; cursor.setPosition( new int[]{ x, y, z} ); }
Example 8
Source File: BinaryInterpolation2D.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
private final void setPosition(final LocalizableByDimCursor<?> c, final int x, final int y) { position[0] = x; position[1] = y; c.setPosition(position); }