From 0f12c2db67f258e570610a714c9fe390f1af1dcb Mon Sep 17 00:00:00 2001 From: Eugene Katrukha Date: Wed, 1 May 2024 16:42:25 +0200 Subject: [PATCH] optimized CC --- src/main/java/averagingND/GenNormCC.java | 6 +- src/main/java/averagingND/ImageSet.java | 11 +- .../java/averagingND/IterativeAveraging.java | 6 +- .../LogPolarToCartesianTransform2D.java | 2 +- src/main/java/averagingND/MaskedNormCC.java | 447 ++++++++++++++++++ src/main/java/averagingND/PairWiseCC.java | 4 +- .../java/averagingND/RegisterSingleND.java | 6 +- src/main/java/averagingND/RotationCC.java | 5 +- .../java/averagingND/TemplateAveraging.java | 1 - src/test/java/tests/optimizeCC.java | 62 +++ src/test/java/tests/virtualWrapTest.java | 2 +- 11 files changed, 526 insertions(+), 26 deletions(-) create mode 100644 src/main/java/averagingND/MaskedNormCC.java create mode 100644 src/test/java/tests/optimizeCC.java diff --git a/src/main/java/averagingND/GenNormCC.java b/src/main/java/averagingND/GenNormCC.java index 8990322..3ae0f64 100644 --- a/src/main/java/averagingND/GenNormCC.java +++ b/src/main/java/averagingND/GenNormCC.java @@ -27,7 +27,7 @@ import net.imglib2.util.Intervals; import net.imglib2.view.IntervalView; import net.imglib2.view.Views; - +@Deprecated public class GenNormCC { /** dimensionality of images **/ @@ -59,7 +59,9 @@ public class GenNormCC { * the boundaries are always strange **/ final double max_fraction_shift = 0.9; - /** + /** //ImagePlus imageIn = IJ.openVirtual("/home/eugene/Desktop/projects/UnequalTiffs/BB/001f.tif"); + //Img< FloatType >img = FloatTiffImgWrap.wrapVirtualFloat(imageIn, MiscUtils.getDimensionsTextImageJ(imageIn)); + //ImageJFunctions.show(img, "test_raw"); * @param image * @param template */ diff --git a/src/main/java/averagingND/ImageSet.java b/src/main/java/averagingND/ImageSet.java index f96452c..01ccbf5 100644 --- a/src/main/java/averagingND/ImageSet.java +++ b/src/main/java/averagingND/ImageSet.java @@ -15,10 +15,7 @@ import ij.ImagePlus; import ij.WindowManager; import ij.measure.Calibration; -import io.scif.config.SCIFIOConfig; -import io.scif.config.SCIFIOConfig.ImgMode; -import io.scif.img.ImgOpener; -import io.scif.img.SCIFIOImgPlus; + import net.imglib2.Cursor; import net.imglib2.RandomAccessibleInterval; import net.imglib2.converter.Converter; @@ -27,10 +24,6 @@ import net.imglib2.img.imageplus.ImagePlusImg; import net.imglib2.img.imageplus.ImagePlusImgFactory; import net.imglib2.type.Type; -import net.imglib2.type.numeric.ARGBType; -import net.imglib2.type.numeric.ComplexType; -import net.imglib2.type.numeric.integer.UnsignedByteType; -import net.imglib2.type.numeric.integer.UnsignedShortType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.view.Views; @@ -153,8 +146,6 @@ boolean initializeFromOpenWindows() return true; } - - @SuppressWarnings("unchecked") boolean loadAllImages() { int i; diff --git a/src/main/java/averagingND/IterativeAveraging.java b/src/main/java/averagingND/IterativeAveraging.java index a48968a..64aa50d 100644 --- a/src/main/java/averagingND/IterativeAveraging.java +++ b/src/main/java/averagingND/IterativeAveraging.java @@ -202,7 +202,8 @@ public void run(String paramString) { processIntermediate(0); } - GenNormCC normCC = new GenNormCC(); + //GenNormCC normCC = new GenNormCC(); + MaskedNormCC normCC = new MaskedNormCC(); normCC.bVerbose = false; normCC.bZeroMask = bZeroMask; normCC.lim_fractions = lim_fractions; @@ -268,7 +269,8 @@ public void run(String paramString) { //currAverageImg = removeOneAverage(sumAndCount,imgs_shift.get(i)); //ImageJFunctions.show(currAverageImg, "aver"+Integer.toString(i+1)); //removeOneAverage - normCC.caclulateGenNormCC(Views.zeroMin(currAverageImg), imageSet.imgs.get(i), false); + //normCC.caclulateGenNormCC(Views.zeroMin(currAverageImg), imageSet.imgs.get(i), false); + normCC.caclulateMaskedNormCC(Views.zeroMin(currAverageImg), imageSet.imgs.get(i), false); avrgCC+=normCC.dMaxCC; listCC[i]=normCC.dMaxCC; diff --git a/src/main/java/averagingND/LogPolarToCartesianTransform2D.java b/src/main/java/averagingND/LogPolarToCartesianTransform2D.java index 9e1c289..d35af7b 100644 --- a/src/main/java/averagingND/LogPolarToCartesianTransform2D.java +++ b/src/main/java/averagingND/LogPolarToCartesianTransform2D.java @@ -4,7 +4,7 @@ import net.imglib2.RealPositionable; import net.imglib2.realtransform.InverseRealTransform; import net.imglib2.realtransform.InvertibleRealTransform; -import net.imglib2.realtransform.PolarToCartesianTransform2D; + public class LogPolarToCartesianTransform2D implements InvertibleRealTransform { diff --git a/src/main/java/averagingND/MaskedNormCC.java b/src/main/java/averagingND/MaskedNormCC.java new file mode 100644 index 0000000..54732bc --- /dev/null +++ b/src/main/java/averagingND/MaskedNormCC.java @@ -0,0 +1,447 @@ +package averagingND; + +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +import ij.IJ; +import net.imglib2.Cursor; +import net.imglib2.FinalDimensions; +import net.imglib2.FinalInterval; +import net.imglib2.Point; +import net.imglib2.RandomAccessibleInterval; +import net.imglib2.algorithm.fft2.FFT; +import net.imglib2.algorithm.fft2.FFTMethods; +import net.imglib2.converter.Converters; +import net.imglib2.img.Img; +import net.imglib2.img.ImgFactory; +import net.imglib2.img.array.ArrayImg; +import net.imglib2.img.array.ArrayImgFactory; +import net.imglib2.img.array.ArrayImgs; +import net.imglib2.img.basictypeaccess.array.FloatArray; +import net.imglib2.img.display.imagej.ImageJFunctions; +import net.imglib2.loops.LoopBuilder; +import net.imglib2.parallel.Parallelization; +import net.imglib2.parallel.TaskExecutor; +import net.imglib2.type.numeric.complex.ComplexFloatType; +import net.imglib2.type.numeric.real.FloatType; +import net.imglib2.util.Intervals; +import net.imglib2.view.IntervalView; +import net.imglib2.view.Views; + +public class MaskedNormCC { + /** dimensionality of images **/ + private int nDim; + + /** maximum of norm cross-correlation coefficient **/ + public double dMaxCC; + + /** final shift of the template to be aligned (corresponding to CC max) **/ + public long [] dShift; + + /** whether to log results to IJ.log window **/ + public boolean bVerbose = true; + + /** whether to exclude/ignore voxels that are zeros **/ + public boolean bZeroMask = false; + + /** window limit of CC max localization as a fraction of max displacement **/ + public double [] lim_fractions = null; + + /** absolute window limit (in voxels) of CC max localization **/ + public FinalInterval limInterval = null; + + /** if false, the limits window of displacement applied to the origin of coordinates, + * if true, it is applied around position where both images are centered **/ + public boolean bCenteredLimit = false; + + /** the fraction of max displacement where norm CC looks ok, + * the boundaries are always strange **/ + final double max_fraction_shift = 0.9; + + ExecutorService es; + TaskExecutor taskExecutor; + + /** + * @param image + * @param template + */ + public boolean caclulateMaskedNormCC(final RandomAccessibleInterval< FloatType > image, final RandomAccessibleInterval< FloatType > template, final boolean bShowCC) + { + int i; + + if(image.numDimensions()!=template.numDimensions()) + { + IJ.log("Error! Different number of dimensions between reference and template images!"); + return false; + } + + nDim = image.numDimensions(); + if(lim_fractions!= null) + { + if(lim_fractions.length!=nDim) + { + IJ.log("Error! Constrain on registration for fraction of image has different dimensions!"); + return false; + } + if(limInterval != null) + { + IJ.log("Warning! multiple constrains (both fraction and pixel)!"); + } + + } + if(limInterval != null) + { + if(limInterval.numDimensions()!=nDim) + { + IJ.log("Error! Constrain on registration in pixels has different dimensions!"); + return false; + } + } + + dShift = new long [nDim]; + long [] imgDim = new long[nDim]; + long [] temDim = new long[nDim]; + image.dimensions(imgDim); + template.dimensions(temDim); + final long [] finDim = new long [nDim]; + for(i=0;i padImg = Views.interval(Views.extendZero(image),imgIntPad); + IntervalView< FloatType > padTem = Views.interval(Views.extendZero(template),temIntPad); + //ImageJFunctions.show(padImg).setTitle( "padded1" ); + //ImageJFunctions.show(padTem).setTitle( "padded2" ); + + //unity images + final ArrayImg unityImg = ArrayImgs.floats(imgDim); + final ArrayImg unityTem = ArrayImgs.floats(temDim); + + if(!bZeroMask) + { + unityImg.forEach(t->t.set(1.0f)); + unityTem.forEach(t->t.set(1.0f)); + } + else + { + //reference image + Cursor< FloatType > unC = unityImg.cursor(); + IntervalView< FloatType > intImg = Views.interval(image,image); + Cursor< FloatType > inC = intImg.cursor(); + while(unC.hasNext()) + { + unC.fwd(); + inC.fwd(); + if(inC.get().get()==0.0f) + { + unC.get().set(0.0f); + } + else + { + unC.get().set(1.0f); + } + } + //template image + unC = unityTem.cursor(); + intImg = Views.interval(template,template); + inC = intImg.cursor(); + while(unC.hasNext()) + { + unC.fwd(); + inC.fwd(); + if(inC.get().get()==0.0f) + { + unC.get().set(0.0f); + } + else + { + unC.get().set(1.0f); + } + } + } + //padded unity images + IntervalView< FloatType > padUnitImg = Views.interval(Views.extendZero(unityImg),imgIntPad); + IntervalView< FloatType > padUnitTem = Views.interval(Views.extendZero(unityTem),temIntPad); + //ImageJFunctions.show(padUnitImg).setTitle( "unipadded1" ); + //ImageJFunctions.show(padUnitTem).setTitle( "unipadded2" ); + + //squared image values + //Img< FloatType > sqImg = ImgView.wrap(image).copy(); + //Img< FloatType > sqTem = ImgView.wrap(template).copy(); + //sqImg.forEach(t-> t.mul(t.get())); + //sqTem.forEach(t-> t.mul(t.get())); + RandomAccessibleInterval< FloatType > sqImg = Converters.convert(image, ( in,out )-> {out.set(in.get()*in.get());}, new FloatType()); + RandomAccessibleInterval< FloatType > sqTem = Converters.convert(template, ( in,out )-> {out.set(in.get()*in.get());}, new FloatType()); + + //padded squared images + IntervalView< FloatType > padSqImg = Views.interval(Views.extendZero(sqImg),imgIntPad); + IntervalView< FloatType > padSqTem = Views.interval(Views.extendZero(sqTem),temIntPad); + + //ImageJFunctions.show(padSqImg).setTitle( "sqpadded1" ); + //ImageJFunctions.show(padSqTem).setTitle( "sqpadded2" ); + + final ImgFactory< ComplexFloatType > factoryComplex = new ArrayImgFactory< ComplexFloatType >(new ComplexFloatType()); + final ImgFactory< FloatType > factoryFloat = new ArrayImgFactory< FloatType >(new FloatType()); + + + final int nThreads = Runtime.getRuntime().availableProcessors(); + es = Executors.newFixedThreadPool( nThreads ); + //start with FFT + final Img< ComplexFloatType > imageFFT2 = FFT.realToComplex(padImg, factoryComplex,es); + final Img< ComplexFloatType > templateFFT2 = FFT.realToComplex(padTem, factoryComplex,es); + final Img< ComplexFloatType > unImageFFT2 = FFT.realToComplex(padUnitImg, factoryComplex,es); + final Img< ComplexFloatType > unTemplateFFT2 = FFT.realToComplex(padUnitTem, factoryComplex,es); + final Img< ComplexFloatType > sqImageFFT2 = FFT.realToComplex(padSqImg, factoryComplex,es); + final Img< ComplexFloatType > sqTemplateFFT2 = FFT.realToComplex(padSqTem, factoryComplex,es); + + //conjugates + FFTMethods.complexConjugate(templateFFT2); + FFTMethods.complexConjugate(unTemplateFFT2); + FFTMethods.complexConjugate(sqTemplateFFT2); + taskExecutor = Parallelization.getTaskExecutor(); + //System.out.println( taskExecutor.suggestNumberOfTasks()); + + //multiplications + //reuse already allocated arrays + final Img< ComplexFloatType > I1F2F2 = multComplInPlaceSecond(unImageFFT2,sqTemplateFFT2,taskExecutor); + final Img< ComplexFloatType > F1F1I2 = multComplInPlaceSecond(unTemplateFFT2,sqImageFFT2,taskExecutor); + + final Img< ComplexFloatType > deNOM = multCompl(unImageFFT2,unTemplateFFT2,taskExecutor); + final Img< ComplexFloatType > I1F2 = multComplInPlaceSecond(templateFFT2,unImageFFT2,taskExecutor); + final Img< ComplexFloatType > F1I2 = multComplInPlaceSecond(imageFFT2,unTemplateFFT2,taskExecutor); + final Img< ComplexFloatType > F1F2 = multComplInPlaceSecond(templateFFT2,imageFFT2,taskExecutor); + + //inverse FFT + final Img< FloatType > invdeNOM = FFT.complexToReal(deNOM, factoryFloat, new FloatType(),es); + final Img< FloatType > invF1F2 = FFT.complexToReal(F1F2, factoryFloat, new FloatType(),es); + final Img< FloatType > invF1I2 = FFT.complexToReal(F1I2, factoryFloat, new FloatType(),es); + final Img< FloatType > invI1F2 = FFT.complexToReal(I1F2, factoryFloat, new FloatType(),es); + final Img< FloatType > invF1F1I2 = FFT.complexToReal(F1F1I2, factoryFloat, new FloatType(),es); + final Img< FloatType > invI1F2F2 = FFT.complexToReal(I1F2F2, factoryFloat, new FloatType(),es); + es.shutdown(); + //ImageJFunctions.show(invdeNOM).setTitle( "denom" ); + //ImageJFunctions.show(invF1F2).setTitle( "invF1F2" ); + //ImageJFunctions.show(invF1I2).setTitle( "invF1I2" ); + //ImageJFunctions.show(invI1F2).setTitle( "invI1F2" ); + //ImageJFunctions.show(invF1F1I2).setTitle( "invF1F1I2" ); + //ImageJFunctions.show(invI1F2F2).setTitle( "invI1F2F2" ); + + calcTermNum(invF1F2,invF1I2,invI1F2,invdeNOM,taskExecutor); + calcTermDenom(invF1F1I2,invF1I2,invF1I2,invdeNOM,taskExecutor); + calcTermDenom(invI1F2F2,invI1F2,invI1F2,invdeNOM,taskExecutor); + + + taskExecutor.close(); + //ImageJFunctions.show(invF1F2).setTitle( "term0" ); + //ImageJFunctions.show(invF1F1I2).setTitle( "term1" ); + //ImageJFunctions.show(invI1F2F2).setTitle( "term2" ); + + final Cursor< FloatType > denom1 = invF1F1I2.cursor(); + final Cursor< FloatType > denom2 = invI1F2F2.cursor(); + float maxVal = Float.MIN_VALUE; + float t2, t3; + + //calculate denominator and its max value + //to estimate precision later + while(denom1.hasNext()) + { + denom1.fwd(); + denom2.fwd(); + t2 = denom1.get().get(); + t3 = denom2.get().get(); + t2 = (float)Math.sqrt(t2*t3); + denom1.get().set(t2); + if(t2>maxVal) + { + maxVal=t2; + } + } + + //numerator and denominator + double tol = Math.abs(maxVal)*1E-4;//float precision limit + final Cursor< FloatType > numCurs = invF1F2.cursor(); + final Cursor< FloatType > denomCurs = invF1F1I2.cursor(); + + while(numCurs.hasNext()) + { + numCurs.fwd(); + denomCurs.fwd(); + + t2 = denomCurs.get().get(); + //check if the value within precision tolerance + if(t2>tol) + { + numCurs.get().mul(1.0f/t2); + } + else + { + numCurs.get().set(0.0f); + } + } + + + long [][] cropCorr = new long[2][nDim]; + long [][] cropFraction = new long[2][nDim]; + + //determine the maximum area (intervalCrop) of shifts for template with respect to original image + double nHalfSpan, nCenter; + + for(i=0;i ivCCswapped; + //full available shift space + ivCCswapped = Views.interval(Views.translate(Views.extendPeriodic( invF1F2 ), nCCOrigin),intervalFull); + + //let's apply constrains + + //voxel constrains + if(limInterval != null) + { + FinalInterval intConstrainPx; + //centered, let's move to the center + if(bCenteredLimit) + { + intConstrainPx = Intervals.intersect(ivCCswapped, Intervals.translate(limInterval, nCCOrigin)); + + } + //from the origin, no need to move + else + { + intConstrainPx = Intervals.intersect(ivCCswapped, limInterval); + } + ivCCswapped = Views.interval(ivCCswapped, intConstrainPx); + } + //fractional constrains + if(lim_fractions != null) + { + //centered, let's move to the center + if(bCenteredLimit) + { + constrainFr = Intervals.translate(constrainFr, nCCOrigin); + + } + + ivCCswapped = Views.interval(ivCCswapped, constrainFr); + } + + + if(bShowCC) + { + ImageJFunctions.show(ivCCswapped).setTitle( "General cross-correlation" ); + } + + //now find max value + Point shift = new Point(nDim); + + FloatType fCCvalue; + + fCCvalue = MiscUtils.computeMaxLocation(ivCCswapped,shift); + + if (bVerbose) + { + String sOutput = "Translation for template to overlap with image (px):\n("+Integer.toString(shift.getIntPosition(0)) ; + for(i=1;i im1, final Img< FloatType > im2,final Img< FloatType > im3, final Img< FloatType > im4, final TaskExecutor te) + { + + LoopBuilder.setImages(im1, im2, im3, im4).multiThreaded(te) + .forEachPixel( + (p1,p2,p3,p4)-> + { + p1.set(p1.getRealFloat()-(p2.getRealFloat()*p3.getRealFloat()/p4.getRealFloat())); + } + + ); + + } + public static void calcTermDenom(final Img< FloatType > im1, final Img< FloatType > im2,final Img< FloatType > im3, final Img< FloatType > im4, final TaskExecutor te) + { + + LoopBuilder.setImages(im1, im2, im3, im4).multiThreaded(te) + .forEachPixel( + (p1,p2,p3,p4)-> + { + p1.set(Math.max(p1.getRealFloat()-(p2.getRealFloat()*p3.getRealFloat()/p4.getRealFloat()),0)); + } + + ); + + + } + public static Img< ComplexFloatType > multCompl(final Img< ComplexFloatType > im1, final Img< ComplexFloatType > im2, final TaskExecutor te) + { + Img< ComplexFloatType > output = im1.copy(); + LoopBuilder.setImages(im2,output).multiThreaded(te).forEachPixel((s,t)->t.mul(s)); + + return output; + } + public static Img< ComplexFloatType > multComplInPlaceSecond(final Img< ComplexFloatType > im1, final Img< ComplexFloatType > im2, final TaskExecutor te) + { + + + LoopBuilder.setImages(im1,im2).multiThreaded(te).forEachPixel((s,t)->t.mul(s)); + + return im2; + } +} diff --git a/src/main/java/averagingND/PairWiseCC.java b/src/main/java/averagingND/PairWiseCC.java index 84f66b0..9cfc8f2 100644 --- a/src/main/java/averagingND/PairWiseCC.java +++ b/src/main/java/averagingND/PairWiseCC.java @@ -229,7 +229,7 @@ public void run(String arg) { final int nImageN = imageSet.nImageN; - GenNormCC normCC = new GenNormCC(); + MaskedNormCC normCC = new MaskedNormCC(); normCC.bVerbose = false; normCC.bZeroMask = bZeroMask; normCC.lim_fractions = lim_fractions; @@ -246,7 +246,7 @@ public void run(String arg) { { for(j=i+1;j image_in = ImagePlusAdapter.convertFloat(imp1); final Img< FloatType > template_in = ImagePlusAdapter.convertFloat(imp2); - GenNormCC normCC = new GenNormCC(); + MaskedNormCC normCC = new MaskedNormCC(); normCC.bZeroMask = bZeroMask; normCC.lim_fractions = lim_fractions; @@ -256,11 +256,11 @@ public void run(String arg) { if(multiCh) { - bNormCCcalc= normCC.caclulateGenNormCC(Views.hyperSlice(image_in, 2, regChannel1), Views.hyperSlice(template_in, 2, regChannel2), bShowCC);//, bRegisterTemplate); + bNormCCcalc= normCC.caclulateMaskedNormCC(Views.hyperSlice(image_in, 2, regChannel1), Views.hyperSlice(template_in, 2, regChannel2), bShowCC);//, bRegisterTemplate); } else { - bNormCCcalc = normCC.caclulateGenNormCC(image_in, template_in, bShowCC);//, bRegisterTemplate); + bNormCCcalc = normCC.caclulateMaskedNormCC(image_in, template_in, bShowCC);//, bRegisterTemplate); } if(!bNormCCcalc) { diff --git a/src/main/java/averagingND/RotationCC.java b/src/main/java/averagingND/RotationCC.java index 70dd7e2..8108993 100644 --- a/src/main/java/averagingND/RotationCC.java +++ b/src/main/java/averagingND/RotationCC.java @@ -7,11 +7,9 @@ import net.imglib2.RandomAccessibleInterval; import net.imglib2.algorithm.fft2.FFT; import net.imglib2.algorithm.fft2.FFTMethods; -import net.imglib2.converter.ComplexPowerFloatConverter; import net.imglib2.converter.ComplexPowerGLogFloatConverter; import net.imglib2.converter.Converters; import net.imglib2.img.Img; -import net.imglib2.algorithm.gauss.Gauss; import net.imglib2.img.ImgFactory; import net.imglib2.img.array.ArrayImgFactory; import net.imglib2.img.display.imagej.ImageJFunctions; @@ -21,7 +19,6 @@ import net.imglib2.realtransform.PolarToCartesianTransform2D; import net.imglib2.realtransform.RealViews; import net.imglib2.realtransform.Scale2D; -import net.imglib2.realtransform.Scale3D; import net.imglib2.type.numeric.complex.ComplexFloatType; import net.imglib2.type.numeric.real.FloatType; import net.imglib2.view.IntervalView; @@ -38,7 +35,7 @@ public class RotationCC { */ public boolean caclulateRotationFFTCC(final RandomAccessibleInterval< FloatType > image, final RandomAccessibleInterval< FloatType > template) { - int i; + //int i; //double [] finData; diff --git a/src/main/java/averagingND/TemplateAveraging.java b/src/main/java/averagingND/TemplateAveraging.java index 149eba9..8970803 100644 --- a/src/main/java/averagingND/TemplateAveraging.java +++ b/src/main/java/averagingND/TemplateAveraging.java @@ -7,7 +7,6 @@ import net.imglib2.RandomAccessibleInterval; 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; diff --git a/src/test/java/tests/optimizeCC.java b/src/test/java/tests/optimizeCC.java new file mode 100644 index 0000000..0d2ed8c --- /dev/null +++ b/src/test/java/tests/optimizeCC.java @@ -0,0 +1,62 @@ +package tests; + + +import averagingND.FloatTiffImgWrap; +import averagingND.GenNormCC; +import averagingND.MaskedNormCC; +import averagingND.MiscUtils; +import ij.IJ; +import ij.ImageJ; +import ij.ImagePlus; +import net.imglib2.FinalInterval; +import net.imglib2.img.ImagePlusAdapter; +import net.imglib2.img.Img; +import net.imglib2.img.display.imagej.ImageJFunctions; +import net.imglib2.type.numeric.real.FloatType; +import net.imglib2.util.StopWatch; +import net.imglib2.view.IntervalView; +import net.imglib2.view.Views; + +public class optimizeCC +{ + public static void main( final String[] args ) + { + + new ImageJ(); + + //ImagePlus image1 = IJ.openImage("/home/eugene/Desktop/projects/UnequalTiffs/BB/001ch2.tif"); + //ImagePlus image2 = IJ.openImage("/home/eugene/Desktop/projects/UnequalTiffs/BB/002ch2.tif"); + ImagePlus image1 = IJ.openImage("/home/eugene/Desktop/projects/UnequalTiffs/BB/001ch2.tif"); + ImagePlus image2 = IJ.openImage("/home/eugene/Desktop/projects/UnequalTiffs/BB/002ch2.tif"); + + Img ref = ImagePlusAdapter.convertFloat(image1); + Img temp = ImagePlusAdapter.convertFloat(image2); + + StopWatch stopwatch; + ImageJFunctions.show(ref,"ref"); + ImageJFunctions.show(temp,"temp"); + + + FinalInterval limit = new FinalInterval(new long[] {-20,-20,-20},new long[] {20,20,20}); + + MaskedNormCC newCC = new MaskedNormCC(); + newCC.bCenteredLimit = true; + newCC.limInterval = limit; + newCC.bZeroMask = true; + newCC.bVerbose = true; + stopwatch = StopWatch.createAndStart(); + newCC.caclulateMaskedNormCC(ref, temp, true); + System.out.println( "new CC time: " + stopwatch ); + + GenNormCC oldCC = new GenNormCC(); + oldCC.bCenteredLimit = true; + oldCC.limInterval = limit; + oldCC.bZeroMask = true; + oldCC.bVerbose = true; + stopwatch= StopWatch.createAndStart(); + oldCC.caclulateGenNormCC(ref, temp, true); + System.out.println( "old CC time: " + stopwatch ); + + } + +} diff --git a/src/test/java/tests/virtualWrapTest.java b/src/test/java/tests/virtualWrapTest.java index 73b6b46..4ee484a 100644 --- a/src/test/java/tests/virtualWrapTest.java +++ b/src/test/java/tests/virtualWrapTest.java @@ -16,7 +16,7 @@ public static void main( final String[] args ) { new ImageJ(); - ImagePlus imageIn = IJ.openVirtual("/home/eugene/Desktop/projects/UnequalTiffs/BB/001f.tif"); + ImagePlus imageIn = IJ.openImage("/home/eugene/Desktop/projects/UnequalTiffs/BB/001f.tif"); Img< FloatType >img = FloatTiffImgWrap.wrapVirtualFloat(imageIn, MiscUtils.getDimensionsTextImageJ(imageIn)); ImageJFunctions.show(img, "test_raw");