Skip to content

Commit

Permalink
Merge pull request #59 from PreibischLab/blk-affine-fusion
Browse files Browse the repository at this point in the history
Use new BlockSupplier API for AffineFusion
  • Loading branch information
StephanPreibisch authored Sep 30, 2024
2 parents 49c5389 + ec107fe commit bc05b8e
Show file tree
Hide file tree
Showing 13 changed files with 1,469 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public interface MultiViewDatasetDefinition
* save it as an XML file.
*
* @param xmlFileName - the filename of the XML that was selected (no path!)
* @return - the saved {@link SpimData} object
* @return - the saved {@link SpimData2} object
*/
public SpimData2 createDataset( final String xmlFileName );

Expand Down
19 changes: 4 additions & 15 deletions src/main/java/net/preibisch/mvrecon/fiji/plugin/Image_Fusion.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import net.preibisch.mvrecon.process.export.Calibrateable;
import net.preibisch.mvrecon.process.export.ImgExport;
import net.preibisch.mvrecon.process.fusion.FusionTools;
import net.preibisch.mvrecon.process.fusion.blk.BlkAffineFusion;
import net.preibisch.mvrecon.process.fusion.lazy.LazyAffineFusion;
import net.preibisch.mvrecon.process.fusion.lazy.LazyNonRigidFusion;
import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual;
Expand Down Expand Up @@ -245,7 +246,9 @@ else if ( fusion.getPixelType() == 1 )
}
else
{
lazy = LazyAffineFusion.init(
System.out.println( "Image_Fusion.fuse" );
// lazy = LazyAffineFusion.init(
lazy = BlkAffineFusion.init(
conv,
spimData.getSequenceDescription().getImgLoader(),
group.getViews(),
Expand All @@ -257,20 +260,6 @@ else if ( fusion.getPixelType() == 1 )
fusion.getBoundingBox(),
(RealType & NativeType)type,
blocksize );

// TODO: replace with LazyAffineFusion and varying blocksizes depending on the task
/*
virtual = FusionTools.fuseVirtual(
spimData.getSequenceDescription().getImgLoader(),
registrations,
spimData.getSequenceDescription().getViewDescriptions(),
group.getViews(),
fusion.useBlending(),
fusion.useContentBased(),
fusion.getInterpolation(),
fusion.getBoundingBox(),
fusion.adjustIntensities() ? spimData.getIntensityAdjustments().getIntensityAdjustments() : null );
*/
}

final String title = getTitle( fusion.getSplittingType(), group );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ else if ( storageType == StorageFormat.HDF5 )
bb.dimensionsAsLongArray(),
compression,
blocksize(),
this.downsampling,
this.downsampling == null ? new int[][] {{1,1,1}} : this.downsampling,
viewId,
path,
xmlOut,
Expand Down
56 changes: 18 additions & 38 deletions src/main/java/net/preibisch/mvrecon/process/fusion/FusionTools.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.generic.sequence.BasicImgLoader;
import mpicbg.spim.data.generic.sequence.BasicViewDescription;
import mpicbg.spim.data.generic.sequence.BasicViewSetup;
import mpicbg.spim.data.registration.ViewRegistration;
import mpicbg.spim.data.sequence.Angle;
import mpicbg.spim.data.sequence.Channel;
Expand All @@ -64,15 +63,19 @@
import net.imglib2.IterableInterval;
import net.imglib2.RandomAccess;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.cache.img.CellLoader;
import net.imglib2.cache.CacheLoader;
import net.imglib2.cache.img.RandomAccessibleCacheLoader;
import net.imglib2.cache.img.ReadOnlyCachedCellImgFactory;
import net.imglib2.cache.img.ReadOnlyCachedCellImgOptions;
import net.imglib2.cache.img.SingleCellArrayImg;
import net.imglib2.cache.img.optional.CacheOptions.CacheType;
import net.imglib2.converter.Converters;
import net.imglib2.converter.RealTypeConverters;
import net.imglib2.img.Img;
import net.imglib2.img.ImgFactory;
import net.imglib2.img.basictypeaccess.AccessFlags;
import net.imglib2.img.basictypeaccess.array.ArrayDataAccess;
import net.imglib2.img.cell.Cell;
import net.imglib2.img.cell.CellGrid;
import net.imglib2.img.imageplus.ImagePlusImgFactory;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.NativeType;
Expand Down Expand Up @@ -783,49 +786,26 @@ public static < T extends NativeType< T > > RandomAccessibleInterval< T > cacheR
return cacheRandomAccessibleInterval( input, -1, type, cellDim );
}

public static < T extends NativeType< T > > RandomAccessibleInterval< T > cacheRandomAccessibleInterval(
public static < T extends NativeType< T >, A extends ArrayDataAccess< A > > RandomAccessibleInterval< T > cacheRandomAccessibleInterval(
final RandomAccessibleInterval< T > input,
final long maxCacheSize,
final T type,
final int... cellDim )
{
final RandomAccessibleInterval< T > in;

if ( Views.isZeroMin( input ) )
in = input;
else
in = Views.zeroMin( input );

final ReadOnlyCachedCellImgOptions options;

if ( maxCacheSize > 0 )
options = new ReadOnlyCachedCellImgOptions().cellDimensions( cellDim ).maxCacheSize( maxCacheSize );
else
options = new ReadOnlyCachedCellImgOptions().cellDimensions( cellDim ).cacheType( CacheType.SOFTREF );

final ReadOnlyCachedCellImgOptions options = ReadOnlyCachedCellImgOptions.options()
.cellDimensions( cellDim )
.cacheType( maxCacheSize > 0 ? CacheType.BOUNDED : CacheType.SOFTREF )
.maxCacheSize( maxCacheSize );
final ReadOnlyCachedCellImgFactory factory = new ReadOnlyCachedCellImgFactory( options );

final CellLoader< T > loader = new CellLoader< T >()
{
@Override
public void load( final SingleCellArrayImg< T, ? > cell ) throws Exception
{
final Cursor< T > cursor = cell.localizingCursor();
final RandomAccess< T > ra = in.randomAccess();

while( cursor.hasNext() )
{
cursor.fwd();
ra.setPosition( cursor );
cursor.get().set( ra.get() );
}
}
};

final long[] dim = new long[ in.numDimensions() ];
in.dimensions( dim );
final long[] dim = input.dimensionsAsLongArray();
final CacheLoader< Long, Cell< A > > loader = RandomAccessibleCacheLoader.get(
new CellGrid( dim, cellDim ),
input.view().zeroMin(),
AccessFlags.setOf( AccessFlags.VOLATILE ) );
final RandomAccessibleInterval<T> copy = factory.createWithCacheLoader( dim, type, loader );

return translateIfNecessary( input, factory.create( dim, type, loader ) );
return translateIfNecessary( input, copy );
}

public static < T extends Type< T > > RandomAccessibleInterval< T > copyImg( final RandomAccessibleInterval< T > input, final ImgFactory< T > factory, final T type, final ExecutorService service )
Expand Down
Loading

0 comments on commit bc05b8e

Please sign in to comment.