Skip to content

Commit

Permalink
Merge branch 'master' into stepsize
Browse files Browse the repository at this point in the history
  • Loading branch information
StephanPreibisch authored Mar 5, 2024
2 parents a60939e + f2a7107 commit b5f66c6
Show file tree
Hide file tree
Showing 17 changed files with 118 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ protected ImagePlus getImagePlusForInteractive( final String dialogHeader )
RandomAccessibleInterval<RealType<?>> imgGeneric = DownsampleTools.openAndDownsample(
spimData.getSequenceDescription().getImgLoader(),
viewDescription,
new long[] { downsampleXY, downsampleXY, downsampleZ } ).getA();
new long[] { downsampleXY, downsampleXY, downsampleZ },
true ).getA();

if ( imgGeneric == null )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import ij.io.Opener;
import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription;
import mpicbg.spim.data.generic.sequence.BasicViewDescription;
import mpicbg.spim.data.generic.sequence.BasicViewSetup;
import mpicbg.spim.data.sequence.Channel;
import mpicbg.spim.data.sequence.ViewId;
import mpicbg.spim.data.sequence.VoxelDimensions;
Expand Down Expand Up @@ -98,9 +97,9 @@ public LegacyDHMImgLoader(
public RandomAccessibleInterval< FloatType > getFloatImage( final ViewId view, final boolean normalize )
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( view ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( view ) );
else
return ImgLib2Tools.convertVirtual( getImage( view ) );
return ImgLib2Tools.convertVirtualRAI( getImage( view ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import net.imglib2.IterableInterval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.img.ImgFactory;
import net.imglib2.img.array.ArrayImg;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
Expand Down Expand Up @@ -139,9 +138,9 @@ public LegacyFileMapImgLoaderLOCI(
public RandomAccessibleInterval< FloatType > getFloatImage(ViewId view, boolean normalize)
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( view ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( view ) );
else
return ImgLib2Tools.convertVirtual( getImage( view ) );
return ImgLib2Tools.convertVirtualRAI( getImage( view ) );
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public LegacyLightSheetZ1ImgLoader(
public RandomAccessibleInterval< FloatType > getFloatImage( final ViewId view, final boolean normalize )
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( view ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( view ) );
else
return ImgLib2Tools.convertVirtual( getImage( view ) );
return ImgLib2Tools.convertVirtualRAI( getImage( view ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ final public static < T extends RealType< T > & NativeType< T > > void populateI
public RandomAccessibleInterval< FloatType > getFloatImage( final ViewId view, final boolean normalize )
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( view ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( view ) );
else
return ImgLib2Tools.convertVirtual( getImage( view ) );
return ImgLib2Tools.convertVirtualRAI( getImage( view ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ public static ImagePlus open( File file )
public RandomAccessibleInterval< FloatType > getFloatImage( final ViewId view, final boolean normalize )
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( view ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( view ) );
else
return ImgLib2Tools.convertVirtual( getImage( view ) );
return ImgLib2Tools.convertVirtualRAI( getImage( view ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ public LegacyStackImgLoaderLOCI(
public RandomAccessibleInterval< FloatType > getFloatImage( final ViewId view, final boolean normalize )
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( view ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( view ) );
else
return ImgLib2Tools.convertVirtual( getImage( view ) );
return ImgLib2Tools.convertVirtualRAI( getImage( view ) );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ public SimViewSetupImgLoader(
public RandomAccessibleInterval<FloatType> getFloatImage( final int timepointId, final boolean normalize, ImgLoaderHint... hints )
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( timepointId, hints ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( timepointId, hints ) );
else
return ImgLib2Tools.convertVirtual( getImage( timepointId, hints ) );
return ImgLib2Tools.convertVirtualRAI( getImage( timepointId, hints ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,9 @@ public RandomAccessibleInterval< FloatType > getFloatImage(int timepointId, bool
ImgLoaderHint... hints)
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( timepointId, hints ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( timepointId, hints ) );
else
return ImgLib2Tools.convertVirtual( getImage( timepointId, hints ) );
return ImgLib2Tools.convertVirtualRAI( getImage( timepointId, hints ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public RandomAccessibleInterval< FloatType > getFloatImage( final int timepointI
// TODO: this is stupid, remove capablitity to get FloatType images!
if ( normalize )
{
return ImgLib2Tools.normalizeVirtual( img );
return ImgLib2Tools.normalizeVirtualRAI( img );
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public RandomAccessibleInterval< FloatType > getFloatImage( final int timepointI
// TODO: this is stupid, remove capablitity to get FloatType images!
if ( normalize )
{
return ImgLib2Tools.normalizeVirtual( img );
return ImgLib2Tools.normalizeVirtualRAI( img );
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ public UnsignedShortType getImageType()
public RandomAccessibleInterval< FloatType > getFloatImage( final int timepointId, final boolean normalize, final ImgLoaderHint... hints )
{
if ( normalize )
return ImgLib2Tools.normalizeVirtual( getImage( timepointId, hints ) );
return ImgLib2Tools.normalizeVirtualRAI( getImage( timepointId, hints ) );
else
return ImgLib2Tools.convertVirtual( getImage( timepointId, hints ) );
return ImgLib2Tools.convertVirtualRAI( getImage( timepointId, hints ) );
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,16 @@ protected boolean loadInterestPoints()
final RandomAccessibleInterval< DoubleType > locData = N5Utils.open( n5, locDataset );
final int n = (int)locData.dimension( 0 );

// empty list
if ( n == 0 )
{
this.interestPoints = new ArrayList<>();
modifiedInterestPoints = false;

n5.close();
return true;
}

final RandomAccess< UnsignedLongType > idRA = idData.randomAccess();
final RandomAccess< DoubleType > locRA = locData.randomAccess();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.util.LinAlgHelpers;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Pair;
import net.imglib2.util.Util;
import net.imglib2.util.ValuePair;
import net.imglib2.view.Views;
import net.preibisch.legacy.io.IOFunctions;
import net.preibisch.mvrecon.fiji.spimdata.interestpoints.InterestPoint;
import net.preibisch.mvrecon.process.downsampling.lazy.LazyDownsample2x;
import net.preibisch.mvrecon.process.interestpointdetection.methods.dog.DoGImgLib2;

public class DownsampleTools
{
Expand Down Expand Up @@ -382,7 +386,7 @@ public static AffineTransform3D getMipMapTransform(
{
final AffineTransform3D mmt = new AffineTransform3D();

openAndDownsample( imgLoader, vd, mmt, downsampleFactors, true );
openAndDownsample( imgLoader, vd, mmt, downsampleFactors, true, false );

return mmt;
}
Expand All @@ -394,17 +398,19 @@ public static AffineTransform3D getMipMapTransform(
* @param imgLoader the imgloader
* @param vd the view id
* @param downsampleFactors - specify which downsampling in each dimension (e.g. 1,2,4,8 )
* @param virtualDownsampling - use virtual downsampling if the requested downsamplefactors are not precomputed
* @return opened image and the mipmap transform
*/
@SuppressWarnings({ "rawtypes" })
public static Pair<RandomAccessibleInterval, AffineTransform3D> openAndDownsample(
final BasicImgLoader imgLoader,
final ViewId vd,
final long[] downsampleFactors )
final long[] downsampleFactors,
final boolean virtualDownsampling )
{
final AffineTransform3D mipMapTransform = new AffineTransform3D();

final RandomAccessibleInterval img = openAndDownsample(imgLoader, vd, mipMapTransform, downsampleFactors, false );
final RandomAccessibleInterval img = openAndDownsample(imgLoader, vd, mipMapTransform, downsampleFactors, false, virtualDownsampling );

return new ValuePair<RandomAccessibleInterval, AffineTransform3D>( img, mipMapTransform );
}
Expand All @@ -417,6 +423,7 @@ public static Pair<RandomAccessibleInterval, AffineTransform3D> openAndDownsampl
* @param vd the view id
* @param mipMapTransform - will be filled if downsampling is performed, otherwise identity transform
* @param downsampleFactors - specify which downsampling in each dimension (e.g. 1,2,4,8 )
* @param virtualDownsampling - use virtual downsampling if the requested downsamplefactors are not precomputed
* @param transformOnly - if true does not open any images but only provides the mipMapTransform (METHOD WILL RETURN NULL!)
* @return opened image
*/
Expand All @@ -426,14 +433,9 @@ private static RandomAccessibleInterval openAndDownsample(
final ViewId vd,
final AffineTransform3D mipMapTransform,
long[] downsampleFactors,
final boolean transformOnly ) // only for ImgLib1 legacy code
final boolean transformOnly, // only for ImgLib1 legacy code
final boolean virtualDownsampling )
{

//if ( !transformOnly )
// IOFunctions.println(
// "(" + new Date(System.currentTimeMillis()) + "): "
// + "Requesting Img from ImgLoader (tp=" + vd.getTimePointId() + ", setup=" + vd.getViewSetupId() + "), downsampling: " + Util.printCoordinates( downsampleFactors ) );

long dsx = downsampleFactors[0];
long dsy = downsampleFactors[1];
long dsz = (downsampleFactors.length > 2) ? downsampleFactors[ 2 ] : 1;
Expand Down Expand Up @@ -473,31 +475,14 @@ private static RandomAccessibleInterval openAndDownsample(

if ( !transformOnly )
{
//IOFunctions.println(
// "(" + new Date(System.currentTimeMillis()) + "): " +
// "Using precomputed Multiresolution Images [" + fx + "x" + fy + "x" + fz + "], " +
// "Remaining downsampling [" + dsx + "x" + dsy + "x" + dsz + "]" );

//if ( openAsFloat )
// input = ImgLib2Tools.convertVirtual( (RandomAccessibleInterval)mrImgLoader.getSetupImgLoader( vd.getViewSetupId() ).getImage( vd.getTimePointId(), bestLevel ) );
//else
input = mrImgLoader.getSetupImgLoader( vd.getViewSetupId() ).getImage( vd.getTimePointId(), bestLevel );
input = mrImgLoader.getSetupImgLoader( vd.getViewSetupId() ).getImage( vd.getTimePointId(), bestLevel );
}
}
else
{
if ( !transformOnly )
{
//IOFunctions.println(
// "(" + new Date(System.currentTimeMillis()) + "): " +
// "Using precomputed Multiresolution Images [1x1x1], " +
// "Remaining downsampling [" + dsx + "x" + dsy + "x" + dsz + "]" );

// we only need to do the complete opening when we do not perform additional downsampling below
//if ( openAsFloat )
// input = ImgLib2Tools.convertVirtual( (RandomAccessibleInterval)imgLoader.getSetupImgLoader( vd.getViewSetupId() ).getImage( vd.getTimePointId() ) );
//else
input = imgLoader.getSetupImgLoader( vd.getViewSetupId() ).getImage( vd.getTimePointId() );
input = imgLoader.getSetupImgLoader( vd.getViewSetupId() ).getImage( vd.getTimePointId() );
}

if ( mipMapTransform != null )
Expand All @@ -509,7 +494,7 @@ private static RandomAccessibleInterval openAndDownsample(
// the additional downsampling (performed below)
final AffineTransform3D additonalDS = new AffineTransform3D();
additonalDS.set( dsx, 0.0, 0.0, 0.0, 0.0, dsy, 0.0, 0.0, 0.0, 0.0, dsz, 0.0 );

// we need to concatenate since when correcting for the downsampling we first multiply by whatever
// the manual downsampling did, and just then by the scaling+offset of the HDF5
//
Expand All @@ -522,15 +507,29 @@ private static RandomAccessibleInterval openAndDownsample(

if ( !transformOnly )
{
// note: every pixel is read exactly once, therefore caching the virtual input would not give any advantages
for ( ;dsx > 1; dsx /= 2 )
input = Downsample.simple2x( input, new boolean[]{ true, false, false } );
if ( virtualDownsampling )
{
for ( ;dsx > 1; dsx /= 2 )
input = LazyDownsample2x.init( Views.extendBorder( input ), input, new FloatType(), DoGImgLib2.blockSize, 0 );

for ( ;dsy > 1; dsy /= 2 )
input = Downsample.simple2x( input, new boolean[]{ false, true, false } );
for ( ;dsy > 1; dsy /= 2 )
input = LazyDownsample2x.init( Views.extendBorder( input ), input, new FloatType(), DoGImgLib2.blockSize, 1 );

for ( ;dsz > 1; dsz /= 2 )
input = Downsample.simple2x( input, new boolean[]{ false, false, true } );
for ( ;dsz > 1; dsz /= 2 )
input = LazyDownsample2x.init( Views.extendBorder( input ), input, new FloatType(), DoGImgLib2.blockSize, 2 );
}
else
{
// note: every pixel is read exactly once, therefore caching the virtual input would not give any advantages
for ( ;dsx > 1; dsx /= 2 )
input = Downsample.simple2x( input, new boolean[]{ true, false, false } );

for ( ;dsy > 1; dsy /= 2 )
input = Downsample.simple2x( input, new boolean[]{ false, true, false } );

for ( ;dsz > 1; dsz /= 2 )
input = Downsample.simple2x( input, new boolean[]{ false, false, true } );
}
}

return input;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import ij.IJ;
import mpicbg.spim.data.sequence.ViewDescription;
import mpicbg.spim.data.sequence.ViewId;
import net.imglib2.FinalInterval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.realtransform.AffineTransform3D;
import net.imglib2.type.NativeType;
Expand Down Expand Up @@ -60,7 +61,7 @@ public static HashMap< ViewId, List< InterestPoint >> findInterestPoints( final
return interestPoints;
}

/**
/*
* finds all interest points and returns them as InterestPoints (which is a mpicbg Point and implements RealLocalizable),
* by default returns world coordinates
*
Expand Down Expand Up @@ -92,8 +93,9 @@ public static < T extends RealType< T > & NativeType< T > > List< InterestPoint
// compute Difference-of-Gaussian (includes normalization)
//
List< InterestPoint > ips = DoGImgLib2.computeDoG(
Views.zeroMin( input ),
Views.extendMirrorSingle( Views.zeroMin( input ) ),
null,
new FinalInterval( Views.zeroMin( input ) ),
sigma,
threshold,
1, // 0 = no subpixel localization, 1 = quadratic fit
Expand Down Expand Up @@ -140,18 +142,19 @@ public static void addInterestPoints( final HashMap< ViewId, List< InterestPoint

final ExecutorService service = Threads.createFixedExecutorService( Threads.numThreads() );

// TODO: downsampling is not virtual!
// downsampling is not virtual!
@SuppressWarnings({"rawtypes" })
final Pair<RandomAccessibleInterval, AffineTransform3D> input =
DownsampleTools.openAndDownsample(
dog.imgloader,
vd,
new long[] { dog.downsampleXY, dog.downsampleXY, dog.downsampleZ } );
new long[] { dog.downsampleXY, dog.downsampleXY, dog.downsampleZ },
false );

@SuppressWarnings("unchecked")
List< InterestPoint > ips = DoGImgLib2.computeDoG(
input.getA(),
Views.extendMirrorSingle( input.getA() ),
null, // mask
new FinalInterval( input.getA() ),
dog.sigma,
dog.threshold,
dog.localization,
Expand Down
Loading

0 comments on commit b5f66c6

Please sign in to comment.