From 1e0e063a7aefd6361220e38e07dac540c500f9cc Mon Sep 17 00:00:00 2001 From: Eugene Katrukha Date: Mon, 25 Mar 2024 14:27:04 +0100 Subject: [PATCH] v.0.0.7 --- .gitignore | 2 - src/main/java/correlescence/Temporal_ICS.java | 192 +++++++++++++----- src/test/java/tests/TICSTest.java | 16 ++ 3 files changed, 153 insertions(+), 57 deletions(-) create mode 100644 src/test/java/tests/TICSTest.java diff --git a/.gitignore b/.gitignore index d3bdf20..731eb43 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ -bin -/bin/ /target/ /.settings/ diff --git a/src/main/java/correlescence/Temporal_ICS.java b/src/main/java/correlescence/Temporal_ICS.java index 53cf138..5443170 100644 --- a/src/main/java/correlescence/Temporal_ICS.java +++ b/src/main/java/correlescence/Temporal_ICS.java @@ -31,7 +31,7 @@ public class Temporal_ICS implements PlugIn { /** correlation normalization method * 0 = overlap area * 1 = full area **/ - int nNormMethod=1; + int nNormMethod = 0; /** object calculating correlation **/ imCC1D x1D = new imCC1D(); @@ -56,9 +56,14 @@ public class Temporal_ICS implements PlugIn { /** stack projection to subtract **/ int nProjMethod; + + /** find first/highest maximum or all of them**/ + int nMaxFindingMethod; + + public static final int MAX_First=0, MAX_max=1, MAX_all=2; - /** find first maximum **/ - boolean bFindFirstMax; + /** find CC maximum **/ + boolean bFindCCMax; /** estimate the period/frequency more precisely **/ boolean bSubFramePeak; @@ -72,6 +77,9 @@ public class Temporal_ICS implements PlugIn { /** rotated stack containing TICS **/ ImageStack ipICSRotated; + /** stack containing all CC maxima **/ + ImageStack isMaxLocations; + /** rescale CC image? **/ boolean bRescaleCC; @@ -93,6 +101,9 @@ public class Temporal_ICS implements PlugIn { String[] projMethods = {"Average Intensity", "Max Intensity", "Min Intensity", "Sum Slices", "Standard Deviation", "Median"}; + String[] maxMethods = + {"First maximum", "Highest Maximum", "All maxima"}; + String [] sOutput = new String [] { "Frequency","Period"}; String [] sOutputUnits = new String [] { @@ -111,7 +122,6 @@ public void run(String arg) ImagePlus finalImpMax=null; String sTitle; - // TODO Auto-generated method stub imp = IJ.getImage(); if (imp==null) @@ -235,7 +245,7 @@ else if (imp.getType() != ImagePlus.GRAY8 && imp.getType() != ImagePlus.GRAY16 & } //if we want to calculate maximum - if(bFindFirstMax) + if(bFindCCMax) { String sTitleMax = "TICS_"; if(nOutput==0) @@ -248,6 +258,18 @@ else if (imp.getType() != ImagePlus.GRAY8 && imp.getType() != ImagePlus.GRAY16 & sTitleMax = sTitleMax+"period_"; IJ.log("Reported TICS results represent period."); } + switch (nMaxFindingMethod) + { + case MAX_First: + IJ.log("Finding the first peak of auto-CC."); + break; + case MAX_max: + IJ.log("Finding the highest peak of auto-CC."); + break; + case MAX_all: + IJ.log("Finding all peaks of auto-CC."); + break; + } if(nOutputUnits==0) { IJ.log("Time units: frames."); @@ -256,11 +278,19 @@ else if (imp.getType() != ImagePlus.GRAY8 && imp.getType() != ImagePlus.GRAY16 & { IJ.log("Frame interval "+Double.toString(dTimeUnits)+ " "+outCal.getTimeUnit()); } - - finalImpMax = new ImagePlus(sTitleMax+sTitle,findMax(ipICSRotated,dMaxTol)); - finalImpMax.setCalibration(outCal); - finalImpMax.show(); - IJ.run(finalImpMax,"Fire",""); + + finalImpMax = findMax(ipICSRotated,dMaxTol,nMaxFindingMethod ,sTitleMax+sTitle); + + if(nMaxFindingMethod == MAX_all) + { + new ImagePlus("CC_max_pos_" + sTitle, resliceRotateStack(new ImagePlus("looped",isMaxLocations))).show(); + } + else + { + finalImpMax.setCalibration(outCal); + finalImpMax.show(); + IJ.run(finalImpMax,"Fire",""); + } } if(bICSfreqphase) { @@ -321,11 +351,18 @@ public void ICS_pixel() IJ.showStatus("Calculating temporal correlation..."); ipICSRotated = new ImageStack(nMaxUserDelayICS+1,origH); + if(nMaxFindingMethod == MAX_all) + { + isMaxLocations = new ImageStack(nMaxUserDelayICS+1,origH); + } for (nindW=0;nindW", Prefs.get("Correlescence.dMaxTolICS", 0.25), 1,7," "); + xTICSDial.addChoice("Analyze CC and find:", maxMethods, Prefs.get("Correlescence.ICSmaxmethod", "First maximum")); xTICSDial.addCheckbox("Subframe precision?", Prefs.get("Correlescence.ICSsubframepeak", true)); xTICSDial.addCheckbox("Show TICS stack?", Prefs.get("Correlescence.ICSshowTICSstack", false)); xTICSDial.addMessage("~~~~~~~ FFT ~~~~~~~"); @@ -389,12 +427,15 @@ public boolean xDialogTICS() nScaledH=(int)xTICSDial.getNextNumber(); Prefs.set("Correlescence.ICSrescaleH", nScaledH); - bFindFirstMax = xTICSDial.getNextBoolean(); - Prefs.set("Correlescence.ICSfindfirstmax", bFindFirstMax); + bFindCCMax = xTICSDial.getNextBoolean(); + Prefs.set("Correlescence.ICSfindfirstmax", bFindCCMax); dMaxTol=xTICSDial.getNextNumber(); Prefs.set("Correlescence.dMaxTolICS", dMaxTol); + nMaxFindingMethod = xTICSDial.getNextChoiceIndex(); + Prefs.set("Correlescence.ICSmaxmethod", maxMethods[nMaxFindingMethod]); + bSubFramePeak = xTICSDial.getNextBoolean(); Prefs.set("Correlescence.ICSsubframepeak", bSubFramePeak); @@ -448,7 +489,7 @@ public ImageProcessor getResliceRotatedSlice(ImagePlus imp_in, int nWidthPos) /** Function reslices (rotates) stack, so time becomes x and height becomes y) * **/ - public ImageStack resliceRotateStack(ImagePlus imp_in) + static public ImageStack resliceRotateStack(ImagePlus imp_in) { ImageStack rotatedIm; @@ -484,7 +525,8 @@ public ImageStack resliceRotateStack(ImagePlus imp_in) } /** function to find first maximum with given tolerance * in the (rotated) stack of TICS **/ - public FloatProcessor findMax(ImageStack imp_in, double tolerance) + public ImagePlus findMax(final ImageStack imp_in, final double tolerance, final int nMaxMethod, String sTitle) + //public FloatProcessor findMax(ImageStack imp_in, double tolerance) { int stackSize, inWidth, inHeight; int j,k; @@ -492,6 +534,7 @@ public FloatProcessor findMax(ImageStack imp_in, double tolerance) FloatProcessor ipFin; ImageProcessor ip; + ImageProcessor ipMaxLoc = null; double[] line = null; @@ -507,19 +550,30 @@ public FloatProcessor findMax(ImageStack imp_in, double tolerance) inWidth = imp_in.getWidth(); inHeight = imp_in.getHeight(); stackSize = imp_in.getSize(); - ipFin = new FloatProcessor(stackSize,inHeight); - + if(nMaxFindingMethod != MAX_all) + { + ipFin = new FloatProcessor(stackSize,inHeight); + } + else + { + ipFin = null; + } IJ.showStatus("Estimating frequency/period.."); for (k=0;kmaxV) + { + maxInd = i; + maxV=line[maxInd]; + } + } + } + //all maxima, store it in imageprocessor + if(nMaxMethod == MAX_all) + { + for (int i=0;i 1 && maxInd 1 && maxInd