/*- * #%L * Fiji's plugin for colocalization analysis. * %% * Copyright (C) 2009 - 2017 Fiji developers. * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program. If not, see * . * #L% */ package tests; import net.imglib2.RandomAccessibleInterval; import net.imglib2.algorithm.math.ImageStatistics; import net.imglib2.img.Img; import net.imglib2.type.logic.BitType; import net.imglib2.type.numeric.RealType; import net.imglib2.type.numeric.integer.UnsignedByteType; import org.junit.After; import org.junit.Before; import gadgets.MaskFactory; public abstract class ColocalisationTest { // images and meta data for zero correlation RandomAccessibleInterval zeroCorrelationImageCh1; RandomAccessibleInterval zeroCorrelationImageCh2; RandomAccessibleInterval zeroCorrelationAlwaysTrueMask; double zeroCorrelationImageCh1Mean; double zeroCorrelationImageCh2Mean; // images and meta data for positive correlation test // and real noisy image Manders' coeff with mask test RandomAccessibleInterval positiveCorrelationImageCh1; RandomAccessibleInterval positiveCorrelationImageCh2; // open mask image as a bit type cursor Img positiveCorrelationMaskImage; RandomAccessibleInterval positiveCorrelationAlwaysTrueMask; double positiveCorrelationImageCh1Mean; double positiveCorrelationImageCh2Mean; // images and meta data for a synthetic negative correlation dataset RandomAccessibleInterval syntheticNegativeCorrelationImageCh1; RandomAccessibleInterval syntheticNegativeCorrelationImageCh2; RandomAccessibleInterval syntheticNegativeCorrelationAlwaysTrueMask; double syntheticNegativeCorrelationImageCh1Mean; double syntheticNegativeCorrelationImageCh2Mean; // images like in the Manders paper RandomAccessibleInterval mandersA, mandersB, mandersC, mandersD, mandersE, mandersF, mandersG, mandersH, mandersI; RandomAccessibleInterval mandersAlwaysTrueMask; /** * This method is run before every single test is run and is meant to set up * the images and meta data needed for testing image colocalisation. */ @Before public void setup() { zeroCorrelationImageCh1 = TestImageAccessor.loadTiffFromJar("/greenZstack.tif"); zeroCorrelationImageCh1Mean = ImageStatistics.getImageMean(zeroCorrelationImageCh1); zeroCorrelationImageCh2 = TestImageAccessor.loadTiffFromJar("/redZstack.tif"); zeroCorrelationImageCh2Mean = ImageStatistics.getImageMean(zeroCorrelationImageCh2); final long[] dimZeroCorrCh1 = new long[ zeroCorrelationImageCh1.numDimensions() ]; zeroCorrelationImageCh1.dimensions(dimZeroCorrCh1); zeroCorrelationAlwaysTrueMask = MaskFactory.createMask(dimZeroCorrCh1, true); positiveCorrelationImageCh1 = TestImageAccessor.loadTiffFromJar("/colocsample1b-green.tif"); positiveCorrelationImageCh1Mean = ImageStatistics.getImageMean(positiveCorrelationImageCh1); positiveCorrelationImageCh2 = TestImageAccessor.loadTiffFromJar("/colocsample1b-red.tif"); positiveCorrelationImageCh2Mean = ImageStatistics.getImageMean(positiveCorrelationImageCh2); positiveCorrelationMaskImage = TestImageAccessor.loadTiffFromJarAsImg("/colocsample1b-mask.tif"); final long[] dimPosCorrCh1 = new long[ positiveCorrelationImageCh1.numDimensions() ]; positiveCorrelationImageCh1.dimensions(dimPosCorrCh1); positiveCorrelationAlwaysTrueMask = MaskFactory.createMask(dimPosCorrCh1, true); syntheticNegativeCorrelationImageCh1 = TestImageAccessor.loadTiffFromJar("/syntheticNegCh1.tif"); syntheticNegativeCorrelationImageCh1Mean = ImageStatistics.getImageMean(syntheticNegativeCorrelationImageCh1); syntheticNegativeCorrelationImageCh2 = TestImageAccessor.loadTiffFromJar("/syntheticNegCh2.tif"); syntheticNegativeCorrelationImageCh2Mean = ImageStatistics.getImageMean(syntheticNegativeCorrelationImageCh2); final long[] dimSynthNegCorrCh1 = new long[ syntheticNegativeCorrelationImageCh1.numDimensions() ]; syntheticNegativeCorrelationImageCh1.dimensions(dimSynthNegCorrCh1); syntheticNegativeCorrelationAlwaysTrueMask = MaskFactory.createMask(dimSynthNegCorrCh1, true); mandersA = TestImageAccessor.loadTiffFromJar("/mandersA.tiff"); mandersB = TestImageAccessor.loadTiffFromJar("/mandersB.tiff"); mandersC = TestImageAccessor.loadTiffFromJar("/mandersC.tiff"); mandersD = TestImageAccessor.loadTiffFromJar("/mandersD.tiff"); mandersE = TestImageAccessor.loadTiffFromJar("/mandersE.tiff"); mandersF = TestImageAccessor.loadTiffFromJar("/mandersF.tiff"); mandersG = TestImageAccessor.loadTiffFromJar("/mandersG.tiff"); mandersH = TestImageAccessor.loadTiffFromJar("/mandersH.tiff"); mandersI = TestImageAccessor.loadTiffFromJar("/mandersI.tiff"); final long[] dimMandersA = new long[ mandersA.numDimensions() ]; mandersA.dimensions(dimMandersA); mandersAlwaysTrueMask = MaskFactory.createMask(dimMandersA, true); } /** * This method is run after every single test and is meant to clean up. */ @After public void cleanup() { // nothing to do } /** * Creates a ROI offset array with a distance of 1/4 to the origin * in each dimension. */ protected > long[] createRoiOffset(RandomAccessibleInterval img) { final long[] offset = new long[ img.numDimensions() ]; img.dimensions(offset); for (int i=0; i> long[] createRoiSize(RandomAccessibleInterval img) { final long[] size = new long[ img.numDimensions() ]; img.dimensions(size); for (int i=0; i