Skip to content

Commit

Permalink
output to single folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ekatrukha committed Apr 30, 2024
1 parent 7fdff9f commit 8086d3b
Showing 1 changed file with 43 additions and 24 deletions.
67 changes: 43 additions & 24 deletions src/main/java/averagingND/IterativeAveraging.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -59,17 +60,19 @@ 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 **/
public boolean bZeroMask = false;

public boolean bOutputInput = false;

String sPathRegistered = "";

/** for now it cannot be changed by user **/
public boolean bIgnoreZeroInAveraging = true;

Expand All @@ -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 **/
Expand Down Expand Up @@ -178,7 +182,7 @@ public void run(String paramString) {
//sumAndCount = AverageWithoutZero.sumAndCountArray(imgs_shift);

IntervalView<FloatType> currAverageImg;
if(bIntermediateAverage && nIterN>0)
if(bSaveIntermediate && nIterN>0)
{
processIntermediate(0);
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<FloatType> finalAver = AverageWithoutZero.averageArray(imgs_avrg_out, bIgnoreZeroInAveraging);

Expand All @@ -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<nImageN;i++)
{
temp = MiscUtils.wrapFloatImgCal(Views.interval(Views.extendZero(imgs_avrg_out.get(i)),finalAver),"iter_aver_"+imageSet.image_names.get(i),imageSet.cal, imageSet.bMultiCh);
temp = MiscUtils.wrapFloatImgCal(Views.interval(Views.extendZero(imgs_avrg_out.get(i)),finalAver),"reg_"+imageSet.image_names.get(i), imageSet.cal, imageSet.bMultiCh);

IJ.saveAsTiff(temp, sPath+temp.getTitle());
IJ.saveAsTiff(temp, sPathRegistered+temp.getTitle());
}
IJ.log("..done");


}
}
Expand Down Expand Up @@ -552,7 +556,7 @@ public void medianCorrectShifts(final long [][] shifts_in)

public void processIntermediate(final int nIt)
{
ArrayList<RandomAccessibleInterval< FloatType >> imgs_avrg_out = getAlignedRAI(shifts, true);
ArrayList<RandomAccessibleInterval< FloatType >> 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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;

}
Expand Down Expand Up @@ -798,7 +817,7 @@ public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
}

/** function returns aligned intervals **/
ArrayList<RandomAccessibleInterval< FloatType >> getAlignedRAI(final ArrayList<long []> shifts_, boolean bIgnoreZero)
ArrayList<RandomAccessibleInterval< FloatType >> getAlignedRAIs(final ArrayList<long []> shifts_, boolean bIgnoreZero)
{
ArrayList<RandomAccessibleInterval< FloatType >> imgs_avrg_out;

Expand Down

0 comments on commit 8086d3b

Please sign in to comment.