Search in sources :

Example 96 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class FluorescenceNoiseTest method doit.

private void doit() throws ImageException {
    int[] sizes = new int[] { 1, 2, 4, 8, 16, 32, 64, 128, 256 };
    for (int imageSize : sizes) {
        ISize size = new ISize(imageSize, imageSize, 1);
        Extent extent = new Extent(1, 1, 1);
        Origin origin = new Origin(0, 0, 0);
        // NormalizedSampleFunction sampleFunction = NormalizedSampleFunction.createUniform("uniformROI", origin, extent, size);
        NormalizedSampleFunction sampleFunction = NormalizedSampleFunction.fromGaussian("testGaussian", origin, extent, size, 0.5, 0.2, 0.1);
        SampleStatistics[] samples = new SampleStatistics[NUM_TRIALS];
        for (int i = 0; i < NUM_TRIALS; i++) {
            UShortImage rawImage = getUniformFluorescenceImage(size, extent, origin, MEAN_INTENSITY);
            samples[i] = sampleFunction.sample(rawImage);
        }
        Mean mean = new Mean();
        Variance var = new Variance();
        double[] weightedMeans = getWeightedMeans(samples);
        double[] weightedVariances = getWeightedVariances(samples);
        double weightedMeansVariance = var.evaluate(weightedMeans);
        double weightedMeansMean = mean.evaluate(weightedMeans);
        double weightedVarVariance = var.evaluate(weightedVariances);
        double weightedVarMean = mean.evaluate(weightedVariances);
        double V1 = samples[0].sumOfWeights;
        double V2 = samples[0].sumOfWeightsSquared;
        System.out.println("image is " + imageSize + "x" + imageSize + ", V1=" + V1 + ", V2=" + V2 + ", numTrials=" + NUM_TRIALS + ", sample means (mu=" + weightedMeansMean + ",s=" + weightedMeansVariance + "), sample variances (mu=" + weightedVarMean + ",s=" + weightedVarVariance);
    }
}
Also used : Origin(org.vcell.util.Origin) Mean(org.apache.commons.math3.stat.descriptive.moment.Mean) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) SampleStatistics(org.vcell.vmicro.workflow.data.NormalizedSampleFunction.SampleStatistics) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Variance(org.apache.commons.math3.stat.descriptive.moment.Variance) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction)

Example 97 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class FluorescenceNoiseTest method testImageTimeSeries.

private void testImageTimeSeries(boolean bNoise, boolean bConvolve) throws ImageException, IOException {
    Origin origin = new Origin(0, 0, 0);
    Extent extent = new Extent(10, 10, 1);
    int numX = 30;
    int numY = 30;
    // typically 10000 or 100000;
    int numParticles = 40000;
    double diffusionRate = 1;
    double bleachRadius = 5 * 5;
    double psfVar = 0.6 * 0.6;
    ImageTimeSeries<UShortImage> rawTimeSeries = generateTestData(origin, extent, numX, numY, numParticles, diffusionRate, psfVar, bleachRadius, bNoise, bConvolve);
    new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeries, "time series", null);
}
Also used : Origin(org.vcell.util.Origin) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) Extent(org.vcell.util.Extent) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 98 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class GenerateNormalizedPhotoactivationDataOp method generate.

public NormalizedPhotoactivationDataResults generate(ImageTimeSeries<UShortImage> rawImageTimeSeries, ROI backgroundROI_2D, Integer indexPostactivation, boolean backgroundSubtract, boolean normalizedByPreactivation) throws Exception {
    UShortImage preactivationImage = rawImageTimeSeries.getAllImages()[0];
    ISize isize = preactivationImage.getISize();
    int nX = isize.getX();
    int nY = isize.getY();
    int nZ = isize.getZ();
    int numTimes = rawImageTimeSeries.getSizeT();
    Extent extent = preactivationImage.getExtent();
    org.vcell.util.Origin origin = preactivationImage.getOrigin();
    if (indexPostactivation == 0) {
        throw new RuntimeException("no preactivation images found - indexOfFirstPostactivation is 0");
    }
    // 
    // find average "dark count" in background of pre-activation images (for background subtraction)
    // 
    float avgBackground = 0.0f;
    int numPreactivation = indexPostactivation;
    for (int i = 0; i < numPreactivation; i++) {
        avgBackground += getAverage(rawImageTimeSeries.getAllImages()[i], backgroundROI_2D);
    }
    avgBackground /= numPreactivation;
    // 
    // find averaged preactivation image (corrected for background).
    // 
    int numPostactivationImages = numTimes - numPreactivation;
    // holds new averaged image pixels
    float[] preactivationAveragePixels = new float[nX * nY * nZ];
    for (int i = 0; i < numPreactivation; i++) {
        short[] currPreactivationImage = rawImageTimeSeries.getAllImages()[i].getPixels();
        for (int j = 0; j < isize.getXYZ(); j++) {
            float intPixel = 0x0000ffff & ((int) currPreactivationImage[j]);
            preactivationAveragePixels[j] += intPixel / numPreactivation;
        }
    }
    FloatImage preactivationAverageImage = new FloatImage(preactivationAveragePixels, origin, extent, nX, nY, nZ);
    UShortImage firstPostactivationImage = rawImageTimeSeries.getAllImages()[indexPostactivation];
    // 
    // create normalized dataset
    // 
    // normalized postbleach = (origPostbleach - background)/(prebleach - background)
    // 
    FloatImage[] normalizedImages = new FloatImage[numPostactivationImages];
    double[] postactivationTimeStamps = new double[numPostactivationImages];
    for (int i = 0; i < numPostactivationImages; i++) {
        double[] origTimeStamps = rawImageTimeSeries.getImageTimeStamps();
        postactivationTimeStamps[i] = origTimeStamps[indexPostactivation + i] - origTimeStamps[indexPostactivation];
        float[] normalizedPixels = new float[isize.getXYZ()];
        normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
        short[] uncorrectedPixels = rawImageTimeSeries.getAllImages()[i + indexPostactivation].getPixels();
        for (int j = 0; j < isize.getXYZ(); j++) {
            int intUncorrectedPixel = 0x0000ffff & ((int) uncorrectedPixels[j]);
            float background = 0;
            if (backgroundSubtract) {
                background = avgBackground;
            }
            if (normalizedByPreactivation) {
                int intPreactivationAvgPixel = 0x0000ffff & ((int) preactivationAveragePixels[j]);
                normalizedPixels[j] = (intUncorrectedPixel - background) / (Math.max(1, intPreactivationAvgPixel - background));
            } else {
                normalizedPixels[j] = (intUncorrectedPixel - background);
            }
        }
        normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
    }
    ImageTimeSeries<FloatImage> normalizedData = new ImageTimeSeries<FloatImage>(FloatImage.class, normalizedImages, postactivationTimeStamps, nZ);
    NormalizedPhotoactivationDataResults results = new NormalizedPhotoactivationDataResults();
    results.normalizedPhotoactivationData = normalizedData;
    results.preactivationAverageImage = preactivationAverageImage;
    results.normalizedPostactivationImage = normalizedData.getAllImages()[0];
    return results;
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Aggregations

Extent (org.vcell.util.Extent)98 Origin (org.vcell.util.Origin)60 ISize (org.vcell.util.ISize)53 VCImageUncompressed (cbit.image.VCImageUncompressed)23 ImageException (cbit.image.ImageException)21 VCImage (cbit.image.VCImage)20 CartesianMesh (cbit.vcell.solvers.CartesianMesh)19 Geometry (cbit.vcell.geometry.Geometry)17 RegionImage (cbit.vcell.geometry.RegionImage)17 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)16 Expression (cbit.vcell.parser.Expression)16 IOException (java.io.IOException)15 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)13 BioModel (cbit.vcell.biomodel.BioModel)13 SubVolume (cbit.vcell.geometry.SubVolume)13 File (java.io.File)13 ArrayList (java.util.ArrayList)13 UserCancelException (org.vcell.util.UserCancelException)13 ExpressionException (cbit.vcell.parser.ExpressionException)12 PropertyVetoException (java.beans.PropertyVetoException)10