Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make downsampling method configurable #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,8 @@
.settings
/target
/samples

# IntelliJ
.idea/
*.iml

1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
<dependency>
<groupId>sc.fiji</groupId>
<artifactId>bigdataviewer-core</artifactId>
<version>10.2.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.imagej</groupId>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/bdv/ij/ExportImagePlusAsN5PlugIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public class ExportImagePlusAsN5PlugIn implements Command
public static void main( final String[] args )
{
new ImageJ();
final ImagePlus imp = IJ.openImage( "/Users/pietzsch/workspace/data/confocal-series.tif" );
imp.show();
IJ.run("Confocal Series (2.2MB)");
//final ImagePlus imp = IJ.openImage( "/Users/tischer/Desktop/Desktop/mri-stack-big.tif" );
//imp.show();
new ExportImagePlusAsN5PlugIn().run();
}

Expand Down
27 changes: 17 additions & 10 deletions src/main/java/bdv/ij/ExportImagePlusPlugIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.HashMap;
import java.util.Map;

import bdv.export.*;
import net.imglib2.FinalDimensions;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.realtransform.AffineTransform3D;
Expand All @@ -39,13 +40,8 @@
import org.scijava.command.Command;
import org.scijava.plugin.Plugin;

import bdv.export.ExportMipmapInfo;
import bdv.export.ExportScalePyramid.AfterEachPlane;
import bdv.export.ExportScalePyramid.LoopbackHeuristic;
import bdv.export.ProgressWriter;
import bdv.export.ProposeMipmaps;
import bdv.export.SubTaskProgressWriter;
import bdv.export.WriteSequenceToHdf5;
import bdv.ij.export.imgloader.ImagePlusImgLoader;
import bdv.ij.export.imgloader.ImagePlusImgLoader.MinMaxOption;
import bdv.ij.util.PluginHelper;
Expand Down Expand Up @@ -82,7 +78,10 @@ public class ExportImagePlusPlugIn implements Command
public static void main( final String[] args )
{
new ImageJ();
IJ.run("Confocal Series (2.2MB)");
//IJ.run("Confocal Series (2.2MB)");
final ImagePlus imp = IJ.openImage( "/Users/tischer/Desktop/Desktop/labels-3d-test.tif" );
imp.show();

new ExportImagePlusPlugIn().run();
}

Expand Down Expand Up @@ -243,14 +242,14 @@ public void afterEachPlane( final boolean usedLoopBack )
{
final Partition partition = partitions.get( i );
final ProgressWriter p = new SubTaskProgressWriter( progressWriter, 0, 0.95 * i / partitions.size() );
WriteSequenceToHdf5.writeHdf5PartitionFile( seq, perSetupExportMipmapInfo, params.deflate, partition, loopbackHeuristic, afterEachPlane, numCellCreatorThreads, p );
WriteSequenceToHdf5.writeHdf5PartitionFile( seq, perSetupExportMipmapInfo, params.downsamplingMethod, params.deflate, partition, loopbackHeuristic, afterEachPlane, numCellCreatorThreads, p );
}
WriteSequenceToHdf5.writeHdf5PartitionLinkFile( seq, perSetupExportMipmapInfo, partitions, params.hdf5File );
}
else
{
partitions = null;
WriteSequenceToHdf5.writeHdf5File( seq, perSetupExportMipmapInfo, params.deflate, params.hdf5File, loopbackHeuristic, afterEachPlane, numCellCreatorThreads, new SubTaskProgressWriter( progressWriter, 0, 0.95 ) );
WriteSequenceToHdf5.writeHdf5File( seq, perSetupExportMipmapInfo, params.downsamplingMethod, params.deflate, params.hdf5File, loopbackHeuristic, afterEachPlane, numCellCreatorThreads, new SubTaskProgressWriter( progressWriter, 0, 0.95 ) );
}

// write xml sequence description
Expand Down Expand Up @@ -285,6 +284,8 @@ protected static class Parameters

final int[][] subdivisions;

final DownsampleBlock.DownsamplingMethod downsamplingMethod;

final File seqFile;

final File hdf5File;
Expand All @@ -305,13 +306,14 @@ protected static class Parameters

public Parameters(
final boolean setMipmapManual, final int[][] resolutions, final int[][] subdivisions,
final File seqFile, final File hdf5File,
DownsampleBlock.DownsamplingMethod downsamplingMethod, final File seqFile, final File hdf5File,
final MinMaxOption minMaxOption, final double rangeMin, final double rangeMax, final boolean deflate,
final boolean split, final int timepointsPerPartition, final int setupsPerPartition )
{
this.setMipmapManual = setMipmapManual;
this.resolutions = resolutions;
this.subdivisions = subdivisions;
this.downsamplingMethod = downsamplingMethod;
this.seqFile = seqFile;
this.hdf5File = hdf5File;
this.minMaxOption = minMaxOption;
Expand All @@ -330,6 +332,8 @@ public Parameters(

static String lastChunkSizes = "{32,32,4}, {16,16,8}, {8,8,8}";

static DownsampleBlock.DownsamplingMethod lastDownsamplingMethod = DownsampleBlock.DownsamplingMethod.Average;

static int lastMinMaxChoice = 2;

static double lastMin = 0;
Expand Down Expand Up @@ -364,6 +368,7 @@ protected Parameters getParameters( final double impMin, final double impMax, fi
final TextField tfSubsampling = ( TextField ) gd.getStringFields().lastElement();
gd.addStringField( "Hdf5_chunk_sizes", lastChunkSizes, 25 );
final TextField tfChunkSizes = ( TextField ) gd.getStringFields().lastElement();
gd.addChoice( "Subsampling_method", new String[]{ DownsampleBlock.DownsamplingMethod.Average.toString(), DownsampleBlock.DownsamplingMethod.Mode.toString(), DownsampleBlock.DownsamplingMethod.Centre.toString() }, lastDownsamplingMethod.toString() );

gd.addMessage( "" );
final String[] minMaxChoices = new String[] { "Use ImageJ's current min/max setting", "Compute min/max of the (hyper-)stack", "Use values specified below" };
Expand Down Expand Up @@ -402,6 +407,7 @@ public boolean dialogItemChanged( final GenericDialog dialog, final AWTEvent e )
gd.getNextBoolean();
gd.getNextString();
gd.getNextString();
gd.getNextChoice();
gd.getNextChoiceIndex();
gd.getNextNumber();
gd.getNextNumber();
Expand Down Expand Up @@ -459,6 +465,7 @@ else if ( e instanceof ItemEvent && e.getID() == ItemEvent.ITEM_STATE_CHANGED &&
lastSetMipmapManual = gd.getNextBoolean();
lastSubsampling = gd.getNextString();
lastChunkSizes = gd.getNextString();
lastDownsamplingMethod = DownsampleBlock.DownsamplingMethod.valueOf( gd.getNextChoice() );
lastMinMaxChoice = gd.getNextChoiceIndex();
lastMin = gd.getNextNumber();
lastMax = gd.getNextNumber();
Expand Down Expand Up @@ -508,6 +515,6 @@ else if ( lastMinMaxChoice == 1 )
final String hdf5Filename = seqFilename.substring( 0, seqFilename.length() - 4 ) + ".h5";
final File hdf5File = new File( hdf5Filename );

return new Parameters( lastSetMipmapManual, resolutions, subdivisions, seqFile, hdf5File, minMaxOption, lastMin, lastMax, lastDeflate, lastSplit, lastTimepointsPerPartition, lastSetupsPerPartition ); }
return new Parameters( lastSetMipmapManual, resolutions, subdivisions, lastDownsamplingMethod, seqFile, hdf5File, minMaxOption, lastMin, lastMax, lastDeflate, lastSplit, lastTimepointsPerPartition, lastSetupsPerPartition ); }
}
}
12 changes: 4 additions & 8 deletions src/main/java/bdv/ij/ExportSpimFusionPlugIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.List;
import java.util.Map;

import bdv.export.*;
import net.imglib2.Dimensions;
import net.imglib2.FinalDimensions;
import net.imglib2.realtransform.AffineTransform3D;
Expand All @@ -47,11 +48,6 @@
import org.scijava.command.Command;
import org.scijava.plugin.Plugin;

import bdv.export.ExportMipmapInfo;
import bdv.export.ProgressWriter;
import bdv.export.ProposeMipmaps;
import bdv.export.SubTaskProgressWriter;
import bdv.export.WriteSequenceToHdf5;
import bdv.ij.export.FusionResult;
import bdv.ij.export.SpimRegistrationSequence;
import bdv.ij.export.ViewSetupWrapper;
Expand Down Expand Up @@ -314,7 +310,7 @@ public static void appendToExistingFile( final Parameters params ) throws SpimDa
{
final SubTaskProgressWriter subtaskProgress = new SubTaskProgressWriter( progress, complete, complete + completionStep );
final int numCellCreatorThreads = Math.max( 1, PluginHelper.numThreads() - 1 );
WriteSequenceToHdf5.writeHdf5PartitionFile( fusionSeq, perSetupExportMipmapInfo, params.deflate, partition, null, null, numCellCreatorThreads, subtaskProgress );
WriteSequenceToHdf5.writeHdf5PartitionFile( fusionSeq, perSetupExportMipmapInfo, DownsampleBlock.DownsamplingMethod.Average, params.deflate, partition, null, null, numCellCreatorThreads, subtaskProgress );
complete += completionStep;
}

Expand Down Expand Up @@ -367,13 +363,13 @@ public static void saveAsNewFile( final Parameters params ) throws SpimDataExcep
{
final Partition partition = partitions.get( i );
final ProgressWriter p = new SubTaskProgressWriter( progress, 0, 0.95 * i / partitions.size() );
WriteSequenceToHdf5.writeHdf5PartitionFile( desc, perSetupExportMipmapInfo, params.deflate, partition, null, null, numCellCreatorThreads, p );
WriteSequenceToHdf5.writeHdf5PartitionFile( desc, perSetupExportMipmapInfo, DownsampleBlock.DownsamplingMethod.Average, params.deflate, partition, null, null, numCellCreatorThreads, p );
}
WriteSequenceToHdf5.writeHdf5PartitionLinkFile( desc, perSetupExportMipmapInfo, partitions, params.hdf5File );
}
else
{
WriteSequenceToHdf5.writeHdf5File( desc, perSetupExportMipmapInfo, params.deflate, params.hdf5File, null, null, numCellCreatorThreads, new SubTaskProgressWriter( progress, 0, 0.95 ) );
WriteSequenceToHdf5.writeHdf5File( desc, perSetupExportMipmapInfo, DownsampleBlock.DownsamplingMethod.Average, params.deflate, params.hdf5File, null, null, numCellCreatorThreads, new SubTaskProgressWriter( progress, 0, 0.95 ) );
}

// write xml file
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/bdv/ij/ExportSpimSequencePlugIn.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@
import java.util.List;
import java.util.Map;

import bdv.export.*;
import org.scijava.command.Command;
import org.scijava.plugin.Plugin;

import bdv.export.ExportMipmapInfo;
import bdv.export.ProgressWriter;
import bdv.export.ProposeMipmaps;
import bdv.export.SubTaskProgressWriter;
import bdv.export.WriteSequenceToHdf5;
import bdv.ij.export.SpimRegistrationSequence;
import bdv.ij.util.PluginHelper;
import bdv.ij.util.ProgressWriterIJ;
Expand Down Expand Up @@ -115,14 +111,14 @@ public void run()
{
final Partition partition = partitions.get( i );
final ProgressWriter p = new SubTaskProgressWriter( progress, 0, 0.95 * i / partitions.size() );
WriteSequenceToHdf5.writeHdf5PartitionFile( desc, perSetupExportMipmapInfo, params.deflate, partition, null, null, numCellCreatorThreads, p );
WriteSequenceToHdf5.writeHdf5PartitionFile( desc, perSetupExportMipmapInfo, DownsampleBlock.DownsamplingMethod.Average, params.deflate, partition, null, null, numCellCreatorThreads, p );
}
WriteSequenceToHdf5.writeHdf5PartitionLinkFile( desc, perSetupExportMipmapInfo, partitions, params.hdf5File );
}
else
{
partitions = null;
WriteSequenceToHdf5.writeHdf5File( desc, perSetupExportMipmapInfo, params.deflate, params.hdf5File, null, null, numCellCreatorThreads, new SubTaskProgressWriter( progress, 0, 0.95 ) );
WriteSequenceToHdf5.writeHdf5File( desc, perSetupExportMipmapInfo, DownsampleBlock.DownsamplingMethod.Average, params.deflate, params.hdf5File, null, null, numCellCreatorThreads, new SubTaskProgressWriter( progress, 0, 0.95 ) );
}

final Hdf5ImageLoader loader = new Hdf5ImageLoader( params.hdf5File, partitions, null, false );
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/bdv/ij/export/Scripting.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.List;
import java.util.Map;

import bdv.export.DownsampleBlock;
import bdv.export.ExportMipmapInfo;
import bdv.export.WriteSequenceToHdf5;
import bdv.ij.util.PluginHelper;
Expand Down Expand Up @@ -233,7 +234,7 @@ public void writePartition( final int index )
if ( index >= 0 && index < partitions.size() )
{
final int numCellCreatorThreads = Math.max( 1, PluginHelper.numThreads() - 1 );
WriteSequenceToHdf5.writeHdf5PartitionFile( spimData.getSequenceDescription(), perSetupMipmapInfo, deflate, partitions.get( index ), null, null, numCellCreatorThreads, null );
WriteSequenceToHdf5.writeHdf5PartitionFile( spimData.getSequenceDescription(), perSetupMipmapInfo, DownsampleBlock.DownsamplingMethod.Average, deflate, partitions.get( index ), null, null, numCellCreatorThreads, null );
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.ArrayList;
import java.util.List;

import bdv.export.DownsampleBlock;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.JDOMException;
Expand Down Expand Up @@ -336,7 +337,7 @@ public void export( final File seqFile, final File hdf5File, final int[][] resol
*/

final int numCellCreatorThreads = Math.max( 1, PluginHelper.numThreads() - 1 );
WriteSequenceToHdf5.writeHdf5File( sequenceDescriptionHDF5, resolutions, chunks, true, hdf5File, null, null, numCellCreatorThreads, progressWriter );
WriteSequenceToHdf5.writeHdf5File( sequenceDescriptionHDF5, resolutions, chunks, DownsampleBlock.DownsamplingMethod.Average, true, hdf5File, null, null, numCellCreatorThreads, progressWriter );

/*
* write XML sequence description
Expand Down