From 96ad3cc4094fe4fd63b1a07249708c1dd61e5bde Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Wed, 28 Aug 2024 13:56:22 -0400 Subject: [PATCH] SpimData2 now has a constructor that takes a URI --- .../mvrecon/fiji/datasetmanager/DHM.java | 2 +- .../FileListDatasetDefinition.java | 2 +- .../fiji/datasetmanager/LightSheetZ1.java | 2 +- .../fiji/datasetmanager/MicroManager.java | 2 +- .../mvrecon/fiji/datasetmanager/SimView.java | 2 +- .../fiji/datasetmanager/StackList.java | 2 +- .../fiji/plugin/fusion/DeconvolutionGUI.java | 10 +- .../fiji/plugin/fusion/QualityGUI.java | 8 +- .../fiji/plugin/resave/Resave_HDF5.java | 4 +- .../mvrecon/fiji/plugin/resave/Resave_N5.java | 52 ++ .../fiji/plugin/resave/Resave_TIFF.java | 4 +- .../mvrecon/fiji/spimdata/SpimData2.java | 13 +- .../imgloaders/LegacyStackImgLoaderIJ.java | 54 +- .../headless/definedataset/LightSheetZ1.java | 3 +- .../headless/definedataset/MicroManager.java | 3 +- .../definedataset/StackListImageJ.java | 2 +- .../headless/definedataset/StackListLOCI.java | 8 +- .../mvrecon/headless/resave/ResaveHdf5.java | 160 ------ .../headless/resave/ResaveHdf5Parameter.java | 52 -- .../process/export/AppendSpimData2HDF5.java | 495 ------------------ .../process/export/ExportSpimData2HDF5.java | 320 ----------- .../process/export/ExportSpimData2TIFF.java | 395 -------------- .../process/splitting/SplittingTools.java | 2 +- 23 files changed, 124 insertions(+), 1473 deletions(-) delete mode 100644 src/main/java/net/preibisch/mvrecon/headless/resave/ResaveHdf5.java delete mode 100644 src/main/java/net/preibisch/mvrecon/headless/resave/ResaveHdf5Parameter.java delete mode 100644 src/main/java/net/preibisch/mvrecon/process/export/AppendSpimData2HDF5.java delete mode 100644 src/main/java/net/preibisch/mvrecon/process/export/ExportSpimData2HDF5.java delete mode 100644 src/main/java/net/preibisch/mvrecon/process/export/ExportSpimData2TIFF.java diff --git a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/DHM.java b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/DHM.java index ec3adbe58..db0303214 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/DHM.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/DHM.java @@ -119,7 +119,7 @@ public SpimData2 createDataset( final String xmlFileName ) //viewInterestPoints.createViewInterestPoints( sequenceDescription.getViewDescriptions() ); // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimData = new SpimData2( meta.getDir(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimData = new SpimData2( meta.getDir().toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); return spimData; } diff --git a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/FileListDatasetDefinition.java b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/FileListDatasetDefinition.java index 34b3e91f5..dc91cc12a 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/FileListDatasetDefinition.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/FileListDatasetDefinition.java @@ -645,7 +645,7 @@ else if ( aInfoI.axis == 2 ) final ViewInterestPoints viewInterestPoints = new ViewInterestPoints(); //viewInterestPoints.createViewInterestPoints( sd.getViewDescriptions() ); - SpimData2 data = new SpimData2( new File("/"), sd, vrs, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + SpimData2 data = new SpimData2( new File("/").toURI(), sd, vrs, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); return data; } diff --git a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/LightSheetZ1.java b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/LightSheetZ1.java index 40a1c1393..0c85ebfb2 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/LightSheetZ1.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/LightSheetZ1.java @@ -148,7 +148,7 @@ public SpimData2 createDataset( final String xmlFileName ) //viewInterestPoints.createViewInterestPoints( sequenceDescription.getViewDescriptions() ); // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimData = new SpimData2( new File( directory ), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimData = new SpimData2( new File( directory ).toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); if ( meta.applyAxis() ) Apply_Transformation.applyAxis( spimData ); diff --git a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/MicroManager.java b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/MicroManager.java index 6e0311910..19e59c224 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/MicroManager.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/MicroManager.java @@ -123,7 +123,7 @@ public SpimData2 createDataset( final String xmlFileName ) //viewInterestPoints.createViewInterestPoints( sequenceDescription.getViewDescriptions() ); // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimData = new SpimData2( new File( directory ), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimData = new SpimData2( new File( directory ).toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); if ( reader.applyAxis() ) Apply_Transformation.applyAxis( spimData ); diff --git a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/SimView.java b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/SimView.java index 7d6c1ee1b..8e6bf1b01 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/SimView.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/SimView.java @@ -151,7 +151,7 @@ public SpimData2 createDataset( final String xmlFileName ) //viewInterestPoints.createViewInterestPoints( sequenceDescription.getViewDescriptions() ); // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimData = new SpimData2( new File( directory ), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimData = new SpimData2( new File( directory ).toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); return spimData; } diff --git a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/StackList.java b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/StackList.java index 8bfb0019d..0e4ff0d69 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/StackList.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/datasetmanager/StackList.java @@ -331,7 +331,7 @@ public SpimData2 createDataset( final String xmlFileName ) //viewInterestPoints.createViewInterestPoints( sequenceDescription.getViewDescriptions() ); // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimData = new SpimData2( new File( directory ), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimData = new SpimData2( new File( directory ).toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); return spimData; } diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/DeconvolutionGUI.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/DeconvolutionGUI.java index 09aac9cc3..9f2d969db 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/DeconvolutionGUI.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/DeconvolutionGUI.java @@ -73,17 +73,15 @@ import net.preibisch.mvrecon.process.deconvolution.iteration.mul.ComputeBlockMulThreadCPUFactory; import net.preibisch.mvrecon.process.deconvolution.iteration.sequential.ComputeBlockSeqThreadCPUFactory; import net.preibisch.mvrecon.process.deconvolution.iteration.sequential.ComputeBlockSeqThreadCUDAFactory; -import net.preibisch.mvrecon.process.export.AppendSpimData2HDF5; +import net.preibisch.mvrecon.process.downsampling.DownsampleTools; import net.preibisch.mvrecon.process.export.DisplayImage; -import net.preibisch.mvrecon.process.export.ExportSpimData2HDF5; -import net.preibisch.mvrecon.process.export.ExportSpimData2TIFF; +import net.preibisch.mvrecon.process.export.ExportN5API; import net.preibisch.mvrecon.process.export.ImgExport; import net.preibisch.mvrecon.process.export.Save3dTIFF; import net.preibisch.mvrecon.process.fusion.FusionTools; import net.preibisch.mvrecon.process.fusion.FusionTools.ImgDataType; import net.preibisch.mvrecon.process.fusion.intensityadjust.IntensityAdjustmentTools; import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual; -import net.preibisch.mvrecon.process.downsampling.DownsampleTools; import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group; public class DeconvolutionGUI implements FusionExportInterface @@ -97,9 +95,7 @@ public class DeconvolutionGUI implements FusionExportInterface staticImgExportAlgorithms.add( new DisplayImage() ); staticImgExportAlgorithms.add( new Save3dTIFF( null ) ); - staticImgExportAlgorithms.add( new ExportSpimData2TIFF() ); - staticImgExportAlgorithms.add( new ExportSpimData2HDF5() ); - staticImgExportAlgorithms.add( new AppendSpimData2HDF5() ); + staticImgExportAlgorithms.add( new ExportN5API() ); imgExportDescriptions = new String[ staticImgExportAlgorithms.size() ]; diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/QualityGUI.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/QualityGUI.java index 0532c24f5..80c5b9262 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/QualityGUI.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/QualityGUI.java @@ -40,14 +40,11 @@ import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBox; import net.preibisch.mvrecon.process.boundingbox.BoundingBoxTools; -import net.preibisch.mvrecon.process.export.AppendSpimData2HDF5; +import net.preibisch.mvrecon.process.downsampling.DownsampleTools; import net.preibisch.mvrecon.process.export.DisplayImage; -import net.preibisch.mvrecon.process.export.ExportSpimData2HDF5; -import net.preibisch.mvrecon.process.export.ExportSpimData2TIFF; import net.preibisch.mvrecon.process.export.ImgExport; import net.preibisch.mvrecon.process.export.Save3dTIFF; import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual; -import net.preibisch.mvrecon.process.downsampling.DownsampleTools; import net.preibisch.mvrecon.process.interestpointregistration.TransformationTools; import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group; @@ -89,9 +86,6 @@ public class QualityGUI implements FusionExportInterface staticImgExportAlgorithms.add( new DisplayImage() ); staticImgExportAlgorithms.add( new Save3dTIFF( null ) ); - staticImgExportAlgorithms.add( new ExportSpimData2TIFF() ); - staticImgExportAlgorithms.add( new ExportSpimData2HDF5() ); - staticImgExportAlgorithms.add( new AppendSpimData2HDF5() ); imgExportDescriptions = new String[ staticImgExportAlgorithms.size() ]; diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_HDF5.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_HDF5.java index e778512dd..563a98305 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_HDF5.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_HDF5.java @@ -267,7 +267,7 @@ public static SpimData2 reduceSpimData2( final SpimData2 oldSpimData, final List //TODO: copy PSFs final SpimData2 newSpimData = new SpimData2( - oldSpimData.getBasePath(), + oldSpimData.getBasePathURI(), sequenceDescription, viewRegistrations, viewsInterestPoints, @@ -288,7 +288,7 @@ public static Pair< SpimData2, List< String > > createXMLObject( { // Re-assemble a new SpimData object containing the subset of viewsetups and timepoints selected final List< String > filesToCopy = new ArrayList< String >(); - final SpimData2 newSpimData = Resave_TIFF.assemblePartialSpimData2( spimData, viewIds, params.seqFile.getParentFile(), filesToCopy ); + final SpimData2 newSpimData = Resave_TIFF.assemblePartialSpimData2( spimData, viewIds, params.seqFile.getParentFile().toURI(), filesToCopy ); final ArrayList< Partition > partitions = Generic_Resave_HDF5.getPartitions( newSpimData, params ); final Hdf5ImageLoader hdf5Loader; diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java index c98f7652c..334a40280 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_N5.java @@ -28,18 +28,31 @@ import java.util.Arrays; import java.util.Collection; import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Map.Entry; import java.util.stream.Collectors; +import org.janelia.saalfeldlab.n5.Compression; +import org.janelia.saalfeldlab.n5.DataType; +import org.janelia.saalfeldlab.n5.N5Writer; +import org.janelia.saalfeldlab.n5.universe.N5Factory; + import bdv.export.ExportMipmapInfo; import bdv.export.ProgressWriter; import bdv.export.n5.WriteSequenceToN5; import bdv.img.n5.N5ImageLoader; import ij.ImageJ; import ij.plugin.PlugIn; +import mpicbg.spim.data.SpimData; import mpicbg.spim.data.SpimDataException; +import mpicbg.spim.data.generic.AbstractSpimData; import mpicbg.spim.data.sequence.TimePoint; import mpicbg.spim.data.sequence.ViewId; import mpicbg.spim.data.sequence.ViewSetup; +import net.imglib2.type.numeric.integer.UnsignedByteType; +import net.imglib2.type.numeric.integer.UnsignedShortType; +import net.imglib2.type.numeric.real.FloatType; import net.preibisch.mvrecon.fiji.plugin.queryXML.LoadParseQueryXML; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; @@ -120,6 +133,7 @@ public static void resaveN5( } else if ( URITools.isS3( n5Params.n5URI ) || URITools.isGC( n5Params.n5URI ) ) { + final N5Writer = new N5Factory().openWriter( URITools.appendName( baseDir, baseN5 ) ); // cloud support, avoid dependency hell if it is a local file // TODO: save to cloud } @@ -134,6 +148,44 @@ else if ( URITools.isS3( n5Params.n5URI ) || URITools.isGC( n5Params.n5URI ) ) progressWriter.out().println( new Date( System.currentTimeMillis() ) + ": Finished saving " + n5Params.n5URI + " and " + n5Params.xmlURI ); } + public static void createDatasets( + final N5Writer n5, + final AbstractSpimData data, + final int[] blockSize, + final int[][] downsamplingFactors, + final Compression compression, + final Map viewSetupIdToDimensions ) + { + for ( final Entry viewSetup : viewSetupIdToDimensions.entrySet() ) + { + final Object type = data.getSequenceDescription().getImgLoader().getSetupImgLoader( viewSetup.getKey() ).getImageType(); + final DataType dataType; + + if ( UnsignedShortType.class.isInstance( type ) ) + dataType = DataType.UINT16; + else if ( UnsignedByteType.class.isInstance( type ) ) + dataType = DataType.UINT8; + else if ( FloatType.class.isInstance( type ) ) + dataType = DataType.FLOAT32; + else + throw new RuntimeException("Unsupported pixel type: " + type.getClass().getCanonicalName() ); + + // TODO: ViewSetupId needs to contain: {"downsamplingFactors":[[1,1,1],[2,2,1]],"dataType":"uint16"} + final String n5Dataset = "setup" + viewSetup.getKey(); + + System.out.println( "Creating group: " + "'setup" + viewSetup.getKey() + "'" ); + + n5.createGroup( n5Dataset ); + + System.out.println( "setting attributes for '" + "setup" + viewSetup.getKey() + "'"); + + n5.setAttribute( n5Dataset, "downsamplingFactors", downsamplingFactors ); + n5.setAttribute( n5Dataset, "dataType", dataType ); + n5.setAttribute( n5Dataset, "blockSize", blockSize ); + n5.setAttribute( n5Dataset, "dimensions", viewSetup.getValue() ); + n5.setAttribute( n5Dataset, "compression", compression ); + } + } public static void main(String[] args) { diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_TIFF.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_TIFF.java index d4af132d1..b48a41d76 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_TIFF.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/resave/Resave_TIFF.java @@ -324,7 +324,7 @@ public static Pair< SpimData2, List< String > > createXMLObject( final SpimData2 // Re-assemble a new SpimData object containing the subset of viewsetups and timepoints selected final List< String > filesToCopy = new ArrayList< String >(); - final SpimData2 newSpimData = assemblePartialSpimData2( spimData, viewIds, new File( URITools.removeFilePrefix( params.getXMLPath() ) ).getParentFile(), filesToCopy ); + final SpimData2 newSpimData = assemblePartialSpimData2( spimData, viewIds, new File( URITools.removeFilePrefix( params.getXMLPath() ) ).getParentFile().toURI(), filesToCopy ); final StackImgLoaderIJ imgLoader = new StackImgLoaderIJ( new File( URITools.removeFilePrefix( params.getXMLPath() ) ).getParentFile(), @@ -393,7 +393,7 @@ public static void copyFolder( final File src, final File dest, final List< Stri * @param basePath - the base path * @return new SpimData */ - public static SpimData2 assemblePartialSpimData2( final SpimData2 spimData, final List< ? extends ViewId > viewIds, final File basePath, final List< String > filesToCopy ) + public static SpimData2 assemblePartialSpimData2( final SpimData2 spimData, final List< ? extends ViewId > viewIds, final URI basePath, final List< String > filesToCopy ) { final TimePoints timepoints; diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/SpimData2.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/SpimData2.java index faa51f058..f669252f4 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/SpimData2.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/SpimData2.java @@ -73,7 +73,8 @@ public class SpimData2 extends SpimData private IntensityAdjustments intensityAdjustments; public boolean gridMoveRequested = false; - // TODO: only for compatibility with depending packages, remove at some point + /* + // only for compatibility with depending packages, remove at some point public SpimData2( final File basePath, final SequenceDescription sequenceDescription, @@ -85,9 +86,10 @@ public SpimData2( { this( basePath, sequenceDescription, viewRegistrations, viewsInterestPoints, boundingBoxes, pointSpreadFunctions, stitchingResults, new IntensityAdjustments() ); } + */ public SpimData2( - final File basePath, + final URI basePathUri, final SequenceDescription sequenceDescription, final ViewRegistrations viewRegistrations, final ViewInterestPoints viewsInterestPoints, @@ -96,7 +98,10 @@ public SpimData2( final StitchingResults stitchingResults, final IntensityAdjustments intensityAdjustments ) { - super( basePath, sequenceDescription, viewRegistrations ); + super( null, sequenceDescription, viewRegistrations ); + + // work-around for the super class not having a constructor for URI + this.setBasePathURI(basePathUri); this.viewsInterestPoints = viewsInterestPoints; this.boundingBoxes = boundingBoxes; @@ -523,7 +528,7 @@ public static SpimData2 convert( final SpimData data1 ) final StitchingResults sr = new StitchingResults(); final IntensityAdjustments ia = new IntensityAdjustments(); - return new SpimData2( data1.getBasePath(), s, vr, vipl, bb, psfs, sr, ia ); + return new SpimData2( data1.getBasePathURI(), s, vr, vipl, bb, psfs, sr, ia ); } /** diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/LegacyStackImgLoaderIJ.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/LegacyStackImgLoaderIJ.java index 0dac97a27..8337fdba9 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/LegacyStackImgLoaderIJ.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/imgloaders/LegacyStackImgLoaderIJ.java @@ -22,40 +22,38 @@ */ package net.preibisch.mvrecon.fiji.spimdata.imgloaders; +import java.io.File; +import java.util.Date; + import ij.ImagePlus; import ij.ImageStack; import ij.gui.GenericDialog; import ij.io.Opener; import ij.process.ImageProcessor; - -import java.io.File; -import java.util.Date; - import mpicbg.spim.data.generic.sequence.AbstractSequenceDescription; import mpicbg.spim.data.sequence.ViewId; import net.imglib2.Cursor; import net.imglib2.RandomAccessibleInterval; import net.imglib2.converter.RealUnsignedShortConverter; import net.imglib2.img.Img; -import net.imglib2.img.ImgFactory; import net.imglib2.img.array.ArrayImg; import net.imglib2.img.display.imagej.ImageJFunctions; import net.imglib2.img.planar.PlanarImg; -import net.imglib2.type.NativeType; +import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.integer.UnsignedShortType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.view.Views; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.fiji.datasetmanager.StackListImageJ; import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5; -import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5.Parameters; +import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5.ParametersResaveHDF5; import net.preibisch.mvrecon.fiji.plugin.util.GUIHelper; -import net.preibisch.mvrecon.process.export.ExportSpimData2HDF5; +import net.preibisch.mvrecon.process.fusion.FusionTools; import util.ImgLib2Tools; public class LegacyStackImgLoaderIJ extends LegacyStackImgLoader { - Parameters params = null; + ParametersResaveHDF5 params = null; public LegacyStackImgLoaderIJ( final File path, final String fileNamePattern, @@ -132,7 +130,7 @@ public RandomAccessibleInterval< UnsignedShortType > getImage( final ViewId view if ( params == null ) return null; - final double[] minmax = ExportSpimData2HDF5.updateAndGetMinMax( ImageJFunctions.wrapFloat( imp ), params ); + final double[] minmax = updateAndGetMinMax( ImageJFunctions.wrapFloat( imp ), params ); converter = new RealUnsignedShortConverter< FloatType >( minmax[ 0 ], minmax[ 1 ] ); } else @@ -246,7 +244,7 @@ public String toString() return new StackListImageJ().getTitle() + ", ImgFactory=" + getImgFactory().getClass().getSimpleName(); } - protected static Parameters queryParameters() + protected static ParametersResaveHDF5 queryParameters() { final GenericDialog gd = new GenericDialog( "Opening 32bit TIFF as 16bit" ); @@ -288,6 +286,38 @@ protected static Parameters queryParameters() Generic_Resave_HDF5.defaultMin = Generic_Resave_HDF5.defaultMax = Double.NaN; } - return new Parameters( false, null, null, null, null, false, false, 0, 0, false, 0, Generic_Resave_HDF5.defaultConvertChoice, Generic_Resave_HDF5.defaultMin, Generic_Resave_HDF5.defaultMax ); + return new ParametersResaveHDF5( false, null, null, null, null, false, false, 0, 0, false, 0, Generic_Resave_HDF5.defaultConvertChoice, Generic_Resave_HDF5.defaultMin, Generic_Resave_HDF5.defaultMax ); } + + public static < T extends RealType< T > > double[] updateAndGetMinMax( final RandomAccessibleInterval< T > img, final ParametersResaveHDF5 params ) + { + double min, max; + + if ( params == null || params.getConvertChoice() == 0 || Double.isNaN( params.getMin() ) || Double.isNaN( params.getMin() ) ) + { + final float[] minmax = FusionTools.minMax( img ); + min = minmax[ 0 ]; + max = minmax[ 1 ]; + + min = Math.max( 0, min - ((min+max)/2.0) * 0.1 ); + max = max + ((min+max)/2.0) * 0.1; + + if ( params != null ) + { + params.setMin( min ); + params.setMax( max ); + } + } + else + { + min = params.getMin(); + max = params.getMax(); + } + + IOFunctions.println( "Min intensity for 16bit conversion: " + min ); + IOFunctions.println( "Max intensity for 16bit conversion: " + max ); + + return new double[]{ min, max }; + } + } diff --git a/src/main/java/net/preibisch/mvrecon/headless/definedataset/LightSheetZ1.java b/src/main/java/net/preibisch/mvrecon/headless/definedataset/LightSheetZ1.java index 5ac5d75a0..58e7be3e6 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/definedataset/LightSheetZ1.java +++ b/src/main/java/net/preibisch/mvrecon/headless/definedataset/LightSheetZ1.java @@ -23,6 +23,7 @@ package net.preibisch.mvrecon.headless.definedataset; import java.io.File; +import java.net.URI; import java.util.ArrayList; import mpicbg.spim.data.registration.ViewRegistrations; @@ -122,7 +123,7 @@ public static SpimData2 createDataset( final String cziFirstFile, final DefineDa // finally create the SpimData itself based on the sequence description and the view registration final SpimData2 spimData = new SpimData2( - new File( cziFile.getParent() ), + new File( cziFile.getParent() ).toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, diff --git a/src/main/java/net/preibisch/mvrecon/headless/definedataset/MicroManager.java b/src/main/java/net/preibisch/mvrecon/headless/definedataset/MicroManager.java index fd07c1f0e..f06010cc4 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/definedataset/MicroManager.java +++ b/src/main/java/net/preibisch/mvrecon/headless/definedataset/MicroManager.java @@ -24,6 +24,7 @@ import java.io.File; import java.io.IOException; +import java.net.URI; import java.util.ArrayList; import mpicbg.spim.data.registration.ViewRegistrations; @@ -128,7 +129,7 @@ public static SpimData2 createDataset( final String tiffFile, final DefineDataSe //viewInterestPoints.createViewInterestPoints( sequenceDescription.getViewDescriptions() ); // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimData = new SpimData2( new File( directory ), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimData = new SpimData2( new File( directory ).toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); if ( reader.applyAxis() ) Apply_Transformation.applyAxis( spimData ); diff --git a/src/main/java/net/preibisch/mvrecon/headless/definedataset/StackListImageJ.java b/src/main/java/net/preibisch/mvrecon/headless/definedataset/StackListImageJ.java index e60625abb..3485a4b0c 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/definedataset/StackListImageJ.java +++ b/src/main/java/net/preibisch/mvrecon/headless/definedataset/StackListImageJ.java @@ -68,7 +68,7 @@ public static SpimData2 createDataset( final String file, final StackListParamet //viewInterestPoints.createViewInterestPoints( sequenceDescription.getViewDescriptions() ); // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimData = new SpimData2( new File( params.directory ), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimData = new SpimData2( new File( params.directory ).toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); return spimData; } diff --git a/src/main/java/net/preibisch/mvrecon/headless/definedataset/StackListLOCI.java b/src/main/java/net/preibisch/mvrecon/headless/definedataset/StackListLOCI.java index e8bca7811..48f7d43be 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/definedataset/StackListLOCI.java +++ b/src/main/java/net/preibisch/mvrecon/headless/definedataset/StackListLOCI.java @@ -27,14 +27,8 @@ import mpicbg.spim.data.registration.ViewRegistrations; import mpicbg.spim.data.sequence.ImgLoader; import mpicbg.spim.data.sequence.SequenceDescription; -import net.imglib2.img.ImgFactory; -import net.imglib2.img.array.ArrayImgFactory; -import net.imglib2.img.cell.CellImgFactory; -import net.imglib2.type.NativeType; -import net.imglib2.type.numeric.real.FloatType; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.fiji.datasetmanager.DatasetCreationUtils; -import net.preibisch.mvrecon.fiji.plugin.Apply_Transformation; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBoxes; import net.preibisch.mvrecon.fiji.spimdata.imgloaders.LegacyStackImgLoaderLOCI; @@ -73,7 +67,7 @@ public static SpimData2 createDataset( final String file, final StackListParamet //viewInterestPoints.createViewInterestPoints( sequenceDescription.getViewDescriptions() ); // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimData = new SpimData2( new File( params.directory ), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimData = new SpimData2( new File( params.directory ).toURI(), sequenceDescription, viewRegistrations, viewInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); return spimData; } diff --git a/src/main/java/net/preibisch/mvrecon/headless/resave/ResaveHdf5.java b/src/main/java/net/preibisch/mvrecon/headless/resave/ResaveHdf5.java deleted file mode 100644 index 3831a8a38..000000000 --- a/src/main/java/net/preibisch/mvrecon/headless/resave/ResaveHdf5.java +++ /dev/null @@ -1,160 +0,0 @@ -/*- - * #%L - * Software for the reconstruction of multi-view microscopic acquisitions - * like Selective Plane Illumination Microscopy (SPIM) Data. - * %% - * Copyright (C) 2012 - 2024 Multiview Reconstruction developers. - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * . - * #L% - */ -package net.preibisch.mvrecon.headless.resave; - -import bdv.export.ExportMipmapInfo; -import bdv.export.ProgressWriter; -import mpicbg.spim.data.SpimDataException; -import mpicbg.spim.data.sequence.ViewId; - -import java.io.File; -import java.util.List; -import java.util.Map; - -import net.preibisch.mvrecon.fiji.ImgLib2Temp; -import net.preibisch.mvrecon.fiji.plugin.resave.*; -import net.preibisch.mvrecon.fiji.spimdata.SpimData2; - -/** - * Created by schmied on 02/07/15. - */ -public class ResaveHdf5 { - - public static void save( final String xmlfile, final ResaveHdf5Parameter params ) - { - final ProgressWriter progressWriter = new ProgressWriterIJ(); - progressWriter.out().println( "starting export..." ); - - final HeadlessParseQueryXML xml = new HeadlessParseQueryXML(); - final String xmlFileName = xmlfile; - if ( !xml.loadXML( xmlFileName, false ) ) return; - - if ( Resave_HDF5.loadDimensions( xml.getData(), xml.getViewSetupsToProcess() ) ) - { - // save the XML again with the dimensions loaded - SpimData2.saveXML( xml.getData(), xml.getXMLFileName() ); - } - - final Map< Integer, ExportMipmapInfo> perSetupExportMipmapInfo = Resave_HDF5.proposeMipmaps( xml.getViewSetupsToProcess() ); - - Generic_Resave_HDF5.lastExportPath = xmlfile; - - final int firstviewSetupId = xml.getData().getSequenceDescription().getViewSetupsOrdered().get( 0 ).getId(); - ExportMipmapInfo autoMipmapSettings = perSetupExportMipmapInfo.get( firstviewSetupId ); - - boolean lastSetMipmapManual = false; - - boolean lastSplit = false; - int lastTimepointsPerPartition = 1; - int lastSetupsPerPartition = 0; - boolean lastDeflate = true; - int lastJobIndex = 0; -// -// if ( params.isUseCluster() ) -// { -// lastSplit = true; -// } - - // If we are using user-defined sub-sampling config, enable the below codes. - // - // String lastSubsampling = "{1,1,1}, {2,2,1}, {4,4,2}"; - // String lastChunkSizes = "{16,16,16}, {16,16,16}, {16,16,16}"; - // final int[][] resolutions = PluginHelper.parseResolutionsString( lastSubsampling ); - // final int[][] subdivisions = PluginHelper.parseResolutionsString( lastChunkSizes ); - - int[][] resolutions = autoMipmapSettings.getExportResolutions(); - if( params.resolutions != null ) - resolutions = PluginHelper.parseResolutionsString(params.resolutions); - - int[][] subdivisions = autoMipmapSettings.getSubdivisions(); - if( params.subdivisions != null ) - subdivisions = PluginHelper.parseResolutionsString( params.subdivisions ); - -// final File seqFile, hdf5File; - -// seqFile = new File(xmlFileName); -// hdf5File = new File(seqFile.getPath().substring( 0, seqFile.getPath().length() - 4 ) + ".h5"); - - int defaultConvertChoice = 1; - double defaultMin, defaultMax; - defaultMin = defaultMax = Double.NaN; - boolean displayClusterProcessing = false; - - final SpimData2 data = xml.getData(); - final List viewIds = SpimData2.getAllViewIdsSorted(data, xml.getViewSetupsToProcess(), xml.getTimePointsToProcess()); - - - - Generic_Resave_HDF5.Parameters newParameters = new Generic_Resave_HDF5.Parameters( - params.setMipmapManual, - resolutions, - subdivisions, - params.seqFile, - params.hdf5File, - params.deflate, - params.split, - params.timepointsPerPartition, - params.setupsPerPartition, - params.onlyRunSingleJob, - params.jobId, - params.convertChoice, - params.min, - params.max - ); - - // write hdf5 - Generic_Resave_HDF5.writeHDF5(Resave_HDF5.reduceSpimData2(data, viewIds), newParameters, progressWriter); - - // write xml sequence description - try - { - final ImgLib2Temp.Pair< SpimData2, List< String > > result = Resave_HDF5.createXMLObject( data, viewIds, newParameters, null, false ); - - xml.getIO().save( result.getA(), newParameters.getSeqFile().getAbsolutePath() ); - - // copy the interest points if they exist - Resave_TIFF.copyInterestPoints(xml.getData().getBasePath(), newParameters.getSeqFile().getParentFile(), result.getB()); - } - catch ( SpimDataException e ) - { - throw new RuntimeException( e ); - } - - - } - - public static void main( final String[] argv ) - { - // Test mvn commamnd - // - // export MAVEN_OPTS="-Xms4g -Xmx16g -Djava.awt.headless=true" - // mvn exec:java -Dexec.mainClass="task.ResaveHdf5Task" -Dexec.args="-Dxml_filename=/projects/pilot_spim/moon/test.xml -Dsubsampling_factors='{1,1,1}, {2,2,1}, {4,4,2}' -Dhdf5_chunk_sizes='{16,16,16}, {16,16,16}, {16,16,16}'" - ResaveHdf5Parameter params = new ResaveHdf5Parameter(); - params.seqFile = new File("/Users/schmied/Desktop/moon/test.xml"); - params.hdf5File = new File(params.seqFile.getPath().substring( 0, params.seqFile.getPath().length() - 4 ) + ".h5"); - ResaveHdf5.save("/Users/schmied/Desktop/moon/test.xml",params); - - System.exit( 0 ); - } - -} diff --git a/src/main/java/net/preibisch/mvrecon/headless/resave/ResaveHdf5Parameter.java b/src/main/java/net/preibisch/mvrecon/headless/resave/ResaveHdf5Parameter.java deleted file mode 100644 index 5816e2deb..000000000 --- a/src/main/java/net/preibisch/mvrecon/headless/resave/ResaveHdf5Parameter.java +++ /dev/null @@ -1,52 +0,0 @@ -/*- - * #%L - * Software for the reconstruction of multi-view microscopic acquisitions - * like Selective Plane Illumination Microscopy (SPIM) Data. - * %% - * Copyright (C) 2012 - 2024 Multiview Reconstruction developers. - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * . - * #L% - */ -package net.preibisch.mvrecon.headless.resave; - -import java.io.File; - -/** - * Created by schmied on 02/07/15. - */ -public class ResaveHdf5Parameter { - - public boolean setMipmapManual = false; - public String resolutions = "{1,1,1}, {2,2,1}, {4,4,2}"; - public String subdivisions = "{16,16,16}, {16,16,16}, {16,16,16}"; - public File seqFile; - public File hdf5File; - public boolean deflate = true; - public boolean split = false; - public int timepointsPerPartition = 1; - public int setupsPerPartition =1; - public boolean onlyRunSingleJob = false; - public int jobId = 0; - - public int convertChoice = 1; - public double min = Double.NaN; - public double max = Double.NaN; - - public String getXmlFilename = "one.xml"; - static int lastJobIndex = 0; - public String exportPath = "/Users/pietzsch/Desktop/spimrec2.xml"; - -} diff --git a/src/main/java/net/preibisch/mvrecon/process/export/AppendSpimData2HDF5.java b/src/main/java/net/preibisch/mvrecon/process/export/AppendSpimData2HDF5.java deleted file mode 100644 index c5718d843..000000000 --- a/src/main/java/net/preibisch/mvrecon/process/export/AppendSpimData2HDF5.java +++ /dev/null @@ -1,495 +0,0 @@ -/*- - * #%L - * Software for the reconstruction of multi-view microscopic acquisitions - * like Selective Plane Illumination Microscopy (SPIM) Data. - * %% - * Copyright (C) 2012 - 2024 Multiview Reconstruction developers. - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * . - * #L% - */ -package net.preibisch.mvrecon.process.export; - -import java.io.File; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - -import bdv.export.ExportMipmapInfo; -import bdv.export.ProgressWriter; -import bdv.export.SubTaskProgressWriter; -import bdv.export.WriteSequenceToHdf5; -import bdv.img.hdf5.Hdf5ImageLoader; -import bdv.img.hdf5.Partition; -import bdv.spimdata.tools.MergePartitionList; -import mpicbg.spim.data.generic.sequence.BasicViewDescription; -import mpicbg.spim.data.registration.ViewRegistration; -import mpicbg.spim.data.registration.ViewTransform; -import mpicbg.spim.data.registration.ViewTransformAffine; -import mpicbg.spim.data.sequence.Angle; -import mpicbg.spim.data.sequence.Channel; -import mpicbg.spim.data.sequence.FinalVoxelDimensions; -import mpicbg.spim.data.sequence.Illumination; -import mpicbg.spim.data.sequence.MissingViews; -import mpicbg.spim.data.sequence.SequenceDescription; -import mpicbg.spim.data.sequence.Tile; -import mpicbg.spim.data.sequence.TimePoint; -import mpicbg.spim.data.sequence.ViewDescription; -import mpicbg.spim.data.sequence.ViewId; -import mpicbg.spim.data.sequence.ViewSetup; -import net.imglib2.Interval; -import net.imglib2.RandomAccessibleInterval; -import net.imglib2.realtransform.AffineTransform3D; -import net.imglib2.type.NativeType; -import net.imglib2.type.numeric.RealType; -import net.imglib2.type.numeric.integer.UnsignedShortType; -import net.imglib2.util.Pair; -import net.imglib2.util.Util; -import net.imglib2.util.ValuePair; -import net.preibisch.mvrecon.Threads; -import net.preibisch.mvrecon.fiji.plugin.fusion.FusionExportInterface; -import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5; -import net.preibisch.mvrecon.fiji.plugin.resave.ProgressWriterIJ; -import net.preibisch.mvrecon.fiji.plugin.resave.Resave_HDF5; -import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5.Parameters; -import net.preibisch.mvrecon.fiji.spimdata.SpimData2; -import net.preibisch.mvrecon.fiji.spimdata.interestpoints.ViewInterestPointLists; -import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group; - -public class AppendSpimData2HDF5 implements ImgExport -{ - public static String defaultPath = null; - - private FusionExportInterface fusion; - - private List< TimePoint > newTimepoints; - - private List< ViewSetup > newViewSetups; - - private Parameters params; - - private SpimData2 spimData; - - private SpimData2 fusionOnlySpimData; - - private Map< Integer, ExportMipmapInfo > perSetupExportMipmapInfo; - - private HashMap< ViewId, Partition > viewIdToPartition; - - private final ProgressWriter progressWriter = new ProgressWriterIJ(); - - @Override - public boolean finish() - { - // this spimdata object was modified - return true; - } - - @Override - public boolean queryParameters( final FusionExportInterface fusion ) - { - System.out.println( "queryParameters()" ); - - this.fusion = fusion; - - // define new timepoints and viewsetups - final Pair< List< TimePoint >, List< ViewSetup > > newStructure = defineNewViewSetups( fusion ); - this.newTimepoints = newStructure.getA(); - this.newViewSetups = newStructure.getB(); - - this.spimData = (SpimData2) fusion.getSpimData(); - - Hdf5ImageLoader il; - if (Hdf5ImageLoader.class.isInstance( spimData.getSequenceDescription().getImgLoader() )) - il = ( Hdf5ImageLoader ) spimData.getSequenceDescription().getImgLoader(); - else - return false; - - perSetupExportMipmapInfo = Resave_HDF5.proposeMipmaps( newViewSetups ); - - String fn = il.getHdf5File().getAbsolutePath(); - if ( fn.endsWith( ".h5" ) ) - fn = fn.substring( 0, fn.length() - ".h5".length() ); - String fusionHdfFilename = ""; - String fusionXmlFilename = ""; - for ( int i = 0;; ++i ) - { - fusionHdfFilename = String.format( "%s-f%d.h5", fn, i ); - fusionXmlFilename = String.format( "%s-f%d.xml", fn, i ); - if ( !new File( fusionHdfFilename ).exists() && !new File( fusionXmlFilename ).exists() ) - break; - } - - boolean is16bit = fusion.getPixelType() == 1; - - final int firstviewSetupId = newViewSetups.get( 0 ).getId(); - params = Generic_Resave_HDF5.getParameters( perSetupExportMipmapInfo.get( firstviewSetupId ), false, getDescription(), is16bit ); - if ( params == null ) - { - System.out.println( "abort " ); - return false; - } - params.setHDF5File( new File( fusionHdfFilename ) ); - params.setSeqFile( new File( fusionXmlFilename ) ); - - Pair< SpimData2, HashMap< ViewId, Partition > > init = ExportSpimData2HDF5.initSpimData( - newTimepoints, newViewSetups, params, perSetupExportMipmapInfo ); - fusionOnlySpimData = init.getA(); - viewIdToPartition = init.getB(); - - perSetupExportMipmapInfo.putAll( - MergePartitionList.getHdf5PerSetupExportMipmapInfos( spimData.getSequenceDescription() ) ); - - appendSpimData2( spimData, newTimepoints, newViewSetups ); - - ArrayList< Partition > mergedPartitions = MergePartitionList.getMergedHdf5PartitionList( - spimData.getSequenceDescription(), fusionOnlySpimData.getSequenceDescription() ); - - String mergedHdfFilename = ""; - for ( int i = 0;; ++i ) - { - mergedHdfFilename = String.format( "%s-m%d.h5", fn, i ); - if ( !new File( mergedHdfFilename ).exists() ) - break; - } - - SequenceDescription seq = spimData.getSequenceDescription(); - Hdf5ImageLoader newLoader = new Hdf5ImageLoader( - new File( mergedHdfFilename ), mergedPartitions, seq, false ); - seq.setImgLoader( newLoader ); - WriteSequenceToHdf5.writeHdf5PartitionLinkFile( spimData.getSequenceDescription(), perSetupExportMipmapInfo ); - - return true; - } - - @Override - public int[] blocksize() { return new int[] { 32, 32, 16 }; } - - public < T extends RealType< T > & NativeType< T >> boolean exportImage( - RandomAccessibleInterval< T > img, - final Interval bb, - final double downsampling, - final double anisoF, - final String title, - final Group< ? extends ViewId > fusionGroup ) - { - System.out.println( "exportImage2()" ); - - final ViewId newViewId = ExportSpimData2TIFF.identifyNewViewId( newTimepoints, newViewSetups, fusionGroup, fusion ); - - // write the image - final RandomAccessibleInterval< UnsignedShortType > ushortimg; - if ( ! UnsignedShortType.class.isInstance( Util.getTypeFromInterval( img ) ) ) - ushortimg = ExportSpimData2HDF5.convert( img, params ); - else - ushortimg = ( RandomAccessibleInterval ) img; - - final Partition partition = viewIdToPartition.get( newViewId ); - final ExportMipmapInfo mipmapInfo = perSetupExportMipmapInfo.get( newViewId.getViewSetupId() ); - final boolean writeMipmapInfo = true; // TODO: remember whether we already wrote it and write only once - final boolean deflate = params.getDeflate(); - final ProgressWriter progressWriter = new SubTaskProgressWriter( this.progressWriter, 0.0, 1.0 ); // TODO - WriteSequenceToHdf5.writeViewToHdf5PartitionFile( ushortimg, partition, newViewId.getTimePointId(), newViewId.getViewSetupId(), mipmapInfo, writeMipmapInfo, deflate, null, null, Threads.numThreads(), progressWriter ); - - // update the registrations - final ViewRegistration vr = spimData.getViewRegistrations().getViewRegistration( newViewId ); - - final double scale = Double.isNaN( downsampling ) ? 1.0 : downsampling; - final double ai = Double.isNaN( anisoF ) ? 1.0 : anisoF; - - final AffineTransform3D m = new AffineTransform3D(); - m.set( scale, 0.0f, 0.0f, bb.min( 0 ), - 0.0f, scale, 0.0f, bb.min( 1 ), - 0.0f, 0.0f, scale * ai, bb.min( 2 ) * ai ); // TODO: bb * ai is right? - final ViewTransform vt = new ViewTransformAffine( "fusion bounding box", m ); - - vr.getTransformList().clear(); - vr.getTransformList().add( vt ); - - return true; - } - - @Override - public ImgExport newInstance() - { - //BoundingBoxGUI.defaultPixelType = 1; // set to 16 bit by default - return new AppendSpimData2HDF5(); - } - - @Override - public String getDescription() - { - return "Append to current XML Project (HDF5)"; - } - - public static Pair< List< TimePoint >, List< ViewSetup > > defineNewViewSetups( final FusionExportInterface fusion ) - { - final List< ViewSetup > newViewSetups = new ArrayList<>(); - final List< TimePoint > newTimepoints; - - int newViewSetupId = Integer.MIN_VALUE; - int newTileId = Integer.MIN_VALUE; - int newChannelId = Integer.MIN_VALUE; - int newAngleId = Integer.MIN_VALUE; - int newIllumId = Integer.MIN_VALUE; - int newTimepointId = Integer.MIN_VALUE; - - for( final ViewSetup vs : fusion.getSpimData().getSequenceDescription().getViewSetupsOrdered() ) - { - newViewSetupId = Math.max( vs.getId(), newViewSetupId ); - newTileId = Math.max( vs.getTile().getId(), newTileId ); - newChannelId = Math.max( vs.getChannel().getId(), newChannelId ); - newAngleId = Math.max( vs.getAngle().getId(), newAngleId ); - newIllumId = Math.max( vs.getIllumination().getId(), newIllumId ); - } - - for ( final TimePoint tp : fusion.getSpimData().getSequenceDescription().getTimePoints().getTimePointsOrdered() ) - newTimepointId = Math.max( tp.getId(), newTimepointId ); - - // this is the id we start with - ++newTimepointId; - ++newViewSetupId; - ++newTileId; - ++newChannelId; - ++newAngleId; - ++newIllumId; - - final double downsampling = Double.isNaN( fusion.getDownsampling() ) ? 1.0 : fusion.getDownsampling(); - - if ( fusion.getSplittingType() < 2 ) // "Each timepoint & channel" or "Each timepoint, channel & illumination" - { - newTimepoints = SpimData2.getAllTimePointsSorted( fusion.getSpimData(), fusion.getViews() ); - - final List< Channel > channels = SpimData2.getAllChannelsSorted( fusion.getSpimData(), fusion.getViews() ); - - if ( fusion.getSplittingType() == 0 )// "Each timepoint & channel" - { - for ( final Channel c : channels ) - newViewSetups.add( - new ViewSetup( - newViewSetupId++, - c.getName(), - fusion.getDownsampledBoundingBox(), - new FinalVoxelDimensions( "px", Util.getArrayFromValue( downsampling, 3 ) ), - new Tile( newTileId ), - c, - new Angle( newAngleId ), - new Illumination( newIllumId ) ) ); - } - else // "Each timepoint, channel & illumination" - { - final List< Illumination > illums = SpimData2.getAllIlluminationsSorted( fusion.getSpimData(), fusion.getViews() ); - - for ( int c = 0; c < channels.size(); ++c ) - for ( int i = 0; i < illums.size(); ++i ) - newViewSetups.add( - new ViewSetup( - newViewSetupId++, - channels.get( c ).getName() + "_" + illums.get( i ).getName(), - fusion.getDownsampledBoundingBox(), - new FinalVoxelDimensions( "px", Util.getArrayFromValue( downsampling, 3 ) ), - new Tile( newTileId ), - channels.get( newChannelId ), - new Angle( newAngleId ), - illums.get( i ) ) ); - } - } - else if ( fusion.getSplittingType() == 2 ) // "All views together" - { - newTimepoints = new ArrayList<>(); - newTimepoints.add( new TimePoint( newTimepointId ) ); - - newViewSetups.add( - new ViewSetup( - newViewSetupId++, - "Fused", - fusion.getDownsampledBoundingBox(), - new FinalVoxelDimensions( "px", Util.getArrayFromValue( downsampling, 3 ) ), - new Tile( newTileId ), - new Channel( newChannelId ), - new Angle( newAngleId ), - new Illumination( newIllumId ) ) ); - } - else if ( fusion.getSplittingType() == 3 ) // "Each view" - { - newTimepoints = new ArrayList<>(); - for ( final TimePoint tp : SpimData2.getAllTimePointsSorted( fusion.getSpimData(), fusion.getViews() ) ) - newTimepoints.add( tp ); - - for ( final ViewSetup vs : SpimData2.getAllViewSetupsSorted( fusion.getSpimData(), fusion.getViews() ) ) - { - newViewSetups.add( - new ViewSetup( - newViewSetupId++, - vs.getName(), - fusion.getDownsampledBoundingBox(), - new FinalVoxelDimensions( "px", Util.getArrayFromValue( downsampling, 3 ) ), - vs.getTile(), - vs.getChannel(), - vs.getAngle(), - vs.getIllumination() ) ); - } - } - else - { - throw new RuntimeException( "SplittingType " + fusion.getSplittingType() + " unknown." ); - } - - return new ValuePair< List< TimePoint >, List< ViewSetup > >( newTimepoints, newViewSetups ); - } - - /* - * Assembles a new SpimData2 based on the timepoints and viewsetups. - * The imgloader is still not set here. - * - */ - public static void appendSpimData2( - final SpimData2 spimData, - final List< TimePoint > timepointsToProcess, - final List< ViewSetup > newViewSetups ) - { - final SequenceDescription sequenceDescription = spimData.getSequenceDescription(); - - // current viewsetups - final Map< Integer, ViewSetup > viewSetups = (Map< Integer, ViewSetup >)sequenceDescription.getViewSetups(); - - // add all the newly fused viewsetups - for ( final ViewSetup vs : newViewSetups ) - viewSetups.put( vs.getId(), vs ); - - resetViewSetupsAndDescriptions( sequenceDescription ); - - // all the timepoints that are not processed are missing views - final HashSet< ViewId > newMissingViews = new HashSet< ViewId >(); - final Map< ViewId, ViewInterestPointLists > ips = spimData.getViewInterestPoints().getViewInterestPoints(); - for ( final TimePoint t : spimData.getSequenceDescription().getTimePoints().getTimePointsOrdered() ) - { - if ( !timepointsToProcess.contains( t ) ) - { - for ( final ViewSetup newSetup : newViewSetups ) - newMissingViews.add( new ViewId( t.getId(), newSetup.getId() ) ); - } - else - { - for ( final ViewSetup newSetup : newViewSetups ) - ips.put( new ViewId( t.getId(), newSetup.getId() ), new ViewInterestPointLists( t.getId(), newSetup.getId() ) ); - } - } - - // are there new ones? if so extend the maybe not existant list - if ( newMissingViews.size() > 0 ) - { - MissingViews m = spimData.getSequenceDescription().getMissingViews(); - if ( m != null ) - newMissingViews.addAll( m.getMissingViews() ); - m = new MissingViews( newMissingViews ); - - // marking the missing views - setMissingViews( spimData.getSequenceDescription(), m ); - BasicViewDescription.markMissingViews( spimData.getSequenceDescription().getViewDescriptions(), m ); - } - - // add the viewregistrations to the exisiting ones - final Map< ViewId, ViewRegistration > regMap = spimData.getViewRegistrations().getViewRegistrations(); - - for ( final TimePoint tp : timepointsToProcess ) - for ( final ViewSetup vs : newViewSetups ) - { - final ViewDescription vd = sequenceDescription.getViewDescription( tp.getId(), vs.getId() ); - final ViewRegistration viewRegistration = new ViewRegistration( vd.getTimePointId(), vd.getViewSetupId() ); - viewRegistration.identity(); - regMap.put( vd, viewRegistration ); - } - } - - private static final void resetViewSetupsAndDescriptions( final SequenceDescription s ) - { - try - { - Class< ? > clazz = null; - Field viewSetupsOrderedDirty = null; - Field viewDescriptionsDirty = null; - - do - { - if ( clazz == null ) - clazz = s.getClass(); - else - clazz = clazz.getSuperclass(); - - if ( clazz != null ) - for ( final Field field : clazz.getDeclaredFields() ) - { - if ( field.getName().equals( "viewSetupsOrderedDirty" ) ) - viewSetupsOrderedDirty = field; - - if ( field.getName().equals( "viewDescriptionsDirty" ) ) - viewDescriptionsDirty = field; - } - } - while ( ( viewSetupsOrderedDirty == null || viewDescriptionsDirty == null ) && clazz != null ); - - if ( viewDescriptionsDirty == null || viewDescriptionsDirty == null ) - { - System.out.println( "Failed to find SequenceDescription.viewSetupsOrderedDirty or SequenceDescription.viewDescriptionsDirty field. Quiting." ); - return; - } - - viewSetupsOrderedDirty.setAccessible( true ); - viewSetupsOrderedDirty.set( s, true ); - viewDescriptionsDirty.setAccessible( true ); - viewDescriptionsDirty.set( s, true ); - } - catch ( Exception e ) { e.printStackTrace(); } - } - - private static final void setMissingViews( final SequenceDescription s, final MissingViews m ) - { - try - { - Class< ? > clazz = null; - boolean found = false; - - do - { - if ( clazz == null ) - clazz = s.getClass(); - else - clazz = clazz.getSuperclass(); - - if ( clazz != null ) - for ( final Method method : clazz.getDeclaredMethods() ) - if ( method.getName().equals( "setMissingViews" ) ) - found = true; - } - while ( !found && clazz != null ); - - if ( !found ) - { - System.out.println( "Failed to find SequenceDescription.setMissingViews method. Quiting." ); - return; - } - - final Method setMissingViews = clazz.getDeclaredMethod( "setMissingViews", MissingViews.class ); - setMissingViews.setAccessible( true ); - setMissingViews.invoke( s, m ); - } - catch ( Exception e ) { e.printStackTrace(); } - } -} diff --git a/src/main/java/net/preibisch/mvrecon/process/export/ExportSpimData2HDF5.java b/src/main/java/net/preibisch/mvrecon/process/export/ExportSpimData2HDF5.java deleted file mode 100644 index 83034b5fa..000000000 --- a/src/main/java/net/preibisch/mvrecon/process/export/ExportSpimData2HDF5.java +++ /dev/null @@ -1,320 +0,0 @@ -/*- - * #%L - * Software for the reconstruction of multi-view microscopic acquisitions - * like Selective Plane Illumination Microscopy (SPIM) Data. - * %% - * Copyright (C) 2012 - 2024 Multiview Reconstruction developers. - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * . - * #L% - */ -package net.preibisch.mvrecon.process.export; - -import java.io.File; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import bdv.export.ExportMipmapInfo; -import bdv.export.ProgressWriter; -import bdv.export.SubTaskProgressWriter; -import bdv.export.WriteSequenceToHdf5; -import bdv.img.hdf5.Hdf5ImageLoader; -import bdv.img.hdf5.Partition; -import mpicbg.spim.data.SpimDataException; -import mpicbg.spim.data.registration.ViewRegistration; -import mpicbg.spim.data.registration.ViewRegistrations; -import mpicbg.spim.data.registration.ViewTransform; -import mpicbg.spim.data.registration.ViewTransformAffine; -import mpicbg.spim.data.sequence.SequenceDescription; -import mpicbg.spim.data.sequence.TimePoint; -import mpicbg.spim.data.sequence.TimePoints; -import mpicbg.spim.data.sequence.ViewDescription; -import mpicbg.spim.data.sequence.ViewId; -import mpicbg.spim.data.sequence.ViewSetup; -import net.imglib2.Interval; -import net.imglib2.RandomAccessibleInterval; -import net.imglib2.converter.Converters; -import net.imglib2.converter.RealUnsignedShortConverter; -import net.imglib2.realtransform.AffineTransform3D; -import net.imglib2.type.NativeType; -import net.imglib2.type.numeric.RealType; -import net.imglib2.type.numeric.integer.UnsignedShortType; -import net.imglib2.util.Pair; -import net.imglib2.util.Util; -import net.imglib2.util.ValuePair; -import net.preibisch.legacy.io.IOFunctions; -import net.preibisch.mvrecon.Threads; -import net.preibisch.mvrecon.fiji.plugin.fusion.FusionExportInterface; -import net.preibisch.mvrecon.fiji.plugin.queryXML.LoadParseQueryXML; -import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5; -import net.preibisch.mvrecon.fiji.plugin.resave.ProgressWriterIJ; -import net.preibisch.mvrecon.fiji.plugin.resave.Resave_HDF5; -import net.preibisch.mvrecon.fiji.plugin.resave.Generic_Resave_HDF5.Parameters; -import net.preibisch.mvrecon.fiji.spimdata.SpimData2; -import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; -import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBoxes; -import net.preibisch.mvrecon.fiji.spimdata.intensityadjust.IntensityAdjustments; -import net.preibisch.mvrecon.fiji.spimdata.interestpoints.ViewInterestPointLists; -import net.preibisch.mvrecon.fiji.spimdata.interestpoints.ViewInterestPoints; -import net.preibisch.mvrecon.fiji.spimdata.pointspreadfunctions.PointSpreadFunctions; -import net.preibisch.mvrecon.fiji.spimdata.stitchingresults.StitchingResults; -import net.preibisch.mvrecon.process.fusion.FusionTools; -import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group; - -public class ExportSpimData2HDF5 implements ImgExport -{ - private FusionExportInterface fusion; - - private List< TimePoint > newTimepoints; - - private List< ViewSetup > newViewSetups; - - private Parameters params; - - private SpimData2 spimData; - - private Map< Integer, ExportMipmapInfo > perSetupExportMipmapInfo; - - private HashMap< ViewId, Partition > viewIdToPartition; - - private final ProgressWriter progressWriter = new ProgressWriterIJ(); - - @Override - public boolean finish() - { - System.out.println( "finish()" ); - String path = params.getSeqFile().getAbsolutePath(); - try - { - new XmlIoSpimData2().save( spimData, path ); - - IOFunctions.println( "(" + new Date( System.currentTimeMillis() ) + "): Saved xml '" + path + "'." ); - - // this spimdata object was not modified, we just wrote a new one - return false; - } - catch ( SpimDataException e ) - { - IOFunctions.println( "(" + new Date( System.currentTimeMillis() ) + "): Could not save xml '" + path + "'." ); - e.printStackTrace(); - return false; - } - } - - @Override - public boolean queryParameters( final FusionExportInterface fusion ) - { - this.fusion = fusion; - - // define new timepoints and viewsetups - final Pair< List< TimePoint >, List< ViewSetup > > newStructure = ExportSpimData2TIFF.defineNewViewSetups( fusion, fusion.getDownsampling(), fusion.getAnisotropyFactor() ); - this.newTimepoints = newStructure.getA(); - this.newViewSetups = newStructure.getB(); - - System.out.println( this + " " + fusion ); - - perSetupExportMipmapInfo = Resave_HDF5.proposeMipmaps( newViewSetups ); - - String fn = LoadParseQueryXML.defaultXMLfilename; - if ( fn.endsWith( ".xml" ) ) - fn = fn.substring( 0, fn.length() - ".xml".length() ); - for ( int i = 0;; ++i ) - { - Generic_Resave_HDF5.lastExportPath = String.format( "%s-f%d.xml", fn, i ); - if ( !new File( Generic_Resave_HDF5.lastExportPath ).exists() ) - break; - } - - boolean is16bit = fusion.getPixelType() == 1; - - final int firstviewSetupId = newViewSetups.get( 0 ).getId(); - params = Generic_Resave_HDF5.getParameters( perSetupExportMipmapInfo.get( firstviewSetupId ), true, getDescription(), is16bit ); - - if ( params == null ) - { - System.out.println( "abort " ); - return false; - } - - Pair< SpimData2, HashMap< ViewId, Partition > > init = initSpimData( newTimepoints, newViewSetups, params, perSetupExportMipmapInfo ); - this.spimData = init.getA(); - viewIdToPartition = init.getB(); - - return true; - } - - protected static Pair< SpimData2, HashMap< ViewId, Partition > > initSpimData( - final List< TimePoint > newTimepoints, - final List< ViewSetup > newViewSetups, - final Parameters params, - final Map< Integer, ExportMipmapInfo > perSetupExportMipmapInfo ) - { - // SequenceDescription containing the subset of viewsetups and timepoints. Does not have an ImgLoader yet. - final SequenceDescription seq = new SequenceDescription( new TimePoints( newTimepoints ), newViewSetups, null, null ); - - // Create identity ViewRegistration for all views. - final Map< ViewId, ViewRegistration > regMap = new HashMap< ViewId, ViewRegistration >(); - for ( final ViewDescription vDesc : seq.getViewDescriptions().values() ) - regMap.put( vDesc, new ViewRegistration( vDesc.getTimePointId(), vDesc.getViewSetupId() ) ); - final ViewRegistrations viewRegistrations = new ViewRegistrations( regMap ); - - // Create empty ViewInterestPoints. - final ViewInterestPoints viewsInterestPoints = new ViewInterestPoints( new HashMap< ViewId, ViewInterestPointLists >() ); - - // base path is directory containing the XML file. - File basePath = params.getSeqFile().getParentFile(); - - ArrayList< Partition > hdf5Partitions = null; - HashMap< ViewId, Partition > viewIdToPartition = new HashMap< ViewId, Partition >(); - - if ( params.getSplit() ) - { - String basename = params.getHDF5File().getAbsolutePath(); - if ( basename.endsWith( ".h5" ) ) - basename = basename.substring( 0, basename.length() - ".h5".length() ); - hdf5Partitions = Partition.split( newTimepoints, newViewSetups, params.getTimepointsPerPartition(), params.getSetupsPerPartition(), basename ); - for ( final ViewDescription vDesc : seq.getViewDescriptions().values() ) - for ( Partition p : hdf5Partitions ) - if ( p.contains( vDesc ) ) - { - viewIdToPartition.put( vDesc, p ); - break; - } - WriteSequenceToHdf5.writeHdf5PartitionLinkFile( seq, perSetupExportMipmapInfo, hdf5Partitions, params.getHDF5File() ); - } - else - { - final HashMap< Integer, Integer > timepointIdSequenceToPartition = new HashMap< Integer, Integer >(); - for ( final TimePoint timepoint : newTimepoints ) - timepointIdSequenceToPartition.put( timepoint.getId(), timepoint.getId() ); - final HashMap< Integer, Integer > setupIdSequenceToPartition = new HashMap< Integer, Integer >(); - for ( final ViewSetup setup : newViewSetups ) - setupIdSequenceToPartition.put( setup.getId(), setup.getId() ); - final Partition partition = new Partition( params.getHDF5File().getAbsolutePath(), timepointIdSequenceToPartition, setupIdSequenceToPartition ); - for ( final ViewDescription vDesc : seq.getViewDescriptions().values() ) - viewIdToPartition.put( vDesc, partition ); - } - - seq.setImgLoader( new Hdf5ImageLoader( params.getHDF5File(), hdf5Partitions, seq, false ) ); - SpimData2 spimData = new SpimData2( basePath, seq, viewRegistrations, viewsInterestPoints, new BoundingBoxes(), new PointSpreadFunctions(), new StitchingResults(), new IntensityAdjustments() ); - - return new ValuePair< SpimData2, HashMap >( spimData, viewIdToPartition ); - } - - public static < T extends RealType< T > > double[] updateAndGetMinMax( final RandomAccessibleInterval< T > img, final Parameters params ) - { - double min, max; - - if ( params == null || params.getConvertChoice() == 0 || Double.isNaN( params.getMin() ) || Double.isNaN( params.getMin() ) ) - { - final float[] minmax = FusionTools.minMax( img ); - min = minmax[ 0 ]; - max = minmax[ 1 ]; - - min = Math.max( 0, min - ((min+max)/2.0) * 0.1 ); - max = max + ((min+max)/2.0) * 0.1; - - if ( params != null ) - { - params.setMin( min ); - params.setMax( max ); - } - } - else - { - min = params.getMin(); - max = params.getMax(); - } - - IOFunctions.println( "Min intensity for 16bit conversion: " + min ); - IOFunctions.println( "Max intensity for 16bit conversion: " + max ); - - return new double[]{ min, max }; - } - - public static < T extends RealType< T > > RandomAccessibleInterval< UnsignedShortType > convert( final RandomAccessibleInterval< T > img, final Parameters params ) - { - final double[] minmax = updateAndGetMinMax( img, params ); - - final RealUnsignedShortConverter< T > converter = new RealUnsignedShortConverter< T >( minmax[ 0 ], minmax[ 1 ] ); - - return Converters.convert( img, converter, new UnsignedShortType() ); - } - - @SuppressWarnings({ "rawtypes", "unchecked" }) - @Override - public < T extends RealType< T > & NativeType< T > > boolean exportImage( - RandomAccessibleInterval< T > img, - final Interval bb, - final double downsampling, - final double anisoF, - final String title, - final Group< ? extends ViewId > fusionGroup ) - { - System.out.println( "exportImage2()" ); - - final ViewId newViewId = ExportSpimData2TIFF.identifyNewViewId( newTimepoints, newViewSetups, fusionGroup, fusion ); - - // write the image - final RandomAccessibleInterval< UnsignedShortType > ushortimg; - if ( ! UnsignedShortType.class.isInstance( Util.getTypeFromInterval( img ) ) ) - ushortimg = convert( img, params ); - else - ushortimg = ( RandomAccessibleInterval ) img; - final Partition partition = viewIdToPartition.get( newViewId ); - final ExportMipmapInfo mipmapInfo = perSetupExportMipmapInfo.get( newViewId.getViewSetupId() ); - final boolean writeMipmapInfo = true; // TODO: remember whether we already wrote it and write only once - final boolean deflate = params.getDeflate(); - final ProgressWriter progressWriter = new SubTaskProgressWriter( this.progressWriter, 0.0, 1.0 ); // TODO - WriteSequenceToHdf5.writeViewToHdf5PartitionFile( ushortimg, partition, newViewId.getTimePointId(), newViewId.getViewSetupId(), mipmapInfo, writeMipmapInfo, deflate, null, null, Threads.numThreads(), progressWriter ); - - // update the registrations - final ViewRegistration vr = spimData.getViewRegistrations().getViewRegistration( newViewId ); - - final double scale = Double.isNaN( downsampling ) ? 1.0 : downsampling; - final double ai = Double.isNaN( anisoF ) ? 1.0 : anisoF; - - final AffineTransform3D m = new AffineTransform3D(); - m.set( scale, 0.0f, 0.0f, bb.min( 0 ), - 0.0f, scale, 0.0f, bb.min( 1 ), - 0.0f, 0.0f, scale * ai, bb.min( 2 ) * ai ); // TODO: bb * ai is right? - final ViewTransform vt = new ViewTransformAffine( "fusion bounding box", m ); - - vr.getTransformList().clear(); - vr.getTransformList().add( vt ); - - return true; - } - - @Override - public ImgExport newInstance() - { - System.out.println( "newInstance()" ); - return new ExportSpimData2HDF5(); - } - - @Override - public String getDescription() - { - System.out.println( "getDescription()" ); - return "Save as new XML Project (HDF5)"; - } - - @Override - public int[] blocksize() { return new int[] { 32, 32, 16 }; } -} diff --git a/src/main/java/net/preibisch/mvrecon/process/export/ExportSpimData2TIFF.java b/src/main/java/net/preibisch/mvrecon/process/export/ExportSpimData2TIFF.java deleted file mode 100644 index 13cf9609c..000000000 --- a/src/main/java/net/preibisch/mvrecon/process/export/ExportSpimData2TIFF.java +++ /dev/null @@ -1,395 +0,0 @@ -/*- - * #%L - * Software for the reconstruction of multi-view microscopic acquisitions - * like Selective Plane Illumination Microscopy (SPIM) Data. - * %% - * Copyright (C) 2012 - 2024 Multiview Reconstruction developers. - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as - * published by the Free Software Foundation, either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program. If not, see - * . - * #L% - */ -package net.preibisch.mvrecon.process.export; - -import java.io.File; -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import mpicbg.spim.data.SpimDataException; -import mpicbg.spim.data.generic.sequence.BasicViewDescription; -import mpicbg.spim.data.registration.ViewRegistration; -import mpicbg.spim.data.registration.ViewRegistrations; -import mpicbg.spim.data.registration.ViewTransform; -import mpicbg.spim.data.registration.ViewTransformAffine; -import mpicbg.spim.data.sequence.Angle; -import mpicbg.spim.data.sequence.Channel; -import mpicbg.spim.data.sequence.FinalVoxelDimensions; -import mpicbg.spim.data.sequence.Illumination; -import mpicbg.spim.data.sequence.MissingViews; -import mpicbg.spim.data.sequence.SequenceDescription; -import mpicbg.spim.data.sequence.Tile; -import mpicbg.spim.data.sequence.TimePoint; -import mpicbg.spim.data.sequence.TimePoints; -import mpicbg.spim.data.sequence.TimePointsPattern; -import mpicbg.spim.data.sequence.ViewDescription; -import mpicbg.spim.data.sequence.ViewId; -import mpicbg.spim.data.sequence.ViewSetup; -import net.imglib2.Interval; -import net.imglib2.RandomAccessibleInterval; -import net.imglib2.realtransform.AffineTransform3D; -import net.imglib2.type.NativeType; -import net.imglib2.type.numeric.RealType; -import net.imglib2.util.Pair; -import net.imglib2.util.ValuePair; -import net.preibisch.legacy.io.IOFunctions; -import net.preibisch.mvrecon.fiji.plugin.fusion.FusionExportInterface; -import net.preibisch.mvrecon.fiji.plugin.resave.Resave_TIFF; -import net.preibisch.mvrecon.fiji.plugin.resave.Resave_TIFF.ParametersResaveAsTIFF; -import net.preibisch.mvrecon.fiji.spimdata.SpimData2; -import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; -import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBoxes; -import net.preibisch.mvrecon.fiji.spimdata.imgloaders.FileMapImgLoaderLOCI; -import net.preibisch.mvrecon.fiji.spimdata.intensityadjust.IntensityAdjustments; -import net.preibisch.mvrecon.fiji.spimdata.interestpoints.ViewInterestPointLists; -import net.preibisch.mvrecon.fiji.spimdata.interestpoints.ViewInterestPoints; -import net.preibisch.mvrecon.fiji.spimdata.pointspreadfunctions.PointSpreadFunctions; -import net.preibisch.mvrecon.fiji.spimdata.stitchingresults.StitchingResults; -import net.preibisch.mvrecon.process.interestpointregistration.pairwise.constellation.grouping.Group; -import util.URITools; - -public class ExportSpimData2TIFF implements ImgExport -{ - File path; - List< TimePoint > newTimepoints; - List< ViewSetup > newViewSetups; - FusionExportInterface fusion; - HashMap, Pair>> fileMap = new HashMap<>(); - - ParametersResaveAsTIFF params; - Save3dTIFF saver; - SpimData2 newSpimData; - - @Override - public < T extends RealType< T > & NativeType< T > > boolean exportImage( - final RandomAccessibleInterval img, - final Interval bb, - final double downsampling, - final double anisoF, - final String title, - final Group< ? extends ViewId > fusionGroup ) - { - // write the image - if ( !this.saver.exportImage( img, bb, downsampling, anisoF, title, fusionGroup ) ) - return false; - - final ViewId newViewId = identifyNewViewId( newTimepoints, newViewSetups, fusionGroup, fusion ); - final ViewDescription newVD = newSpimData.getSequenceDescription().getViewDescription( newViewId ); - - // populate HashMap for the ImgLoader - fileMap.put( newVD, new ValuePair< File, Pair >( new File( saver.getFileName( title ) ), new ValuePair<>( 0, 0 ) ) ); - - // update the registrations - final ViewRegistration vr = newSpimData.getViewRegistrations().getViewRegistration( newViewId ); - - final double scale = Double.isNaN( downsampling ) ? 1.0 : downsampling; - final double ai = Double.isNaN( anisoF ) ? 1.0 : anisoF; - - final AffineTransform3D m = new AffineTransform3D(); - m.set( scale, 0.0f, 0.0f, bb.min( 0 ), - 0.0f, scale, 0.0f, bb.min( 1 ), - 0.0f, 0.0f, scale * ai, bb.min( 2 ) * ai ); // TODO: bb * ai is right? - final ViewTransform vt = new ViewTransformAffine( "fusion bounding box", m ); - - vr.getTransformList().clear(); - vr.getTransformList().add( vt ); - - return true; - } - - @Override - public boolean finish() - { - final FileMapImgLoaderLOCI imgLoader = new FileMapImgLoaderLOCI( fileMap, newSpimData.getSequenceDescription() ); - - newSpimData.getSequenceDescription().setImgLoader( imgLoader ); - - final XmlIoSpimData2 io = new XmlIoSpimData2(); - - try - { - io.save( newSpimData, new File( URITools.removeFilePrefix( params.getXMLPath() ) ).getAbsolutePath() ); - - IOFunctions.println( "(" + new Date( System.currentTimeMillis() ) + "): Saved xml '" + io.lastURI() + "'." ); - - // this spimdata object was not modified, we just wrote a new one - return false; - } - catch ( SpimDataException e ) - { - IOFunctions.println( "(" + new Date( System.currentTimeMillis() ) + "): Could not save xml '" + io.lastURI() + "'." ); - e.printStackTrace(); - return false; - } - } - - @Override - public boolean queryParameters( final FusionExportInterface fusion ) - { - if ( Resave_TIFF.defaultPath == null ) - Resave_TIFF.defaultPath = ""; - - this.params = Resave_TIFF.getParameters(); - - if ( this.params == null ) - return false; - - this.path = new File( new File( URITools.removeFilePrefix( params.getXMLPath() ) ).getParent() ); - this.saver = new Save3dTIFF( this.path.toString(), this.params.compress() ); - - // define new timepoints and viewsetups - final Pair< List< TimePoint >, List< ViewSetup > > newStructure = defineNewViewSetups( fusion, fusion.getDownsampling(), fusion.getAnisotropyFactor() ); - this.newTimepoints = newStructure.getA(); - this.newViewSetups = newStructure.getB(); - - this.fusion = fusion; // we need it later to find the right new ViewId for a FusionGroup - this.newSpimData = createSpimData2( newTimepoints, newViewSetups, params ); - - return true; - } - - @Override - public ImgExport newInstance() { return new ExportSpimData2TIFF(); } - - @Override - public String getDescription() { return "Save as new XML Project (TIFF)"; } - - @Override - public int[] blocksize() { return new int[] { 128, 128, 1}; } - - public static ViewId identifyNewViewId( - final List< TimePoint > newTimepoints, - final List< ViewSetup > newViewSetups, - final Group< ? extends ViewId > fusionGroup, - final FusionExportInterface fusion ) - { - if ( fusion.getSplittingType() == 0 ) // "Each timepoint & channel" - { - final ViewDescription old = fusion.getSpimData().getSequenceDescription().getViewDescription( fusionGroup.iterator().next() ); - - TimePoint tpNew = old.getTimePoint(); // stays the same - ViewSetup vsNew = null; - - final int oc = old.getViewSetup().getChannel().getId(); - - for ( final ViewSetup vs : newViewSetups ) - if ( vs.getChannel().getId() == oc ) - vsNew = vs; - - return new ViewId( tpNew.getId(), vsNew.getId() ); - } - else if ( fusion.getSplittingType() == 1 ) // "Each timepoint, channel & illumination" - { - final ViewDescription old = fusion.getSpimData().getSequenceDescription().getViewDescription( fusionGroup.iterator().next() ); - - TimePoint tpNew = old.getTimePoint(); // stays the same - ViewSetup vsNew = null; - - final int oc = old.getViewSetup().getChannel().getId(); - final int oi = old.getViewSetup().getIllumination().getId(); - - for ( final ViewSetup vs : newViewSetups ) - if ( vs.getChannel().getId() == oc && vs.getIllumination().getId() == oi ) - vsNew = vs; - - return new ViewId( tpNew.getId(), vsNew.getId() ); - } - else if ( fusion.getSplittingType() == 2 ) // "All views together" - { - return new ViewId( 0, 0 ); - } - else if ( fusion.getSplittingType() == 3 ) // "Each view" - { - return fusion.getSpimData().getSequenceDescription().getViewDescription( fusionGroup.iterator().next() ); - } - else - { - throw new RuntimeException( "SplittingType " + fusion.getSplittingType() + " unknown." ); - } - } - - public static Pair< List< TimePoint >, List< ViewSetup > > defineNewViewSetups( final FusionExportInterface fusion, double downsampling, double anisoF ) - { - final List< ViewSetup > newViewSetups = new ArrayList<>(); - final List< TimePoint > newTimepoints; - - int newViewSetupId = 0; - - downsampling = Double.isNaN( downsampling ) ? 1.0 : downsampling; - anisoF = Double.isNaN( anisoF ) ? 1.0 : anisoF; - - if ( fusion.getSplittingType() < 2 ) // "Each timepoint & channel" or "Each timepoint, channel & illumination" - { - newTimepoints = SpimData2.getAllTimePointsSorted( fusion.getSpimData(), fusion.getViews() ); - - final List< Channel > channels = SpimData2.getAllChannelsSorted( fusion.getSpimData(), fusion.getViews() ); - - if ( fusion.getSplittingType() == 0 )// "Each timepoint & channel" - { - for ( final Channel c : channels ) - newViewSetups.add( - new ViewSetup( - newViewSetupId++, - c.getName(), - fusion.getDownsampledBoundingBox(), - new FinalVoxelDimensions( "px", new double[] { downsampling, downsampling, downsampling * anisoF } ), - new Tile( 0 ), - c, - new Angle( 0 ), - new Illumination( 0 ) ) ); - } - else // "Each timepoint, channel & illumination" - { - final List< Illumination > illums = SpimData2.getAllIlluminationsSorted( fusion.getSpimData(), fusion.getViews() ); - - for ( int c = 0; c < channels.size(); ++c ) - for ( int i = 0; i < illums.size(); ++i ) - newViewSetups.add( - new ViewSetup( - newViewSetupId++, - channels.get( c ).getName() + "_" + illums.get( i ).getName(), - fusion.getDownsampledBoundingBox(), - new FinalVoxelDimensions( "px", new double[] { downsampling, downsampling, downsampling * anisoF } ), - new Tile( 0 ), - channels.get( c ), - new Angle( 0 ), - illums.get( i ) ) ); - } - } - else if ( fusion.getSplittingType() == 2 ) // "All views together" - { - newTimepoints = new ArrayList<>(); - newTimepoints.add( new TimePoint( 0 ) ); - - newViewSetups.add( - new ViewSetup( - 0, - "Fused", - fusion.getDownsampledBoundingBox(), - new FinalVoxelDimensions( "px", new double[] { downsampling, downsampling, downsampling * anisoF } ), - new Tile( 0 ), - new Channel( 0 ), - new Angle( 0 ), - new Illumination( 0 ) ) ); - } - else if ( fusion.getSplittingType() == 3 ) // "Each view" - { - newTimepoints = new ArrayList<>(); - for ( final TimePoint tp : SpimData2.getAllTimePointsSorted( fusion.getSpimData(), fusion.getViews() ) ) - newTimepoints.add( tp ); - - for ( final ViewSetup vs : SpimData2.getAllViewSetupsSorted( fusion.getSpimData(), fusion.getViews() ) ) - { - newViewSetups.add( - new ViewSetup( - vs.getId(), - vs.getName(), - fusion.getDownsampledBoundingBox(), - new FinalVoxelDimensions( "px", new double[] { downsampling, downsampling, downsampling * anisoF } ), - vs.getTile(), - vs.getChannel(), - vs.getAngle(), - vs.getIllumination() ) ); - } - } - else - { - throw new RuntimeException( "SplittingType " + fusion.getSplittingType() + " unknown." ); - } - - return new ValuePair< List< TimePoint >, List< ViewSetup > >( newTimepoints, newViewSetups ); - } - - protected SpimData2 createSpimData2( - final List< TimePoint > timepointsToProcess, - final List< ViewSetup > viewSetupsToProcess, - final ParametersResaveAsTIFF params ) - { - // Assemble a new SpimData object containing the subset of viewsetups and timepoints - return assembleSpimData2( timepointsToProcess, viewSetupsToProcess, new File( URITools.removeFilePrefix( params.getXMLPath() ) ).getParentFile() ); - } - - /** - * Assembles a new SpimData2 based on the timepoints and viewsetups. - * The imgloader is still not set here. - * @param timepointsToProcess TimePoints to process - * @param viewSetupsToProcess ViewSetups to process - * @param basePath the base path - * @return the new SpimData2 - */ - public static SpimData2 assembleSpimData2( - final List< TimePoint > timepointsToProcess, - final List< ViewSetup > viewSetupsToProcess, - final File basePath ) - { - final TimePoints timepoints; - - try - { - timepoints = new TimePointsPattern( Resave_TIFF.listAllTimePoints( timepointsToProcess ) ); - } - catch (ParseException e) - { - IOFunctions.println( "Automatically created list of timepoints failed to parse. This should not happen, really :) -- " + e ); - IOFunctions.println( "Here is the list: " + Resave_TIFF.listAllTimePoints( timepointsToProcess ) ); - e.printStackTrace(); - return null; - } - - final MissingViews missingViews = new MissingViews( new ArrayList< ViewId >() ); - - // instantiate the sequencedescription - final SequenceDescription sequenceDescription = new SequenceDescription( timepoints, viewSetupsToProcess, null, missingViews ); - - // assemble the viewregistrations - final Map< ViewId, ViewRegistration > regMap = new HashMap< ViewId, ViewRegistration >(); - - for ( final ViewDescription vDesc : sequenceDescription.getViewDescriptions().values() ) - { - final ViewRegistration viewRegistration = new ViewRegistration( vDesc.getTimePointId(), vDesc.getViewSetupId() ); - viewRegistration.identity(); - regMap.put( viewRegistration, viewRegistration ); - } - - final ViewRegistrations viewRegistrations = new ViewRegistrations( regMap ); - - // assemble the interestpoints and a list of filenames to copy - final ViewInterestPoints viewsInterestPoints = new ViewInterestPoints( new HashMap< ViewId, ViewInterestPointLists >() ); - - final SpimData2 newSpimData = new SpimData2( - basePath, - sequenceDescription, - viewRegistrations, - viewsInterestPoints, - new BoundingBoxes(), - new PointSpreadFunctions(), - new StitchingResults(), - new IntensityAdjustments() ); - - return newSpimData; - } -} diff --git a/src/main/java/net/preibisch/mvrecon/process/splitting/SplittingTools.java b/src/main/java/net/preibisch/mvrecon/process/splitting/SplittingTools.java index d04619cd4..794320463 100644 --- a/src/main/java/net/preibisch/mvrecon/process/splitting/SplittingTools.java +++ b/src/main/java/net/preibisch/mvrecon/process/splitting/SplittingTools.java @@ -446,7 +446,7 @@ else if ( MultiResolutionImgLoader.class.isInstance( underlyingImgLoader ) ) // TODO: fix intensity adjustments? // finally create the SpimData itself based on the sequence description and the view registration - final SpimData2 spimDataNew = new SpimData2( spimData.getBasePath(), sequenceDescription, viewRegistrations, viewInterestPoints, spimData.getBoundingBoxes(), psfs, new StitchingResults(), new IntensityAdjustments() ); + final SpimData2 spimDataNew = new SpimData2( spimData.getBasePathURI(), sequenceDescription, viewRegistrations, viewInterestPoints, spimData.getBoundingBoxes(), psfs, new StitchingResults(), new IntensityAdjustments() ); return spimDataNew; }