Java Code Examples for net.imglib2.Dimensions#dimension()
The following examples show how to use
net.imglib2.Dimensions#dimension() .
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: PainteraAlerts.java From paintera with GNU General Public License v2.0 | 5 votes |
private static int argMaxDim(final Dimensions dims) { long max = -1; int argMax = -1; for (int d = 0; d < dims.numDimensions(); ++d) { if (dims.dimension(d) > max) { max = dims.dimension(d); argMax = d; } } return argMax; }
Example 2
Source File: PainteraCommandLineArgs.java From paintera with GNU General Public License v2.0 | 5 votes |
private static int argMaxDim(final Dimensions dims) { long max = -1; int argMax = -1; for (int d = 0; d < dims.numDimensions(); ++d) { if (dims.dimension(d) > max) { max = dims.dimension(d); argMax = d; } } return argMax; }
Example 3
Source File: PhaseCorrelation2Util.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
/** * calculate the size difference of two Dimensions objects (dim2-dim1) * @param dim1 first Dimensions * @param dim2 second Dimensions * @return int array of difference */ public static int[] getSizeDifference(Dimensions dim1, Dimensions dim2) { int[] diff = new int[dim1.numDimensions()]; for (int i = 0; i < dim1.numDimensions(); i++){ diff[i] = (int) (dim2.dimension(i) - dim1.dimension(i)); } return diff; }
Example 4
Source File: PhaseCorrelation2Util.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
/** * calculate the size of an extended image big enough to hold dim1 and dim2 * with each dimension also enlarged by extension pixels on each side (but at most by the original image size) * @param dim1 first Dimensions * @param dim2 second Dimensions * @param extension: number of pixels to add at each side in each dimension * @return extended dimensions */ public static FinalDimensions getExtendedSize(Dimensions dim1, Dimensions dim2, int [] extension) { long[] extDims = new long[dim1.numDimensions()]; for (int i = 0; i <dim1.numDimensions(); i++){ extDims[i] = dim1.dimension(i) > dim2.dimension(i) ? dim1.dimension(i) : dim2.dimension(i); long extBothSides = extDims[i] < extension[i] ? extDims[i] * 2 : extension[i] * 2; extDims[i] += extBothSides; } return new FinalDimensions(extDims); }
Example 5
Source File: PhaseCorrelation2Util.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
public static int[] extensionByFactor(Dimensions dims, double extensionFactor){ int[] res = new int[dims.numDimensions()]; for (int i = 0; i< dims.numDimensions(); i++){ res[i] = (int) (dims.dimension(i)*extensionFactor); } return res; }
Example 6
Source File: LinkOverlay.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static void drawViewOutlines( final Graphics2D g, final Dimensions dims, final AffineTransform3D transfrom, final Color color ) { final int n = dims.numDimensions(); final Queue< List< Boolean > > worklist = new LinkedList<>(); // add 0,0,.. final List< Boolean > origin = new ArrayList<>(); for (int d = 0; d < n; d++) origin.add( false ); worklist.add( origin ); while ( worklist.size() > 0 ) { final List< Boolean > vertex1 = worklist.poll(); final List< List< Boolean > > neighbors = getHigherVertices( vertex1 ); worklist.addAll( neighbors ); for (final List<Boolean> vertex2 : neighbors) { final double[] v1Pos = new double[ n ]; final double[] v2Pos = new double[ n ]; for (int d = 0; d < n; d++) { // the outline goes from -0.5 to dimension(d) - 0.5 (compared to the actual range of (0, dim(d)-1)) // this is because BDV (correctly) draws pixels with center at pixel location v1Pos[d] = vertex1.get( d ) ? dims.dimension( d ) - 0.5 : -0.5; v2Pos[d] = vertex2.get( d ) ? dims.dimension( d ) - 0.5 : -0.5; } transfrom.apply( v1Pos, v1Pos ); transfrom.apply( v2Pos, v2Pos ); g.setColor( color ); g.setStroke( new BasicStroke( 1.0f ) ); g.drawLine((int) v1Pos[0],(int) v1Pos[1],(int) v2Pos[0],(int) v2Pos[1] ); } } }
Example 7
Source File: PhaseCorrelation2Util.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static List<PhaseCorrelationPeak2> expandPeakToPossibleShifts( PhaseCorrelationPeak2 peak, Dimensions pcmDims, Dimensions img1Dims, Dimensions img2Dims) { int n = pcmDims.numDimensions(); double[] subpixelDiff = new double[n]; if (peak.getSubpixelPcmLocation() != null) for (int i = 0; i < n; i++) subpixelDiff[i] = peak.getSubpixelPcmLocation().getDoublePosition( i ) - peak.getPcmLocation().getIntPosition( i ); int[] originalPCMPeakWithOffset = new int[n]; peak.getPcmLocation().localize(originalPCMPeakWithOffset); int[] extensionImg1 = getSizeDifference(img1Dims, pcmDims); int[] extensionImg2 = getSizeDifference(img2Dims, pcmDims); int[] offset = new int[pcmDims.numDimensions()]; for(int i = 0; i < offset.length; i++){ offset[i] = (extensionImg2[i] - extensionImg1[i] ) / 2; originalPCMPeakWithOffset[i] += offset[i]; originalPCMPeakWithOffset[i] %= pcmDims.dimension(i); } List<PhaseCorrelationPeak2> shiftedPeaks = new ArrayList<PhaseCorrelationPeak2>(); for (int i = 0; i < Math.pow(2, pcmDims.numDimensions()); i++){ int[] possibleShift = originalPCMPeakWithOffset.clone(); PhaseCorrelationPeak2 peakWithShift = new PhaseCorrelationPeak2(peak); for (int d = 0; d < pcmDims.numDimensions(); d++){ /* * mirror the shift around the origin in dimension d if (i / 2^d) is even * --> all possible shifts */ if ((i / (int) Math.pow(2, d) % 2) == 0){ possibleShift[d] = possibleShift[d] < 0 ? possibleShift[d] + (int) pcmDims.dimension(d) : possibleShift[d] - (int) pcmDims.dimension(d); } } peakWithShift.setShift(new Point(possibleShift)); if (peakWithShift.getSubpixelPcmLocation() != null) { double[] subpixelShift = new double[n]; for (int j =0; j<n;j++){ subpixelShift[j] = possibleShift[j] + subpixelDiff[j]; } peakWithShift.setSubpixelShift( new RealPoint( subpixelShift ) ); } shiftedPeaks.add(peakWithShift); } return shiftedPeaks; }
Example 8
Source File: PhaseCorrelation2Util.java From BigStitcher with GNU General Public License v2.0 | 4 votes |
public static Pair<Interval, Interval> getOverlapIntervals(Dimensions img1, Dimensions img2, Localizable shift){ final int numDimensions = img1.numDimensions(); final long[] offsetImage1 = new long[ numDimensions ]; final long[] offsetImage2 = new long[ numDimensions ]; final long[] maxImage1 = new long[ numDimensions ]; final long[] maxImage2 = new long[ numDimensions ]; long overlapSize; for ( int d = 0; d < numDimensions; ++d ) { if ( shift.getLongPosition(d) >= 0 ) { // two possiblities // // shift=start end // | | // A: Image 1 ------------------------------ // Image 2 ---------------------------------- // // shift=start end // | | // B: Image 1 ------------------------------ // Image 2 ------------------- // they are not overlapping ( this might happen due to fft zeropadding and extension ) if ( shift.getLongPosition(d) >= img1.dimension( d ) ) { return null; } offsetImage1[ d ] = shift.getLongPosition(d); offsetImage2[ d ] = 0; overlapSize = Math.min( img1.dimension( d ) - shift.getLongPosition(d), img2.dimension( d ) ); maxImage1[ d ] = offsetImage1[d] + overlapSize -1; maxImage2[ d ] = offsetImage2[d] + overlapSize -1; } else { // two possiblities // // shift start end // | | ` | // A: Image 1 ------------------------------ // Image 2 ------------------------------ // // shift start end // | | | // B: Image 1 ------------ // Image 2 ------------------- // they are not overlapping ( this might happen due to fft zeropadding and extension if ( shift.getLongPosition(d) <= -img2.dimension( d ) ) { return null; } offsetImage1[ d ] = 0; offsetImage2[ d ] = -shift.getLongPosition(d); overlapSize = Math.min( img2.dimension( d ) + shift.getLongPosition(d), img1.dimension( d ) ); maxImage1[ d ] = offsetImage1[d] + overlapSize -1; maxImage2[ d ] = offsetImage2[d] + overlapSize -1; } } FinalInterval img1Interval = new FinalInterval(offsetImage1, maxImage1); FinalInterval img2Interval = new FinalInterval(offsetImage2, maxImage2); Pair<Interval, Interval> res = new ValuePair<Interval, Interval>(img1Interval, img2Interval); return res; }
Example 9
Source File: GlobalOptimizationSubset.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
protected < M extends Model< M > > AffineTransform3D computeMapBackModel( final HashMap< ViewId, Tile< M > > tiles, final GlobalOptimizationType type, final SpimData2 spimData ) { final AbstractModel< ? > mapBackModel = type.getMapBackModel(); if ( mapBackModel.getMinNumMatches() > 4 ) { IOFunctions.println( "Cannot map back using a model that needs more than 4 points: " + mapBackModel.getClass().getSimpleName() ); return null; } else { IOFunctions.println( "Mapping back to reference frame using a " + mapBackModel.getClass().getSimpleName() ); final ViewId referenceTile = type.getMapBackReferenceTile( this ); final ViewDescription referenceTileViewDescription = spimData.getSequenceDescription().getViewDescription( referenceTile ); final ViewSetup referenceTileSetup = referenceTileViewDescription.getViewSetup(); Dimensions size = ViewSetupUtils.getSizeOrLoad( referenceTileSetup, referenceTileViewDescription.getTimePoint(), spimData.getSequenceDescription().getImgLoader() ); long w = size.dimension( 0 ); long h = size.dimension( 1 ); final double[][] p = new double[][]{ { 0, 0, 0 }, { w, 0, 0 }, { 0, h, 0 }, { w, h, 0 } }; // original coordinates == pa final double[][] pa = new double[ 4 ][ 3 ]; // map coordinates to the actual input coordinates final ViewRegistration inputModel = spimData.getViewRegistrations().getViewRegistration( referenceTile ); for ( int i = 0; i < p.length; ++i ) inputModel.getModel().apply( p[ i ], pa[ i ] ); final M outputModel = tiles.get( referenceTile ).getModel(); // transformed coordinates == pb final double[][] pb = new double[ 4 ][ 3 ]; for ( int i = 0; i < p.length; ++i ) pb[ i ] = outputModel.apply( pa[ i ] ); // compute the model that maps pb >> pa try { final ArrayList< PointMatch > pm = new ArrayList< PointMatch >(); for ( int i = 0; i < p.length; ++i ) pm.add( new PointMatch( new Point( pb[ i ] ), new Point( pa[ i ] ) ) ); mapBackModel.fit( pm ); } catch ( Exception e ) { IOFunctions.println( "Could not compute model for mapping back: " + e ); e.printStackTrace(); return null; } final AffineTransform3D mapBack = new AffineTransform3D(); final double[][] m = new double[ 3 ][ 4 ]; ((Affine3D<?>)mapBackModel).toMatrix( m ); mapBack.set( m[0][0], m[0][1], m[0][2], + m[0][3], m[1][0], m[1][1], m[1][2], m[1][3], m[2][0], m[2][1], m[2][2], m[2][3] ); IOFunctions.println( "Model for mapping back: " + mapBack + "\n" ); return mapBack; } }
Example 10
Source File: BoundingBoxGUI.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
/** * @param spimData * @param viewIdsToProcess * @param minBB * @param maxBB * @return - true if the SpimData object was modified, otherwise false */ public static boolean computeMaxBoundingBoxDimensions( final SpimData2 spimData, final List< ViewId > viewIdsToProcess, final double[] minBB, final double[] maxBB ) { for ( int d = 0; d < minBB.length; ++d ) { minBB[ d ] = Double.MAX_VALUE; maxBB[ d ] = -Double.MAX_VALUE; } boolean changed = false; IOFunctions.println( new Date( System.currentTimeMillis() ) + ": Estimating Bounding Box for Fusion. If size of images is not known (they were never opened before), some of them need to be opened once to determine their size."); for ( final ViewId viewId : viewIdsToProcess ) { final ViewDescription viewDescription = spimData.getSequenceDescription().getViewDescription( viewId.getTimePointId(), viewId.getViewSetupId() ); if ( !viewDescription.isPresent() ) continue; if ( !viewDescription.getViewSetup().hasSize() ) changed = true; final Dimensions size = ViewSetupUtils.getSizeOrLoad( viewDescription.getViewSetup(), viewDescription.getTimePoint(), spimData.getSequenceDescription().getImgLoader() ); final double[] min = new double[]{ 0, 0, 0 }; final double[] max = new double[]{ size.dimension( 0 ) - 1, size.dimension( 1 ) - 1, size.dimension( 2 ) - 1 }; final ViewRegistration r = spimData.getViewRegistrations().getViewRegistration( viewId ); r.updateModel(); final FinalRealInterval interval = r.getModel().estimateBounds( new FinalRealInterval( min, max ) ); for ( int d = 0; d < minBB.length; ++d ) { minBB[ d ] = Math.min( minBB[ d ], interval.realMin( d ) ); maxBB[ d ] = Math.max( maxBB[ d ], interval.realMax( d ) ); } } return changed; }
Example 11
Source File: MVDeconvolution.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
protected static Img< FloatType > loadInitialImage( final String fileName, final boolean checkNumbers, final float minValue, final Dimensions dimensions, final ImgFactory< FloatType > imageFactory ) { IOFunctions.println( "Loading image '" + fileName + "' as start for iteration." ); final ImagePlus impPSI = LegacyStackImgLoaderIJ.open( new File( fileName ) ); if ( impPSI == null ) { IOFunctions.println( "Could not load image '" + fileName + "'." ); return null; } final long[] dimPsi = impPSI.getStack().getSize() == 1 ? new long[]{ impPSI.getWidth(), impPSI.getHeight() } : new long[]{ impPSI.getWidth(), impPSI.getHeight(), impPSI.getStack().getSize() }; final Img< FloatType > psi = imageFactory.create( dimPsi, new FloatType() ); LegacyStackImgLoaderIJ.imagePlus2ImgLib2Img( impPSI, psi, false ); if ( psi == null ) { IOFunctions.println( "Could not load image '" + fileName + "'." ); return null; } else { boolean dimensionsMatch = true; final long dim[] = new long[ dimensions.numDimensions() ]; for ( int d = 0; d < psi.numDimensions(); ++d ) { if ( psi.dimension( d ) != dimensions.dimension( d ) ) dimensionsMatch = false; dim[ d ] = dimensions.dimension( d ); } if ( !dimensionsMatch ) { IOFunctions.println( "Dimensions of '" + fileName + "' do not match: " + Util.printCoordinates( dimPsi ) + " != " + Util.printCoordinates( dim ) ); return null; } if ( checkNumbers ) { IOFunctions.println( "Checking values of '" + fileName + "' you can disable this check by setting " + "spim.process.fusion.deconvolution.MVDeconvolution.checkNumbers = false;" ); boolean smaller = false; boolean hasZerosOrNeg = false; for ( final FloatType v : psi ) { if ( v.get() < minValue ) smaller = true; if ( v.get() <= 0 ) { hasZerosOrNeg = true; v.set( minValue ); } } if ( smaller ) IOFunctions.println( "Some values '" + fileName + "' are smaller than the minimal value of " + minValue + ", this can lead to instabilities." ); if ( hasZerosOrNeg ) IOFunctions.println( "Some values '" + fileName + "' were smaller or equal to zero," + "they have been replaced with the min value of " + minValue ); } } return psi; }