From d4d7f3865dcaf9b14e7e32721a7bb3411a554289 Mon Sep 17 00:00:00 2001 From: Stephan Preibisch Date: Tue, 2 Jul 2024 17:20:14 -0300 Subject: [PATCH] support multiple fusion methods (AVG, MAX, FIRST TILE WINS) throughout the application --- .../mvrecon/fiji/plugin/Image_Fusion.java | 6 +-- .../mvrecon/fiji/plugin/fusion/FusionGUI.java | 34 ++++++------ .../fusion/ManageFusionDialogListeners.java | 14 ++--- .../interactive/MultiResolutionSource.java | 7 ++- .../interactive/MultiResolutionTools.java | 34 +++++++----- .../DifferenceOfGUI.java | 4 +- .../popup/DisplayFusedImagesPopup.java | 6 +-- .../explorer/popup/VisualizeNonRigid.java | 15 +++--- .../boundingbox/TestRealDataBoundingBox.java | 3 +- .../headless/fusion/OpenSeaDragonExport.java | 8 +-- .../mvrecon/headless/fusion/TestFusion.java | 2 + .../fusion/TestIntensityAdjustment.java | 5 +- .../mvrecon/headless/fusion/TestNonRigid.java | 8 ++- .../BoundingBoxMinFilterThreshold.java | 3 +- .../FusedNonZeroRandomAccessibleInterval.java | 2 +- .../util/ProcessInputImages.java | 4 +- .../mvrecon/process/fusion/FusionTools.java | 54 +++++++++++++------ .../process/fusion/lazy/LazyAffineFusion.java | 25 ++++----- .../fusion/lazy/LazyNonRigidFusion.java | 36 +++++++------ .../FusedRandomAccessibleInterval.java | 4 +- .../transformed/nonrigid/NonRigidTools.java | 40 ++++++++------ .../mvrecon/process/quality/FRCTools.java | 3 +- 22 files changed, 176 insertions(+), 141 deletions(-) diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/Image_Fusion.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/Image_Fusion.java index 449c66234..d38a31436 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/Image_Fusion.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/Image_Fusion.java @@ -209,8 +209,7 @@ else if ( fusion.getPixelType() == 1 ) group.getViews(), viewsToUse, fusion.getNonRigidParameters().getLabels(), - fusion.useBlending(), - fusion.useContentBased(), + fusion.getFusionType(), fusion.getNonRigidParameters().showDistanceMap(), Util.getArrayFromValue( fusion.getNonRigidParameters().getControlPointDistance(), 3 ), fusion.getNonRigidParameters().getAlpha(), @@ -252,8 +251,7 @@ else if ( fusion.getPixelType() == 1 ) group.getViews(), registrations, spimData.getSequenceDescription().getViewDescriptions(), - fusion.useBlending(), // blending - fusion.useContentBased(), // content based + fusion.getFusionType(), fusion.getInterpolation(), // linear interpolatio fusion.adjustIntensities() ? spimData.getIntensityAdjustments().getIntensityAdjustments() : null, fusion.getBoundingBox(), diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/FusionGUI.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/FusionGUI.java index 593ad9567..1f015ca8f 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/FusionGUI.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/FusionGUI.java @@ -80,6 +80,10 @@ public class FusionGUI implements FusionExportInterface public static String[] interpolationTypes = new String[]{ "Nearest Neighbor", "Linear Interpolation" }; public static int defaultInterpolation = 1; + public enum FusionType { AVG, AVG_BLEND, AVG_CONTENT, AVG_BLEND_CONTENT, MAX, FIRST } + public static String[] fusionTypes = new String[]{ "Avg", "Avg, Blending", "Avg, Content Based", "Avg, Blending & Content Based", "Max intensity", "First Tile Wins (lowest ViewSetupId)" }; + public static int defaultFusionType = 1; + public static String[] pixelTypes1 = new String[]{ "32-bit floating point", "16-bit unsigned integer", "8-bit unsigned integer" }; public static int defaultPixelType = 0; @@ -95,8 +99,6 @@ public class FusionGUI implements FusionExportInterface public static int defaultSplittingType = 0; - public static boolean defaultUseBlending = true; - public static boolean defaultUseContentBased = false; public static boolean defaultAdjustIntensities = false; public static boolean defaultPreserveAnisotropy = false; @@ -110,11 +112,9 @@ public class FusionGUI implements FusionExportInterface protected int defineMinMax = defaultDefineMinMax; protected double min = defaultMin; protected double max = defaultMax; - //protected int cacheType = defaultCache; protected int splittingType = defaultSplittingType; protected double downsampling = defaultDownsampling; - protected boolean useBlending = defaultUseBlending; - protected boolean useContentBased = defaultUseContentBased; + protected int fusionType = defaultFusionType; protected boolean adjustIntensities = defaultAdjustIntensities; protected boolean preserveAnisotropy = defaultPreserveAnisotropy; protected double avgAnisoF; @@ -206,9 +206,7 @@ public Interval getDownsampledBoundingBox() @Override public double getDownsampling(){ return downsampling; } - public boolean useBlending() { return useBlending; } - - public boolean useContentBased() { return useContentBased; } + public FusionType getFusionType() { return FusionType.values()[ fusionType ]; } public boolean adjustIntensities() { return adjustIntensities; } @@ -292,7 +290,7 @@ public boolean queryDetails() final boolean enableNonRigid = NonRigidParametersGUI.enableNonRigid; final Choice boundingBoxChoice, pixelTypeChoice, /*cachingChoice, */nonrigidChoice, splitChoice; final TextField downsampleField; - final Checkbox contentbasedCheckbox, anisoCheckbox; + final Checkbox anisoCheckbox; final String[] choices = FusionGUI.getBoundingBoxChoices( allBoxes ); final String[] choicesForMacro = FusionGUI.getBoundingBoxChoices( allBoxes, false ); @@ -317,6 +315,8 @@ public boolean queryDetails() gd.addChoice( "Interpolation", interpolationTypes, interpolationTypes[ defaultInterpolation ] ); + gd.addChoice( "Fusion_type", fusionTypes, fusionTypes[ defaultFusionType ] ); + gd.addChoice( "Pixel_type", pixelTypes1, pixelTypes1[ defaultPixelType ] ); pixelTypeChoice = PluginHelper.isHeadless() ? null : (Choice)gd.getChoices().lastElement(); //gd.addCheckbox( "Manually_define_min_max intensity for fusion (only relevant for 16-bit)", defaultDefineMinMax ); @@ -338,9 +338,9 @@ public boolean queryDetails() nonrigidChoice = null; } - gd.addCheckbox( "Blend images smoothly", defaultUseBlending ); - gd.addCheckbox( "Use content based fusion (warning, slow)", defaultUseContentBased ); - contentbasedCheckbox = PluginHelper.isHeadless() ? null : (Checkbox)gd.getCheckboxes().lastElement(); + //gd.addCheckbox( "Blend images smoothly", defaultUseBlending ); + //gd.addCheckbox( "Use content based fusion (warning, slow)", defaultUseContentBased ); + //contentbasedCheckbox = PluginHelper.isHeadless() ? null : (Checkbox)gd.getCheckboxes().lastElement(); if ( hasIntensityAdjustments ) gd.addCheckbox( "Adjust_image_intensities (only use with 32-bit output)", defaultAdjustIntensities ); @@ -378,7 +378,7 @@ public boolean queryDetails() pixelTypeChoice, //cachingChoice, nonrigidChoice, - contentbasedCheckbox, + //contentbasedCheckbox, anisoCheckbox, splitChoice, label1, @@ -414,6 +414,7 @@ public boolean queryDetails() downsampling = Double.NaN; interpolation = defaultInterpolation = gd.getNextChoiceIndex(); + fusionType = defaultFusionType = gd.getNextChoiceIndex(); pixelType = defaultPixelType = gd.getNextChoiceIndex(); //defineMinMax = defaultDefineMinMax = gd.getNextBoolean(); //cacheType = defaultCache = gd.getNextChoiceIndex(); @@ -424,8 +425,6 @@ public boolean queryDetails() return false; } - useBlending = defaultUseBlending = gd.getNextBoolean(); - useContentBased = defaultUseContentBased = gd.getNextBoolean(); if ( hasIntensityAdjustments ) adjustIntensities = defaultAdjustIntensities = gd.getNextBoolean(); else @@ -465,6 +464,7 @@ public boolean queryDetails() IOFunctions.println( "BoundingBox: " + getBoundingBox() ); IOFunctions.println( "DownsampledBoundingBox: " + getDownsampledBoundingBox() ); IOFunctions.println( "PixelType: " + pixelTypes1[ getPixelType() ] ); + IOFunctions.println( "FusionType: " + fusionTypes[ getFusionType().ordinal() ] ); IOFunctions.println( "Manually defined min/max: " + manuallyDefinedMinMax() ); if ( manuallyDefinedMinMax() ) { IOFunctions.println( "Min: " + minIntensity() ); @@ -472,9 +472,9 @@ public boolean queryDetails() } IOFunctions.println( "Interpolation: " + interpolationTypes[ getInterpolation() ] ); //IOFunctions.println( "CacheType: " + FusionTools.imgDataTypeChoice[ getCacheType() ] ); - IOFunctions.println( "Blending: " + useBlending ); + //IOFunctions.println( "Blending: " + useBlending ); IOFunctions.println( "Adjust intensities: " + adjustIntensities ); - IOFunctions.println( "Content-based: " + useContentBased ); + //IOFunctions.println( "Content-based: " + useContentBased ); IOFunctions.println( "AnisotropyFactor: " + avgAnisoF ); IOFunctions.println( "Split by: " + splittingTypes[ getSplittingType() ] ); IOFunctions.println( "Image Export: " + imgExportDescriptions[ imgExport ] ); diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/ManageFusionDialogListeners.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/ManageFusionDialogListeners.java index 7893e0813..f943a4bdb 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/ManageFusionDialogListeners.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/fusion/ManageFusionDialogListeners.java @@ -42,7 +42,7 @@ public class ManageFusionDialogListeners final GenericDialog gd; final TextField downsampleField; final Choice boundingBoxChoice, pixelTypeChoice, /*cachingChoice, */nonRigidChoice, splitChoice; - final Checkbox contentbasedCheckbox, anisoCheckbox; + final Checkbox anisoCheckbox; final Label label1; final Label label2; final FusionGUI fusion; @@ -56,7 +56,7 @@ public ManageFusionDialogListeners( final Choice pixelTypeChoice, //final Choice cachingChoice, final Choice nonRigidChoice, - final Checkbox contentbasedCheckbox, + //final Checkbox contentbasedCheckbox, final Checkbox anisoCheckbox, final Choice splitChoice, final Label label1, @@ -69,7 +69,7 @@ public ManageFusionDialogListeners( this.pixelTypeChoice = pixelTypeChoice; //this.cachingChoice = cachingChoice; this.nonRigidChoice = nonRigidChoice; - this.contentbasedCheckbox = contentbasedCheckbox; + //this.contentbasedCheckbox = contentbasedCheckbox; this.anisoCheckbox = anisoCheckbox; this.splitChoice = splitChoice; this.label1 = label1; @@ -95,8 +95,8 @@ public ManageFusionDialogListeners( this.splitChoice.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { update(); } }); - this.contentbasedCheckbox.addItemListener( new ItemListener() { @Override - public void itemStateChanged(ItemEvent e) { update(); } }); + //this.contentbasedCheckbox.addItemListener( new ItemListener() { @Override + // public void itemStateChanged(ItemEvent e) { update(); } }); if ( this.anisoCheckbox != null ) { @@ -112,7 +112,7 @@ public void update() fusion.downsampling = Integer.parseInt( downsampleField.getText() ); fusion.pixelType = pixelTypeChoice.getSelectedIndex(); //fusion.cacheType = cachingChoice.getSelectedIndex(); - fusion.useContentBased = contentbasedCheckbox.getState(); + //fusion.useContentBased = contentbasedCheckbox.getState(); fusion.splittingType = splitChoice.getSelectedIndex(); if ( anisoCheckbox != null ) { @@ -186,6 +186,7 @@ public long totalRAM( long fusedSizeMB, final int bytePerPixel ) long processingMB = 0; + /* if ( fusion.useContentBased ) { if ( fusion.isMultiResolution() ) @@ -193,6 +194,7 @@ public long totalRAM( long fusedSizeMB, final int bytePerPixel ) else processingMB = ( maxNumPixelsInput / Math.round( inputDownSampling * 1024*1024 ) ) * 4; } + */ /*if ( fusion.cacheType == 0 ) // Virtual fusedSizeMB /= Math.max( 1, Math.round( Math.pow( fusedSizeMB, 0.3 ) ) ); diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/interactive/MultiResolutionSource.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/interactive/MultiResolutionSource.java index afb042561..c79f3e727 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/interactive/MultiResolutionSource.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/interactive/MultiResolutionSource.java @@ -49,6 +49,7 @@ import net.imglib2.util.Pair; import net.imglib2.view.Views; import net.preibisch.legacy.io.IOFunctions; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBox; @@ -181,8 +182,7 @@ public static void main( String[] args ) throws SpimDataException final long cpd = 10; final double alpha = 1.0; - final boolean useBlending = true; - final boolean useContentBased = false; + final FusionType fusionType = FusionType.AVG_BLEND; final boolean displayDistances = false; final ExecutorService service = DeconViews.createExecutorService(); @@ -193,8 +193,7 @@ public static void main( String[] args ) throws SpimDataException viewsToFuse, viewsToUse, labels, - useBlending, - useContentBased, + fusionType, displayDistances, cpd, alpha, diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/interactive/MultiResolutionTools.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/interactive/MultiResolutionTools.java index 62c0ef914..4b3a93ee4 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/interactive/MultiResolutionTools.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/interactive/MultiResolutionTools.java @@ -50,12 +50,14 @@ import net.imglib2.util.ValuePair; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.interestpoints.ViewInterestPointLists; import net.preibisch.mvrecon.process.fusion.FusionTools; import net.preibisch.mvrecon.process.fusion.lazy.LazyFusionTools; import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval; import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual; +import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval.Fusion; import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.CorrespondingIP; import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.NonRigidTools; import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.SimpleReferenceIP; @@ -83,7 +85,7 @@ public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTran final int maxDS, final int dsInc ) { - return createMultiResolutionNonRigid( spimData, viewsToFuse, viewsToUse, labels, true, false, false, controlPointDistance, 1.0, 1, boundingBox, null, service, minDS, maxDS, dsInc ); + return createMultiResolutionNonRigid( spimData, viewsToFuse, viewsToUse, labels, FusionType.AVG_BLEND, false, controlPointDistance, 1.0, 1, boundingBox, null, service, minDS, maxDS, dsInc ); } public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTransform3D > > createMultiResolutionNonRigid( @@ -91,8 +93,7 @@ public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTran final Collection< ? extends ViewId > viewsToFuse, final Collection< ? extends ViewId > viewsToUse, final ArrayList< String > labels, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final boolean displayDistances, final long controlPointDistance, final double alpha, @@ -124,7 +125,7 @@ public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTran final Map< ViewId, ? extends BasicViewDescription< ? > > viewDescriptions = spimData.getSequenceDescription().getViewDescriptions(); - return createMultiResolutionNonRigid( imgLoader, viewRegistrations, spimData.getViewInterestPoints().getViewInterestPoints(), viewDescriptions, viewsToFuse, viewsToUse, labels, useBlending, useContentBased, displayDistances, controlPointDistance, alpha, interpolation, boundingBox, intensityAdjustments, service, minDS, maxDS, dsInc ); + return createMultiResolutionNonRigid( imgLoader, viewRegistrations, spimData.getViewInterestPoints().getViewInterestPoints(), viewDescriptions, viewsToFuse, viewsToUse, labels, fusionType, displayDistances, controlPointDistance, alpha, interpolation, boundingBox, intensityAdjustments, service, minDS, maxDS, dsInc ); } public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTransform3D > > createMultiResolutionNonRigid( @@ -135,8 +136,7 @@ public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTran final Collection< ? extends ViewId > viewsToFuse, final Collection< ? extends ViewId > viewsToUse, final ArrayList< String > labels, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final boolean displayDistances, final long controlPointDistance, final double alpha, @@ -194,14 +194,22 @@ public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTran downsampledRegistrations, nonrigidGrids, bbDS, - useBlending, - useContentBased, + fusionType, displayDistances, interpolation, intensityAdjustments, NonRigidTools.defaultOverlapExpansion( uniquePointsData.getB() ) ); - multiRes.add( new ValuePair<>( new FusedRandomAccessibleInterval( FusionTools.getFusedZeroMinInterval( bbDS ), virtual.getA(), virtual.getB() ), bbTransform ) ); + final Fusion fusion; + + if ( fusionType == FusionType.AVG || fusionType == FusionType.AVG_BLEND || fusionType == FusionType.AVG_BLEND_CONTENT || fusionType == FusionType.AVG_CONTENT ) + fusion = Fusion.AVG; + else if ( fusionType == FusionType.MAX ) + fusion = Fusion.MAX; + else + fusion = Fusion.FIRST_WINS; + + multiRes.add( new ValuePair<>( new FusedRandomAccessibleInterval( FusionTools.getFusedZeroMinInterval( bbDS ), fusion, virtual.getA(), virtual.getB() ), bbTransform ) ); } return multiRes; @@ -228,7 +236,7 @@ public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTran spimData.getSequenceDescription().getImgLoader(), registrations, spimData.getSequenceDescription().getViewDescriptions(), - viewIds, true, false, 1, boundingBox, null, minDS, maxDS, dsInc ); + viewIds, FusionType.AVG_BLEND, 1, boundingBox, null, minDS, maxDS, dsInc ); } public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTransform3D > > createMultiResolutionAffine( @@ -236,8 +244,7 @@ public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTran final Map< ViewId, AffineTransform3D > registrations, final Map< ViewId, ? extends BasicViewDescription< ? > > viewDescriptions, final Collection< ? extends ViewId > views, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final int interpolation, final Interval boundingBox, final Map< ? extends ViewId, AffineModel1D > intensityAdjustments, @@ -268,8 +275,7 @@ public static ArrayList< Pair< RandomAccessibleInterval< FloatType >, AffineTran registrationsAdjusted, viewDescriptions, views, - useBlending, - useContentBased, + fusionType, interpolation, pair.getA(), // bounding box intensityAdjustments ), diff --git a/src/main/java/net/preibisch/mvrecon/fiji/plugin/interestpointdetection/DifferenceOfGUI.java b/src/main/java/net/preibisch/mvrecon/fiji/plugin/interestpointdetection/DifferenceOfGUI.java index 630a50b03..22fd95463 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/plugin/interestpointdetection/DifferenceOfGUI.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/plugin/interestpointdetection/DifferenceOfGUI.java @@ -53,6 +53,7 @@ import net.imglib2.util.Util; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.plugin.util.GUIHelper; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.ViewSetupUtils; @@ -693,8 +694,7 @@ protected ImagePlus getGroupedImagePlusForInteractive( final String dialogHeader registrationsAdjusted, viewDescriptions, group.getViews(), - DisplayFusedImagesPopup.defaultUseBlending, - false, + FusionType.FIRST, DisplayFusedImagesPopup.defaultInterpolation, bbDS, null ); diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/DisplayFusedImagesPopup.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/DisplayFusedImagesPopup.java index 88397dc42..1a7a1cf04 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/DisplayFusedImagesPopup.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/DisplayFusedImagesPopup.java @@ -46,6 +46,7 @@ import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.real.FloatType; import net.preibisch.legacy.io.IOFunctions; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.plugin.util.MouseOverPopUpStateChanger; import net.preibisch.mvrecon.fiji.plugin.util.MouseOverPopUpStateChanger.StateChanger; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; @@ -67,7 +68,7 @@ public class DisplayFusedImagesPopup extends JMenu implements ExplorerWindowSeta public static int maxCacheSize = 100000; public static int defaultInterpolation = 1; - public static boolean defaultUseBlending = true; + public static FusionType defaultFusionType = FusionType.AVG_BLEND; private static final long serialVersionUID = -4895470813542722644L; @@ -219,8 +220,7 @@ public void run() views, registrations, spimData.getSequenceDescription().getViewDescriptions(), - defaultUseBlending, // blending - false, // content based + defaultFusionType, // blending defaultInterpolation, // linear interpolatio null, bbDS, diff --git a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/VisualizeNonRigid.java b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/VisualizeNonRigid.java index dd2925acd..ae00f9fcc 100644 --- a/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/VisualizeNonRigid.java +++ b/src/main/java/net/preibisch/mvrecon/fiji/spimdata/explorer/popup/VisualizeNonRigid.java @@ -51,6 +51,7 @@ import net.imglib2.util.Pair; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.plugin.fusion.NonRigidParametersGUI; import net.preibisch.mvrecon.fiji.plugin.interactive.MultiResolutionSource; import net.preibisch.mvrecon.fiji.plugin.interactive.MultiResolutionTools; @@ -171,8 +172,7 @@ public void run() NonRigidTools.assembleViewsToUse( spimData, viewIds, params.nonRigidAcrossTime() ); final int interpolation = 1; - final boolean useBlending = true; - final boolean useContentBased = false; + final FusionType fusionType = FusionType.AVG_BLEND; final ExecutorService service = DeconViews.createExecutorService(); @@ -182,8 +182,7 @@ public void run() viewsToFuse, viewsToUse, params.getLabels(), - useBlending, - useContentBased, + fusionType, params.showDistanceMap(), params.getControlPointDistance(), params.getAlpha(), @@ -235,7 +234,7 @@ MultiResolutionTools. createMultiResolutionAffine( spimData.getSequenceDescription().getImgLoader(), registrations, spimData.getSequenceDescription().getViewDescriptions(), - viewIds, true, false, 1, boundingBox, null, minDS, maxDS, dsInc ); + viewIds, FusionType.AVG_BLEND, 1, boundingBox, null, minDS, maxDS, dsInc ); BdvOptions options = Bdv.options().numSourceGroups( 2 ).frameTitle( "Affine (magenta) vs. Previous Affine (green)" ); BdvStackSource< ? > affine = BdvFunctions.show( new MultiResolutionSource( MultiResolutionTools.createVolatileRAIs( multiResAffine ), "affine" ), options ); @@ -266,8 +265,7 @@ else if ( display == 2 ) viewsToFuse.add( viewId ); final int interpolation = 1; - final boolean useBlending = true; - final boolean useContentBased = false; + final FusionType fusionType = FusionType.AVG_BLEND; final ExecutorService service = DeconViews.createExecutorService(); @@ -277,8 +275,7 @@ else if ( display == 2 ) viewsToFuse, viewsToUse, params.getLabels(), - useBlending, - useContentBased, + fusionType, params.showDistanceMap(), params.getControlPointDistance(), params.getAlpha(), diff --git a/src/main/java/net/preibisch/mvrecon/headless/boundingbox/TestRealDataBoundingBox.java b/src/main/java/net/preibisch/mvrecon/headless/boundingbox/TestRealDataBoundingBox.java index 7454f62e5..55f590163 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/boundingbox/TestRealDataBoundingBox.java +++ b/src/main/java/net/preibisch/mvrecon/headless/boundingbox/TestRealDataBoundingBox.java @@ -34,6 +34,7 @@ import net.imglib2.type.numeric.real.FloatType; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.fiji.plugin.boundingbox.MinFilterThresholdBoundingBoxGUI; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBox; @@ -76,6 +77,6 @@ public static void main( String[] args ) throws SpimDataException service.shutdown(); - FusionTools.displayCopy( FusionTools.fuseVirtual( spimData, viewIds, true, false, 1, bb, null ), estimation.getMinIntensity(), estimation.getMaxIntensity() ).show(); + FusionTools.displayCopy( FusionTools.fuseVirtual( spimData, viewIds, FusionType.AVG_BLEND, 1, bb, null ), estimation.getMinIntensity(), estimation.getMaxIntensity() ).show(); } } diff --git a/src/main/java/net/preibisch/mvrecon/headless/fusion/OpenSeaDragonExport.java b/src/main/java/net/preibisch/mvrecon/headless/fusion/OpenSeaDragonExport.java index aaffc17a5..647f4eb43 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/fusion/OpenSeaDragonExport.java +++ b/src/main/java/net/preibisch/mvrecon/headless/fusion/OpenSeaDragonExport.java @@ -59,11 +59,13 @@ import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Util; import net.imglib2.view.Views; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; import net.preibisch.mvrecon.process.boundingbox.BoundingBoxMaximal; import net.preibisch.mvrecon.process.export.OpenSeaDragon.OpenSeaDragonImgLib2; import net.preibisch.mvrecon.process.fusion.FusionTools; +import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval.Fusion; public class OpenSeaDragonExport { @@ -132,9 +134,9 @@ public static void testOpenSeaDragonExport( final SpimData2 spimData, final int // // display virtually fused // - final RandomAccessibleInterval< FloatType > virtualRed = FusionTools.fuseVirtual( spimData, viewIdsRed, bb ); - final RandomAccessibleInterval< FloatType > virtualGreen = FusionTools.fuseVirtual( spimData, viewIdsGreen, bb ); - final RandomAccessibleInterval< FloatType > virtualBlue = FusionTools.fuseVirtual( spimData, viewIdsBlue, bb ); + final RandomAccessibleInterval< FloatType > virtualRed = FusionTools.fuseVirtual( spimData, viewIdsRed, FusionType.AVG_BLEND, bb ); + final RandomAccessibleInterval< FloatType > virtualGreen = FusionTools.fuseVirtual( spimData, viewIdsGreen, FusionType.AVG_BLEND, bb ); + final RandomAccessibleInterval< FloatType > virtualBlue = FusionTools.fuseVirtual( spimData, viewIdsBlue, FusionType.AVG_BLEND, bb ); final RandomAccessibleInterval< UnsignedByteType > r8bit = Converters.convertRAI( virtualRed, (i,o) -> o.set( Math.min( 255, Math.max( 0, (int)i.get() ) ) ), new UnsignedByteType() ); final RandomAccessibleInterval< UnsignedByteType > g8bit = Converters.convertRAI( virtualGreen, (i,o) -> o.set( Math.min( 255, Math.max( 0, (int)i.get() ) ) ), new UnsignedByteType() ); diff --git a/src/main/java/net/preibisch/mvrecon/headless/fusion/TestFusion.java b/src/main/java/net/preibisch/mvrecon/headless/fusion/TestFusion.java index 74151a12f..7901948c8 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/fusion/TestFusion.java +++ b/src/main/java/net/preibisch/mvrecon/headless/fusion/TestFusion.java @@ -36,6 +36,7 @@ import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Util; import net.preibisch.legacy.io.IOFunctions; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.headless.boundingbox.TestBoundingBox; import net.preibisch.mvrecon.process.export.DisplayImage; @@ -96,6 +97,7 @@ public static void testFusion( final SpimData2 spimData ) registrations, spimData.getSequenceDescription().getViewDescriptions(), viewIds, + FusionType.AVG_BLEND, bb ); DisplayImage.getImagePlusInstance( virtual, true, "Fused, Virtual", 0, 255 ).show(); diff --git a/src/main/java/net/preibisch/mvrecon/headless/fusion/TestIntensityAdjustment.java b/src/main/java/net/preibisch/mvrecon/headless/fusion/TestIntensityAdjustment.java index fed107ab1..2e4683295 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/fusion/TestIntensityAdjustment.java +++ b/src/main/java/net/preibisch/mvrecon/headless/fusion/TestIntensityAdjustment.java @@ -44,6 +44,7 @@ import net.imglib2.util.Pair; import net.imglib2.util.ValuePair; import net.preibisch.legacy.io.IOFunctions; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; import net.preibisch.mvrecon.process.export.DisplayImage; @@ -149,14 +150,14 @@ public static void testBalance( final SpimData2 spimData ) spimData.getSequenceDescription().getImgLoader(), registrations, spimData.getSequenceDescription().getViewDescriptions(), - viewIds, false, false, 1, bb, intensityMapping ); + viewIds, FusionType.AVG, 1, bb, intensityMapping ); final RandomAccessibleInterval< FloatType > virtual = FusionTools.fuseVirtual( spimData.getSequenceDescription().getImgLoader(), registrations, spimData.getSequenceDescription().getViewDescriptions(), - viewIds, false, false, 1, bb, null ); + viewIds, FusionType.AVG, 1, bb, null ); // // actually fuse into an image multithreaded diff --git a/src/main/java/net/preibisch/mvrecon/headless/fusion/TestNonRigid.java b/src/main/java/net/preibisch/mvrecon/headless/fusion/TestNonRigid.java index 56c7f78fd..3a9a86fa4 100644 --- a/src/main/java/net/preibisch/mvrecon/headless/fusion/TestNonRigid.java +++ b/src/main/java/net/preibisch/mvrecon/headless/fusion/TestNonRigid.java @@ -43,6 +43,7 @@ import net.imglib2.util.Util; import net.imglib2.util.ValuePair; import net.preibisch.legacy.io.IOFunctions; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBox; @@ -102,7 +103,7 @@ public static void compareToFusion( spimData.getSequenceDescription().getImgLoader(), registrations, spimData.getSequenceDescription().getViewDescriptions(), - fused, boundingBox ); + fused, FusionType.AVG_BLEND, boundingBox ); DisplayImage.getImagePlusInstance( virtual, false, "Fused Affine", 0, 255 ).show(); @@ -158,8 +159,6 @@ public static Pair< List< ViewId >, Interval > testInterpolation( final double alpha = 1.0; final boolean virtualGrid = false; - final boolean useBlending = true; - final boolean useContentBased = false; final boolean displayDistances = false; final ExecutorService service = DeconViews.createExecutorService(); @@ -188,8 +187,7 @@ public static Pair< List< ViewId >, Interval > testInterpolation( viewsToFuse, viewsToUse, labels, - useBlending, - useContentBased, + FusionType.AVG_BLEND, displayDistances, controlPointDistance, alpha, diff --git a/src/main/java/net/preibisch/mvrecon/process/boundingbox/BoundingBoxMinFilterThreshold.java b/src/main/java/net/preibisch/mvrecon/process/boundingbox/BoundingBoxMinFilterThreshold.java index a6f9cd0ba..2b6a6bddb 100644 --- a/src/main/java/net/preibisch/mvrecon/process/boundingbox/BoundingBoxMinFilterThreshold.java +++ b/src/main/java/net/preibisch/mvrecon/process/boundingbox/BoundingBoxMinFilterThreshold.java @@ -50,6 +50,7 @@ import net.imglib2.view.Views; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.Threads; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBox; import net.preibisch.mvrecon.process.export.DisplayImage; @@ -121,7 +122,7 @@ public BoundingBox estimate( final String title ) spimData.getSequenceDescription().getImgLoader(), registrations, spimData.getSequenceDescription().getViewDescriptions(), - views, true, false, 1, maxBBDS, null ), + views, FusionType.AVG_BLEND, 1, maxBBDS, null ), new ArrayImgFactory<>( new FloatType() ), new FloatType(), service ); diff --git a/src/main/java/net/preibisch/mvrecon/process/deconvolution/util/FusedNonZeroRandomAccessibleInterval.java b/src/main/java/net/preibisch/mvrecon/process/deconvolution/util/FusedNonZeroRandomAccessibleInterval.java index ed042abb6..0ab020a42 100644 --- a/src/main/java/net/preibisch/mvrecon/process/deconvolution/util/FusedNonZeroRandomAccessibleInterval.java +++ b/src/main/java/net/preibisch/mvrecon/process/deconvolution/util/FusedNonZeroRandomAccessibleInterval.java @@ -40,7 +40,7 @@ public FusedNonZeroRandomAccessibleInterval( final List< ? extends RandomAccessible< FloatType > > images, final List< ? extends RandomAccessible< FloatType > > weights ) { - super( interval, images, weights ); + super( interval, Fusion.AVG, images, weights ); this.accesses = new Vector<>(); } diff --git a/src/main/java/net/preibisch/mvrecon/process/deconvolution/util/ProcessInputImages.java b/src/main/java/net/preibisch/mvrecon/process/deconvolution/util/ProcessInputImages.java index c47a7a585..698c6bd4c 100644 --- a/src/main/java/net/preibisch/mvrecon/process/deconvolution/util/ProcessInputImages.java +++ b/src/main/java/net/preibisch/mvrecon/process/deconvolution/util/ProcessInputImages.java @@ -50,12 +50,14 @@ import net.imglib2.util.Util; import net.imglib2.view.Views; import net.preibisch.legacy.io.IOFunctions; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.process.deconvolution.MultiViewDeconvolution; import net.preibisch.mvrecon.process.deconvolution.normalization.NormalizingRandomAccessibleInterval; import net.preibisch.mvrecon.process.fusion.FusionTools; import net.preibisch.mvrecon.process.fusion.intensityadjust.IntensityAdjuster; import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval; +import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval.Fusion; import net.preibisch.mvrecon.process.fusion.transformed.TransformView; import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual; import net.preibisch.mvrecon.process.fusion.transformed.TransformWeight; @@ -384,7 +386,7 @@ public static < V extends ViewId > Interval fuseGroups( } // the fused image per group - final RandomAccessibleInterval< FloatType > img = new FusedRandomAccessibleInterval( new FinalInterval( dim ), images, weightsFusion ); + final RandomAccessibleInterval< FloatType > img = new FusedRandomAccessibleInterval( new FinalInterval( dim ), Fusion.AVG, images, weightsFusion ); // the weights used for deconvolution per group final RandomAccessibleInterval< FloatType > weight = new CombineWeightsRandomAccessibleInterval( new FinalInterval( dim ), weightsDecon, CombineType.SUM ); diff --git a/src/main/java/net/preibisch/mvrecon/process/fusion/FusionTools.java b/src/main/java/net/preibisch/mvrecon/process/fusion/FusionTools.java index 6ec563ea8..e7707f771 100644 --- a/src/main/java/net/preibisch/mvrecon/process/fusion/FusionTools.java +++ b/src/main/java/net/preibisch/mvrecon/process/fusion/FusionTools.java @@ -86,6 +86,7 @@ import net.imglib2.view.Views; import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.Threads; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.ViewSetupUtils; import net.preibisch.mvrecon.fiji.spimdata.explorer.popup.DisplayFusedImagesPopup; @@ -95,6 +96,7 @@ import net.preibisch.mvrecon.process.fusion.intensityadjust.IntensityAdjuster; import net.preibisch.mvrecon.process.fusion.lazy.LazyFusionTools; import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval; +import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval.Fusion; import net.preibisch.mvrecon.process.fusion.transformed.TransformView; import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual; import net.preibisch.mvrecon.process.fusion.transformed.TransformWeight; @@ -162,16 +164,19 @@ public static long numPixels( final long[] min, final long[] max, final double d * * @param spimData - an AbstractSpimData object * @param viewIds - which viewIds to fuse (be careful to remove not present one's first) + * @param fusionType - how to combine pixels * * @return a virtually fused zeroMin RandomAccessibleInterval and the transformation to map it to global coordinates */ public static RandomAccessibleInterval< FloatType > fuseVirtual( final AbstractSpimData< ? extends AbstractSequenceDescription< ?, ?, ? extends ImgLoader > > spimData, - final Collection< ? extends ViewId > viewIds ) + final Collection< ? extends ViewId > viewIds, + final FusionType fusionType ) { return fuseVirtual( spimData, viewIds, + fusionType, new BoundingBoxMaximal( viewIds, spimData ).estimate( "Full Bounding Box" ), null ); } @@ -182,17 +187,19 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( * @param spimData - an AbstractSpimData object * @param viewIds - which viewIds to fuse (be careful to remove not present one's first) * @param adjustIntensities - adjust intensities according to whats stored in the spimdata - * + * @param fusionType - how to combine pixels * @return a virtually fused zeroMin RandomAccessibleInterval */ public static RandomAccessibleInterval< FloatType > fuseVirtual( final SpimData2 spimData, final Collection< ? extends ViewId > viewIds, + final FusionType fusionType, final boolean adjustIntensities ) { return fuseVirtual( spimData, viewIds, + fusionType, new BoundingBoxMaximal( viewIds, spimData ).estimate( "Full Bounding Box" ), adjustIntensities ? spimData.getIntensityAdjustments().getIntensityAdjustments() : null ); } @@ -204,6 +211,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( * @param registrations - all (updated) registrations * @param viewDescriptions - all viewdescriptions * @param views - which viewIds to fuse (be careful to remove not present one's first) + * @param fusionType - how to combine pixels * @param bb - the bounding box in world coordinates (can be loaded from XML or defined through one of the BoundingBoxEstimation implementations) * * @return a virtually fused zeroMin RandomAccessibleInterval and the transformation to map it to global coordinates @@ -213,9 +221,10 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( final Map< ViewId, ? extends AffineTransform3D > registrations, // now contain the downsampling already final Map< ViewId, ? extends BasicViewDescription< ? > > viewDescriptions, final Collection< ? extends ViewId > views, + final FusionType fusionType, final Interval bb ) { - return fuseVirtual( imgloader, registrations, viewDescriptions, views, true, false, 1, bb, null ); + return fuseVirtual( imgloader, registrations, viewDescriptions, views, fusionType, 1, bb, null ); } /** @@ -223,6 +232,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( * * @param spimData - an AbstractSpimData object * @param viewIds - which viewIds to fuse (be careful to remove not present one's first) + * @param fusionType - how to combine pixels * @param bb - the bounding box in world coordinates (can be loaded from XML or defined through one of the BoundingBoxEstimation implementations) * * @return a virtually fused zeroMin RandomAccessibleInterval and the transformation to map it to global coordinates @@ -230,9 +240,10 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( public static RandomAccessibleInterval< FloatType > fuseVirtual( final AbstractSpimData< ? > spimData, final Collection< ? extends ViewId > viewIds, + final FusionType fusionType, final Interval bb ) { - return fuseVirtual( spimData, viewIds, bb, null ); + return fuseVirtual( spimData, viewIds, fusionType, bb, null ); } /** @@ -240,6 +251,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( * * @param spimData - an AbstractSpimData object * @param viewIds - which viewIds to fuse (be careful to remove not present one's first) + * @param fusionType - how to combine pixels * @param bb - the bounding box in world coordinates (can be loaded from XML or defined through one of the BoundingBoxEstimation implementations) * @param intensityAdjustments - the intensityadjustsments or null * @@ -248,17 +260,17 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( public static RandomAccessibleInterval< FloatType > fuseVirtual( final AbstractSpimData< ? > spimData, final Collection< ? extends ViewId > viewIds, + final FusionType fusionType, final Interval bb, final Map< ? extends ViewId, AffineModel1D > intensityAdjustments ) { - return fuseVirtual( spimData, viewIds, true, false, 1, bb, intensityAdjustments ); + return fuseVirtual( spimData, viewIds, fusionType, 1, bb, intensityAdjustments ); } public static RandomAccessibleInterval< FloatType > fuseVirtual( final AbstractSpimData< ? > spimData, final Collection< ? extends ViewId > views, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final int interpolation, final Interval boundingBox, final Map< ? extends ViewId, AffineModel1D > intensityAdjustments ) @@ -276,7 +288,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( final Map< ViewId, ? extends BasicViewDescription< ? > > viewDescriptions = spimData.getSequenceDescription().getViewDescriptions(); - return fuseVirtual( imgLoader, registrations, viewDescriptions, views, useBlending, useContentBased, interpolation, boundingBox, intensityAdjustments ); + return fuseVirtual( imgLoader, registrations, viewDescriptions, views, fusionType, interpolation, boundingBox, intensityAdjustments ); } /** @@ -377,8 +389,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( final Map< ViewId, ? extends AffineTransform3D > registrations, // now contain the downsampling already final Map< ViewId, ? extends BasicViewDescription< ? > > viewDescriptions, final Collection< ? extends ViewId > views, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, // see FusionGUI.fusionTypes[]{"Avg", "Avg, Blending", "Avg, Content Based", "Avg, Blending & Content Based", "Max", "First Tile Wins"} final int interpolation, final Interval boundingBox, // is already downsampled //final double downsampling, @@ -481,12 +492,12 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( images.add( TransformView.transformView( inputImg, model, bb, 0, interpolation ) ); // add all (or no) weighting schemes - if ( useBlending || useContentBased ) + if ( fusionType == FusionType.AVG_BLEND || fusionType == FusionType.AVG_BLEND_CONTENT || fusionType == FusionType.AVG_CONTENT ) { RandomAccessibleInterval< FloatType > transformedBlending = null, transformedContentBased = null; // instantiate blending if necessary - if ( useBlending ) + if ( fusionType == FusionType.AVG_BLEND || fusionType == FusionType.AVG_BLEND_CONTENT ) { final float[] blending = Util.getArrayFromValue( defaultBlendingRange, 3 ); final float[] border = Util.getArrayFromValue( defaultBlendingBorder, 3 ); @@ -505,7 +516,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( } // instantiate content based if necessary - if ( useContentBased ) + if ( fusionType == FusionType.AVG_BLEND_CONTENT || fusionType == FusionType.AVG_CONTENT ) { final double[] sigma1 = Util.getArrayFromValue( defaultContentBasedSigma1, 3 ); final double[] sigma2 = Util.getArrayFromValue( defaultContentBasedSigma2, 3 ); @@ -523,7 +534,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( transformedContentBased = TransformWeight.transformContentBased( inputImg, sigma1, sigma2, LazyFusionTools.defaultBlockSize3d, ContentBasedRealRandomAccessible.defaultScale, model, bb ); } - if ( useContentBased && useBlending ) + if ( fusionType == FusionType.AVG_BLEND_CONTENT ) { weights.add( new CombineWeightsRandomAccessibleInterval( new FinalInterval( transformedBlending ), @@ -531,11 +542,11 @@ public static RandomAccessibleInterval< FloatType > fuseVirtual( transformedContentBased, CombineType.MUL ) ); } - else if ( useBlending ) + else if ( fusionType == FusionType.AVG_BLEND ) { weights.add( transformedBlending ); } - else if ( useContentBased ) + else if ( fusionType == FusionType.AVG_CONTENT ) { weights.add( transformedContentBased ); } @@ -549,7 +560,16 @@ else if ( useContentBased ) } } - return new FusedRandomAccessibleInterval( new FinalInterval( getFusedZeroMinInterval( bb ) ), images, weights ); + final Fusion fusion; + + if ( fusionType == FusionType.AVG || fusionType == FusionType.AVG_BLEND || fusionType == FusionType.AVG_BLEND_CONTENT || fusionType == FusionType.AVG_CONTENT ) + fusion = Fusion.AVG; + else if ( fusionType == FusionType.MAX ) + fusion = Fusion.MAX; + else + fusion = Fusion.FIRST_WINS; + + return new FusedRandomAccessibleInterval( new FinalInterval( getFusedZeroMinInterval( bb ) ), fusion, images, weights ); //return new ValuePair<>( new FusedRandomAccessibleInterval( new FinalInterval( getFusedZeroMinInterval( bb ) ), images, weights ), bbTransform ); } diff --git a/src/main/java/net/preibisch/mvrecon/process/fusion/lazy/LazyAffineFusion.java b/src/main/java/net/preibisch/mvrecon/process/fusion/lazy/LazyAffineFusion.java index 4b86a88f2..62689cf5f 100644 --- a/src/main/java/net/preibisch/mvrecon/process/fusion/lazy/LazyAffineFusion.java +++ b/src/main/java/net/preibisch/mvrecon/process/fusion/lazy/LazyAffineFusion.java @@ -49,6 +49,7 @@ import net.imglib2.type.numeric.real.FloatType; import net.imglib2.util.Intervals; import net.imglib2.view.Views; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; import net.preibisch.mvrecon.process.deconvolution.DeconViews; @@ -72,8 +73,7 @@ public class LazyAffineFusion & NativeType> implements final Map< ViewId, ? extends AffineTransform3D > viewRegistrations; final Map< ViewId, ? extends BasicViewDescription< ? > > viewDescriptions; - final boolean useBlending; - final boolean useContentBased; + final FusionType fusionType; final int interpolation; final Map< ViewId, AffineModel1D > intensityAdjustments; @@ -86,8 +86,7 @@ public class LazyAffineFusion & NativeType> implements * @param viewIds - which viewids to fuse * @param viewRegistrations - the registrations (must include anisotropy and downsampling if desired) * @param viewDescriptions - the viewdescriptions - * @param useBlending - blend images when overlapping? - * @param useContentBased - use content-based fusion? + * @param fusionType - how to combine pixels * @param interpolation - 1==linear, 0==nearest neighbor * @param intensityAdjustments - intensity adjustments, can be null * @param globalMin - the output RAI typically sits at 0,0...0 because it usually is a CachedCellImage (but the actual interval to process in many blocks sits somewhere else) @@ -99,8 +98,7 @@ public LazyAffineFusion( final Collection< ? extends ViewId > viewIds, final Map< ViewId, ? extends AffineTransform3D > viewRegistrations, final Map< ViewId, ? extends BasicViewDescription< ? > > viewDescriptions, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final int interpolation, final Map< ViewId, AffineModel1D > intensityAdjustments, final long[] globalMin, @@ -115,8 +113,7 @@ public LazyAffineFusion( this.viewIds = viewIds; this.viewRegistrations = viewRegistrations; this.viewDescriptions = viewDescriptions; - this.useBlending = useBlending; - this.useContentBased = useContentBased; + this.fusionType = fusionType; this.interpolation = interpolation; this.intensityAdjustments = intensityAdjustments; } @@ -136,8 +133,7 @@ public void accept( final RandomAccessibleInterval output ) viewRegistrations, viewDescriptions, viewIds, - useBlending, // use blending - useContentBased, // use content-based + fusionType, interpolation, // linear interpolation targetBlock, intensityAdjustments ); // intensity adjustments @@ -174,8 +170,7 @@ public static final & NativeType> RandomAccessibleInte final Collection< ? extends ViewId > viewIds, final Map< ViewId, ? extends AffineTransform3D > viewRegistrations, final Map< ViewId, ? extends BasicViewDescription< ? > > viewDescriptions, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final int interpolation, final Map< ViewId, AffineModel1D > intensityAdjustments, final Interval fusionInterval, @@ -189,8 +184,7 @@ public static final & NativeType> RandomAccessibleInte viewIds, viewRegistrations, viewDescriptions, - useBlending, - useContentBased, + fusionType, interpolation, intensityAdjustments, fusionInterval.minAsLongArray(), @@ -235,8 +229,7 @@ public static void main( String[] args ) throws SpimDataException viewIds, registrations, data.getSequenceDescription().getViewDescriptions(), - true, // blending - false, // content based + FusionType.AVG_BLEND, 1, // linear interpolatio null, // intensity adjustment bb, diff --git a/src/main/java/net/preibisch/mvrecon/process/fusion/lazy/LazyNonRigidFusion.java b/src/main/java/net/preibisch/mvrecon/process/fusion/lazy/LazyNonRigidFusion.java index 049088a93..a33449c1f 100644 --- a/src/main/java/net/preibisch/mvrecon/process/fusion/lazy/LazyNonRigidFusion.java +++ b/src/main/java/net/preibisch/mvrecon/process/fusion/lazy/LazyNonRigidFusion.java @@ -53,6 +53,7 @@ import net.imglib2.util.Pair; import net.imglib2.util.Util; import net.preibisch.legacy.io.IOFunctions; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.XmlIoSpimData2; import net.preibisch.mvrecon.fiji.spimdata.boundingbox.BoundingBox; @@ -63,6 +64,7 @@ import net.preibisch.mvrecon.process.fusion.FusionTools; import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval; import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual; +import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval.Fusion; import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.CorrespondingIP; import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.NonRigidTools; import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.SimpleReferenceIP; @@ -79,8 +81,7 @@ public class LazyNonRigidFusion & NativeType> implemen final Collection< ? extends ViewId > viewsToFuse; final HashMap< ViewId, AffineTransform3D > registrations; final HashMap< ViewId, ModelGrid > nonrigidGrids; - final boolean useBlending; - final boolean useContentBased; + final FusionType fusionType; final boolean displayDistances; final int interpolation; final Map< ? extends ViewId, AffineModel1D > intensityAdjustments; @@ -100,8 +101,7 @@ public LazyNonRigidFusion( final Collection< ? extends ViewId > viewsToFuse, final Collection< ? extends ViewId > viewsToUse, final List< String > labels, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final boolean displayDistances, final long[] controlPointDistance, final double alpha, @@ -117,8 +117,7 @@ public LazyNonRigidFusion( this.imgloader = imgloader; this.viewDescriptions = viewDescriptions; this.viewsToFuse = viewsToFuse; - this.useBlending = useBlending; - this.useContentBased = useContentBased; + this.fusionType = fusionType; this.displayDistances = displayDistances; this.interpolation = interpolation; this.intensityAdjustments = intensityAdjustments; @@ -170,16 +169,25 @@ public void accept( final RandomAccessibleInterval output ) registrations, nonrigidGrids, targetBlock, - useBlending, - useContentBased, + fusionType, displayDistances, interpolation, intensityAdjustments, NonRigidTools.defaultOverlapExpansion( maxDist ) ); + final Fusion fusion; + + if ( fusionType == FusionType.AVG || fusionType == FusionType.AVG_BLEND || fusionType == FusionType.AVG_BLEND_CONTENT || fusionType == FusionType.AVG_CONTENT ) + fusion = Fusion.AVG; + else if ( fusionType == FusionType.MAX ) + fusion = Fusion.MAX; + else + fusion = Fusion.FIRST_WINS; + final RandomAccessibleInterval fused = new FusedRandomAccessibleInterval( FusionTools.getFusedZeroMinInterval( targetBlock ), + fusion, virtual.getA(), virtual.getB() ); @@ -195,8 +203,7 @@ public static final & NativeType> RandomAccessibleInte final Collection< ? extends ViewId > viewsToFuse, final Collection< ? extends ViewId > viewsToUse, final List< String > labels, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final boolean displayDistances, final long[] controlPointDistance, final double alpha, @@ -218,8 +225,7 @@ public static final & NativeType> RandomAccessibleInte viewsToFuse, viewsToUse, labels, - useBlending, - useContentBased, + fusionType, displayDistances, controlPointDistance, alpha, @@ -259,8 +265,7 @@ public static void main( String[] args ) throws SpimDataException final long[] controlPointDistance = new long[] { cpd, cpd, cpd }; final double alpha = 1.0; final boolean virtualGrid = false; - final boolean useBlending = true; - final boolean useContentBased = false; + final FusionType fusionType = FusionType.AVG_BLEND; final boolean displayDistances = false; final ExecutorService service = DeconViews.createExecutorService(); @@ -288,8 +293,7 @@ public static void main( String[] args ) throws SpimDataException viewsToFuse, viewsToUse, labels, - useBlending, - useContentBased, + fusionType, displayDistances, controlPointDistance, alpha, diff --git a/src/main/java/net/preibisch/mvrecon/process/fusion/transformed/FusedRandomAccessibleInterval.java b/src/main/java/net/preibisch/mvrecon/process/fusion/transformed/FusedRandomAccessibleInterval.java index 61261b433..6cdda023c 100644 --- a/src/main/java/net/preibisch/mvrecon/process/fusion/transformed/FusedRandomAccessibleInterval.java +++ b/src/main/java/net/preibisch/mvrecon/process/fusion/transformed/FusedRandomAccessibleInterval.java @@ -46,6 +46,7 @@ public enum Fusion {AVG, MAX, FIRST_WINS}; public FusedRandomAccessibleInterval( final Interval interval, + final Fusion fusion, final List< ? extends RandomAccessible< FloatType > > images, final List< ? extends RandomAccessible< FloatType > > weights ) { @@ -67,9 +68,10 @@ public FusedRandomAccessibleInterval( public FusedRandomAccessibleInterval( final Interval interval, + final Fusion fusion, final List< ? extends RandomAccessible< FloatType > > images ) { - this( interval, images, null ); + this( interval, fusion, images, null ); } public Interval getInterval() { return interval; } diff --git a/src/main/java/net/preibisch/mvrecon/process/fusion/transformed/nonrigid/NonRigidTools.java b/src/main/java/net/preibisch/mvrecon/process/fusion/transformed/nonrigid/NonRigidTools.java index 285fcd48b..8f8f0fadc 100644 --- a/src/main/java/net/preibisch/mvrecon/process/fusion/transformed/nonrigid/NonRigidTools.java +++ b/src/main/java/net/preibisch/mvrecon/process/fusion/transformed/nonrigid/NonRigidTools.java @@ -58,6 +58,7 @@ import net.imglib2.util.ValuePair; import net.imglib2.view.Views; import net.preibisch.legacy.io.IOFunctions; +import net.preibisch.mvrecon.fiji.plugin.fusion.FusionGUI.FusionType; import net.preibisch.mvrecon.fiji.spimdata.SpimData2; import net.preibisch.mvrecon.fiji.spimdata.interestpoints.CorrespondingInterestPoints; import net.preibisch.mvrecon.fiji.spimdata.interestpoints.InterestPoint; @@ -72,6 +73,7 @@ import net.preibisch.mvrecon.process.fusion.transformed.TransformView; import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual; import net.preibisch.mvrecon.process.fusion.transformed.TransformWeight; +import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval.Fusion; import net.preibisch.mvrecon.process.fusion.transformed.nonrigid.grid.ModelGrid; import net.preibisch.mvrecon.process.fusion.transformed.weightcombination.CombineWeightsRandomAccessibleInterval; import net.preibisch.mvrecon.process.fusion.transformed.weightcombination.CombineWeightsRandomAccessibleInterval.CombineType; @@ -88,8 +90,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtualInterpolatedNonRi final Collection< ? extends ViewId > viewsToFuse, final Collection< ? extends ViewId > viewsToUse, final ArrayList< String > labels, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final boolean displayDistances, final long[] controlPointDistance, final double alpha, @@ -127,8 +128,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtualInterpolatedNonRi viewsToFuse, viewsToUse, labels, - useBlending, - useContentBased, + fusionType, displayDistances, controlPointDistance, alpha, @@ -147,8 +147,7 @@ public static RandomAccessibleInterval< FloatType > fuseVirtualInterpolatedNonRi final Collection< ? extends ViewId > viewsToFuse, final Collection< ? extends ViewId > viewsToUse, final ArrayList< String > labels, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final boolean displayDistances, final long[] controlPointDistance, final double alpha, @@ -198,14 +197,22 @@ public static RandomAccessibleInterval< FloatType > fuseVirtualInterpolatedNonRi registrations, nonrigidGrids, boundingBox, - useBlending, - useContentBased, + fusionType, displayDistances, interpolation, intensityAdjustments, defaultOverlapExpansion( uniquePointsData.getB() ) ); - return new FusedRandomAccessibleInterval( FusionTools.getFusedZeroMinInterval( boundingBox ), virtual.getA(), virtual.getB() ); + final Fusion fusion; + + if ( fusionType == FusionType.AVG || fusionType == FusionType.AVG_BLEND || fusionType == FusionType.AVG_BLEND_CONTENT || fusionType == FusionType.AVG_CONTENT ) + fusion = Fusion.AVG; + else if ( fusionType == FusionType.MAX ) + fusion = Fusion.MAX; + else + fusion = Fusion.FIRST_WINS; + + return new FusedRandomAccessibleInterval( FusionTools.getFusedZeroMinInterval( boundingBox ), fusion, virtual.getA(), virtual.getB() ); //return new ValuePair<>( new FusedRandomAccessibleInterval( FusionTools.getFusedZeroMinInterval( bbDS ), virtual.getA(), virtual.getB() ), bbTransform ); } @@ -303,8 +310,7 @@ public static Pair< ArrayList< RandomAccessibleInterval< FloatType > >, ArrayLis final Map< ViewId, AffineTransform3D > downsampledRegistrations, final HashMap< ViewId, ModelGrid > nonrigidGrids, final Interval bbDS, - final boolean useBlending, - final boolean useContentBased, + final FusionType fusionType, final boolean displayDistances, final int interpolation, final Map< ? extends ViewId, AffineModel1D > intensityAdjustments, @@ -398,12 +404,12 @@ public static Pair< ArrayList< RandomAccessibleInterval< FloatType > >, ArrayLis // // weights // - if ( useBlending || useContentBased ) + if ( fusionType == FusionType.AVG_BLEND || fusionType == FusionType.AVG_BLEND_CONTENT || fusionType == FusionType.AVG_CONTENT ) { RandomAccessibleInterval< FloatType > transformedBlending = null, transformedContentBased = null; // instantiate blending if necessary - if ( useBlending ) + if ( fusionType == FusionType.AVG_BLEND || fusionType == FusionType.AVG_BLEND_CONTENT ) { final float[] blending = Util.getArrayFromValue( FusionTools.defaultBlendingRange, 3 ); final float[] border = Util.getArrayFromValue( FusionTools.defaultBlendingBorder, 3 ); @@ -423,7 +429,7 @@ public static Pair< ArrayList< RandomAccessibleInterval< FloatType > >, ArrayLis } // instantiate content based if necessary - if ( useContentBased ) + if ( fusionType == FusionType.AVG_BLEND_CONTENT || fusionType == FusionType.AVG_CONTENT ) { final double[] sigma1 = Util.getArrayFromValue( FusionTools.defaultContentBasedSigma1, 3 ); final double[] sigma2 = Util.getArrayFromValue( FusionTools.defaultContentBasedSigma2, 3 ); @@ -449,7 +455,7 @@ public static Pair< ArrayList< RandomAccessibleInterval< FloatType > >, ArrayLis bbDS ); } - if ( useContentBased && useBlending ) + if ( fusionType == FusionType.AVG_BLEND_CONTENT ) { weights.add( new CombineWeightsRandomAccessibleInterval( new FinalInterval( transformedBlending ), @@ -457,11 +463,11 @@ public static Pair< ArrayList< RandomAccessibleInterval< FloatType > >, ArrayLis transformedContentBased, CombineType.MUL ) ); } - else if ( useBlending ) + else if ( fusionType == FusionType.AVG_BLEND ) { weights.add( transformedBlending ); } - else if ( useContentBased ) + else if ( fusionType == FusionType.AVG_CONTENT ) { weights.add( transformedContentBased ); } diff --git a/src/main/java/net/preibisch/mvrecon/process/quality/FRCTools.java b/src/main/java/net/preibisch/mvrecon/process/quality/FRCTools.java index 229713e33..6aa4a3574 100644 --- a/src/main/java/net/preibisch/mvrecon/process/quality/FRCTools.java +++ b/src/main/java/net/preibisch/mvrecon/process/quality/FRCTools.java @@ -42,6 +42,7 @@ import net.preibisch.legacy.io.IOFunctions; import net.preibisch.mvrecon.process.fusion.FusionTools; import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval; +import net.preibisch.mvrecon.process.fusion.transformed.FusedRandomAccessibleInterval.Fusion; import net.preibisch.mvrecon.process.fusion.transformed.TransformView; import net.preibisch.mvrecon.process.fusion.transformed.TransformVirtual; import net.preibisch.mvrecon.process.fusion.transformed.TransformWeight; @@ -110,7 +111,7 @@ public static RandomAccessibleInterval< FloatType > fuseRAIs( weights.add( TransformWeight.transformBlending( d.getA(), border, blending, model, bb ) ); } - return new FusedRandomAccessibleInterval( new FinalInterval( dim ), images, weights ); + return new FusedRandomAccessibleInterval( new FinalInterval( dim ), Fusion.AVG, images, weights ); }