From 8086d3b6b03a21aa81cb48a5ae46a121a633e3ba Mon Sep 17 00:00:00 2001 From: Eugene Katrukha Date: Tue, 30 Apr 2024 13:38:14 +0200 Subject: [PATCH] output to single folder --- .../java/averagingND/IterativeAveraging.java | 67 ++++++++++++------- 1 file changed, 43 insertions(+), 24 deletions(-) diff --git a/src/main/java/averagingND/IterativeAveraging.java b/src/main/java/averagingND/IterativeAveraging.java index 27d3a7e..5f86498 100644 --- a/src/main/java/averagingND/IterativeAveraging.java +++ b/src/main/java/averagingND/IterativeAveraging.java @@ -5,6 +5,7 @@ import java.awt.Choice; import java.awt.Label; import java.awt.TextField; +import java.io.File; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.ArrayList; @@ -59,10 +60,10 @@ public class IterativeAveraging implements PlugIn, DialogListener { public int nIterN = 0; /** whether or not generate intermediate average **/ - boolean bIntermediateAverage = false; - boolean bSaveIntermediate = false; + String sPathGeneralOutput = ""; + String sPathIntermediate = ""; /** whether to use zero masked CC **/ @@ -70,6 +71,8 @@ public class IterativeAveraging implements PlugIn, DialogListener { public boolean bOutputInput = false; + String sPathRegistered = ""; + /** for now it cannot be changed by user **/ public boolean bIgnoreZeroInAveraging = true; @@ -81,6 +84,7 @@ public class IterativeAveraging implements PlugIn, DialogListener { public int nConstrainReg = 0; double [] lim_fractions = null; + FinalInterval limInterval = null; /** choice UI for constrain type **/ @@ -178,7 +182,7 @@ public void run(String paramString) { //sumAndCount = AverageWithoutZero.sumAndCountArray(imgs_shift); IntervalView currAverageImg; - if(bIntermediateAverage && nIterN>0) + if(bSaveIntermediate && nIterN>0) { processIntermediate(0); } @@ -326,7 +330,7 @@ public void run(String paramString) { } IJ.log("Iteration "+Integer.toString(iter+1)+" average CC " + df.format(avrgCC) +sTimeEl); - if(bIntermediateAverage && nIterN>0) + if(bSaveIntermediate && nIterN>0) { processIntermediate(iter+1); } @@ -365,7 +369,7 @@ public void run(String paramString) { //calculate final average image IJ.log("calculating final average image.."); - imgs_avrg_out = getAlignedRAI(shifts, true); + imgs_avrg_out = getAlignedRAIs(shifts, true); IntervalView finalAver = AverageWithoutZero.averageArray(imgs_avrg_out, bIgnoreZeroInAveraging); @@ -379,17 +383,17 @@ public void run(String paramString) { if(bOutputInput) { - DirectoryChooser dc = new DirectoryChooser ( "Choose a folder to save output..." ); - String sPath = dc.getDirectory(); - if(sPath == null || finalAver == null) - return; + + IJ.log("saving registered inputs..."); ImagePlus temp; for(i=0;i> imgs_avrg_out = getAlignedRAI(shifts, true); + ArrayList> imgs_avrg_out = getAlignedRAIs(shifts, true); String sName = "intermediate_average_"+Integer.toString(nIt); ImagePlus temp; temp = MiscUtils.wrapFloatImgCal(AverageWithoutZero.averageArray(imgs_avrg_out, bIgnoreZeroInAveraging),sName,imageSet.cal,imageSet.bMultiCh); @@ -629,9 +633,8 @@ public boolean dialogSettings() } } gd1.addMessage("Output:"); - gd1.addCheckbox("Show intermediate average?", Prefs.get("RegisterNDFFT.IA.bShowIntermediateAverage",false)); - gd1.addCheckbox("If yes, save intermediate on disk?", Prefs.get("RegisterNDFFT.IA.bSaveIntermediate",false)); - gd1.addCheckbox("Output registered inputs?", Prefs.get("RegisterNDFFT.IA.bOutputInput",false)); + gd1.addCheckbox("Save intermediates?", Prefs.get("RegisterNDFFT.IA.bSaveIntermediate",false)); + gd1.addCheckbox("Save registered inputs?", Prefs.get("RegisterNDFFT.IA.bOutputInput",false)); gd1.addDialogListener(this); gd1.showDialog(); @@ -731,23 +734,39 @@ public boolean dialogSettings() } } - bIntermediateAverage = gd1.getNextBoolean(); - Prefs.set("RegisterNDFFT.IA.bShowIntermediateAverage", bIntermediateAverage); bSaveIntermediate = gd1.getNextBoolean(); Prefs.set("RegisterNDFFT.IA.bSaveIntermediate", bSaveIntermediate); bOutputInput = gd1.getNextBoolean(); Prefs.set("RegisterNDFFT.IA.bOutputInput", bOutputInput); + DirectoryChooser dc = new DirectoryChooser ( "Choose a folder to save output..." ); + sPathGeneralOutput = dc.getDirectory(); + if(sPathGeneralOutput == null) + return false; - - if(bIntermediateAverage && bSaveIntermediate && nIterN>0) + if(bSaveIntermediate && nIterN>0) { - DirectoryChooser dc = new DirectoryChooser ( "Choose a folder to save intermediate averages..." ); - sPathIntermediate = dc.getDirectory(); - if(sPathIntermediate == null) - return false; + sPathIntermediate = sPathGeneralOutput +"intermediate/"; + File theDir = new File(sPathIntermediate); + if (!theDir.exists()) + { + theDir.mkdirs(); + } + //DirectoryChooser dc = new DirectoryChooser ( "Choose a folder to save intermediate averages..." ); + //sPathIntermediate = dc.getDirectory(); + //if(sPathIntermediate == null) + //return false; } + if(bOutputInput) + { + sPathRegistered = sPathGeneralOutput +"registered/"; + File theDir = new File(sPathRegistered); + if (!theDir.exists()) + { + theDir.mkdirs(); + } + } return true; } @@ -798,7 +817,7 @@ public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) { } /** function returns aligned intervals **/ - ArrayList> getAlignedRAI(final ArrayList shifts_, boolean bIgnoreZero) + ArrayList> getAlignedRAIs(final ArrayList shifts_, boolean bIgnoreZero) { ArrayList> imgs_avrg_out;