Skip to content

Commit

Permalink
masked rename
Browse files Browse the repository at this point in the history
  • Loading branch information
ekatrukha committed Apr 30, 2024
1 parent 4e412bd commit 82b9c80
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 80 deletions.
3 changes: 1 addition & 2 deletions src/main/java/averagingND/AverageWithoutZero.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
import net.imglib2.img.ImagePlusAdapter;
import net.imglib2.img.Img;
import net.imglib2.img.array.ArrayImgs;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Intervals;
import net.imglib2.view.IntervalView;
import net.imglib2.view.Views;

public class AverageWithoutZero implements PlugIn {

public boolean multiCh=false;
public boolean multiCh = false;
@Override
public void run(String arg0) {

Expand Down
40 changes: 7 additions & 33 deletions src/main/java/averagingND/GenNormCC.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class GenNormCC {
public boolean bVerbose = true;

/** whether to exclude/ignore voxels that are zeros **/
public boolean bExcludeZeros = false;
public boolean bZeroMask = false;

/** window limit of CC max localization as a fraction of max displacement **/
public double [] lim_fractions = null;
Expand All @@ -64,7 +64,7 @@ public boolean caclulateGenNormCC(final RandomAccessibleInterval< FloatType > im

if(image.numDimensions()!=template.numDimensions())
{
IJ.log("Error! Different dimensions of input and template!");
IJ.log("Error! Different number of dimensions between reference and template images!");
return false;
}

Expand Down Expand Up @@ -103,12 +103,10 @@ public boolean caclulateGenNormCC(final RandomAccessibleInterval< FloatType > im
}


long[] paddedDimensions = new long[template.numDimensions()];
long[] fftSize = new long[template.numDimensions()];
long[] paddedDimensions = new long[nDim];
long[] fftSize = new long[nDim];
FFTMethods.dimensionsRealToComplexFast(new FinalDimensions(finDim), paddedDimensions, fftSize);

//System.out.println("done");

//padded intervals
FinalInterval imgIntPad = (FinalInterval) FFTMethods.paddingIntervalCentered(image, new FinalDimensions(paddedDimensions));
FinalInterval temIntPad = (FinalInterval) FFTMethods.paddingIntervalCentered(template, new FinalDimensions(paddedDimensions));
Expand All @@ -123,7 +121,7 @@ public boolean caclulateGenNormCC(final RandomAccessibleInterval< FloatType > im
final ArrayImg<FloatType, FloatArray> unityImg = ArrayImgs.floats(imgDim);
final ArrayImg<FloatType, FloatArray> unityTem = ArrayImgs.floats(temDim);

if(!bExcludeZeros)
if(!bZeroMask)
{
unityImg.forEach(t->t.set(1.0f));
unityTem.forEach(t->t.set(1.0f));
Expand Down Expand Up @@ -303,10 +301,6 @@ public boolean caclulateGenNormCC(final RandomAccessibleInterval< FloatType > im
{
constrainFr = new FinalInterval(cropFraction[0] , cropFraction[1]);
}
// if(limInterval != null)
// {
// intervalCrop = Intervals.intersect(intervalCrop, limInterval);
// }

//Now we need to account for the padding. Since it is changing the origin
//of coordinates of template with respect to the original image
Expand All @@ -324,8 +318,6 @@ public boolean caclulateGenNormCC(final RandomAccessibleInterval< FloatType > im
//full available shift space
ivCCswapped = Views.interval(Views.translate(Views.extendPeriodic( invF1F2 ), nCCOrigin),intervalFull);



//let's apply constrains

//voxel constrains
Expand Down Expand Up @@ -359,17 +351,6 @@ public boolean caclulateGenNormCC(final RandomAccessibleInterval< FloatType > im
}


// if(bCenteredLimit)
// {
// ivCCswapped = Views.interval(Views.extendPeriodic( invF1F2 ),intervalCrop);
// }
// else
// {
// //ivCCswapped = Views.interval(Views.extendPeriodic( invF1F2 ),intervalCrop);
// ivCCswapped = Views.interval(Views.translate(Views.extendPeriodic( invF1F2 ), nCCOrigin),intervalCrop);
// //ivCCswapped = Views.interval(Views.translate(Views.extendPeriodic( invF1F2 ), nCCOrigin),intervalCrop);
// }

if(bShowCC)
{
ImageJFunctions.show(ivCCswapped).setTitle( "General cross-correlation" );
Expand Down Expand Up @@ -397,14 +378,7 @@ public boolean caclulateGenNormCC(final RandomAccessibleInterval< FloatType > im

// final shift of images
shift.localize(dShift);
// if(bCenteredLimit)
// {
// //add center position
// for(i=0;i<nDim;i++)
// {
// dShift[i] += nCCOrigin[i];
// }
// }

// max of cross-correlation
dMaxCC = fCCvalue.get();

Expand Down Expand Up @@ -456,7 +430,7 @@ public static void calcTermDenom(final Img< FloatType > im1, final Img< FloatTyp
//if(Math.abs(t4)>Float.MIN_VALUE)
{

temp=cursFl1.get().get()-(cursFl2.get().get()*cursFl3.get().get()/cursFl4.get().get());
temp = cursFl1.get().get()-(cursFl2.get().get()*cursFl3.get().get()/cursFl4.get().get());
cursFl1.get().set(Math.max(temp, 0));

}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/averagingND/ImageSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ boolean loadAllImages()
}
}
}
IJ.log("Dimension ranges of the input images:");
for(int d=0;d<nDim;d++)
{
IJ.log("Axis "+sRefDimsIJ.charAt(d)+" min: "+Long.toString(dimsMin[d])+" max: "+Long.toString(dimsMax[d]));
Expand Down
44 changes: 23 additions & 21 deletions src/main/java/averagingND/IterativeAveraging.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public class IterativeAveraging implements PlugIn, DialogListener {

String sPathIntermediate = "";

public boolean bExcludeZeros = false;
/** whether to use zero masked CC **/
public boolean bZeroMask = false;

public boolean bOutputInput = false;

Expand All @@ -76,6 +77,9 @@ public class IterativeAveraging implements PlugIn, DialogListener {
* **/
public int nConstrainReg = 0;

/** choice UI for constrain type **/
Choice limitCh;

/** labels of constrain axes **/
Label [] limName;

Expand All @@ -98,7 +102,7 @@ public void run(String paramString) {

ArrayList<RandomAccessibleInterval< FloatType >> imgs_avrg_out;

//double format formatting toold
//double format formatting tool
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
DecimalFormat df = new DecimalFormat ("#.########", symbols);
Expand Down Expand Up @@ -150,7 +154,7 @@ public void run(String paramString) {
limVal = new TextField[nDimReg];
dLimits = new double [nDimReg];

final String[] sIniTemplate = new String[ ]{"Average (center)","Average (top-left)"};
final String[] sIniTemplate = new String[ ]{"Centered","Zero (top-left)"};
final String[] limitsReg = new String[ ] {"No","by voxels", "by image fraction"};
final GenericDialog gd1 = new GenericDialog( "Averaging parameters" );
if(imageSet.bMultiCh)
Expand All @@ -162,12 +166,13 @@ public void run(String paramString) {
}
gd1.addChoice( "Initial template:", sIniTemplate, Prefs.get("RegisterNDFFT.IA.nIniTemplate", sIniTemplate[0]) );
gd1.addNumericField("Number of iterations", Prefs.get("RegisterNDFFT.IA.nIterN",10),0);
gd1.addCheckbox("Exclude zero values?", Prefs.get("RegisterNDFFT.IA.bExcludeZeros", false));
gd1.addCheckbox("Use zero masked CC?", Prefs.get("RegisterNDFFT.IA.bExcludeZeros", false));
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));
String sCurrChoice = Prefs.get("RegisterNDFFT.IA.sConstrain", "No");
gd1.addChoice("Constrain registration?", limitsReg, sCurrChoice);
limitCh = (Choice) gd1.getChoices().lastElement();
for (d=0;d<nDimReg;d++)
{
switch (sCurrChoice)
Expand Down Expand Up @@ -204,8 +209,8 @@ public void run(String paramString) {
Prefs.set("RegisterNDFFT.IA.nIniTemplate", sIniTemplate[nIniTemplate]);
nIterN = (int)gd1.getNextNumber();
Prefs.set("RegisterNDFFT.IA.nIterN", nIterN);
bExcludeZeros = gd1.getNextBoolean();
Prefs.set("RegisterNDFFT.IA.bExcludeZeros", bExcludeZeros);
bZeroMask = gd1.getNextBoolean();
Prefs.set("RegisterNDFFT.IA.bExcludeZeros", bZeroMask);
bIntermediateAverage = gd1.getNextBoolean();
Prefs.set("RegisterNDFFT.IA.bShowIntermediateAverage", bIntermediateAverage);
bSaveIntermediate = gd1.getNextBoolean();
Expand Down Expand Up @@ -278,13 +283,13 @@ public void run(String paramString) {
}
}

if(bExcludeZeros)
if(bZeroMask)
{
IJ.log("Excluding zeros: true.");
IJ.log("Using zero masked cross-correlation.");
}
else
{
IJ.log("Excluding zeros: false.");
IJ.log("Using non-masked cross-correlation.");
}


Expand Down Expand Up @@ -324,7 +329,7 @@ public void run(String paramString) {

GenNormCC normCC = new GenNormCC();
normCC.bVerbose = false;
normCC.bExcludeZeros = bExcludeZeros;
normCC.bZeroMask = bZeroMask;
normCC.lim_fractions = lim_fractions;
normCC.limInterval = limInterval;
normCC.bCenteredLimit = true;
Expand Down Expand Up @@ -660,12 +665,12 @@ public double buildShiftedIntervals(final ArrayList<RandomAccessibleInterval< Fl

public void medianCorrectShifts(final long [][] shifts_in)
{
int i,j;
int d = shifts_in[0].length;
int imN = shifts_in.length;
long [] dimX = new long[imN];
int j;
final int d = shifts_in[0].length;
final int imN = shifts_in.length;
final long [] dimX = new long[imN];
long median;
for(i=0;i<d;i++)
for(int i=0;i<d;i++)
{
for(j=0;j<imN;j++)
{
Expand Down Expand Up @@ -709,13 +714,10 @@ public boolean dialogItemChanged(GenericDialog gd, AWTEvent e) {
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
DecimalFormat df1 = new DecimalFormat ("#.##", symbols);
int nCh = 1;
if(imageSet.bMultiCh)
nCh = 2;
Choice limit = (Choice) gd.getChoices().get(nCh);
if(e.getSource()==limit)

if(e.getSource()==limitCh)
{
switch (limit.getSelectedIndex())
switch (limitCh.getSelectedIndex())
{
case 0:
for(d=0;d<nDimReg;d++)
Expand Down
Loading

0 comments on commit 82b9c80

Please sign in to comment.