Search in sources :

Example 71 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.

the class FRAPData method fastDilate.

private UShortImage fastDilate(UShortImage dilateSource, int radius, UShortImage mask) throws ImageException {
    short[] sourcePixels = dilateSource.getPixels();
    short[] targetPixels = dilateSource.getPixels().clone();
    KernelJAI dilateKernel = createCircularBinaryKernel(radius);
    float[] kernelData = dilateKernel.getKernelData();
    BitSet kernelBitSet = new BitSet(kernelData.length);
    for (int i = 0; i < kernelData.length; i++) {
        if (kernelData[i] == 1.0f) {
            kernelBitSet.set(i);
        }
    }
    boolean bNeedsFill = false;
    for (int y = 0; y < dilateSource.getNumY(); y++) {
        int yOffset = y * dilateSource.getNumX();
        int yMinus = yOffset - dilateSource.getNumX();
        int yPlus = yOffset + dilateSource.getNumX();
        for (int x = 0; x < dilateSource.getNumX(); x++) {
            bNeedsFill = false;
            if (sourcePixels[x + yOffset] != 0) {
                if (x - 1 >= 0 && sourcePixels[(x - 1) + yOffset] == 0) {
                    bNeedsFill = true;
                } else if (y - 1 >= 0 && sourcePixels[x + yMinus] == 0) {
                    bNeedsFill = true;
                } else if (x + 1 < dilateSource.getNumX() && sourcePixels[(x + 1) + yOffset] == 0) {
                    bNeedsFill = true;
                } else if (y + 1 < dilateSource.getNumY() && sourcePixels[x + yPlus] == 0) {
                    bNeedsFill = true;
                }
                if (bNeedsFill) {
                    int masterKernelIndex = 0;
                    for (int y2 = y - radius; y2 <= y + radius; y2++) {
                        if (y2 >= 0 && y2 < dilateSource.getNumY()) {
                            int kernelIndex = masterKernelIndex;
                            int targetYIndex = y2 * dilateSource.getNumX();
                            for (int x2 = x - radius; x2 <= x + radius; x2++) {
                                if (kernelBitSet.get(kernelIndex) && x2 >= 0 && x2 < dilateSource.getNumX()) {
                                    targetPixels[targetYIndex + x2] = 1;
                                }
                                kernelIndex++;
                            }
                        }
                        masterKernelIndex += dilateKernel.getWidth();
                    }
                }
            }
        }
    }
    UShortImage resultImage = new UShortImage(targetPixels, dilateSource.getOrigin(), dilateSource.getExtent(), dilateSource.getNumX(), dilateSource.getNumY(), dilateSource.getNumZ());
    resultImage.and(mask);
    return resultImage;
}
Also used : KernelJAI(javax.media.jai.KernelJAI) BitSet(java.util.BitSet) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 72 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.

the class FRAPData method fixROIConstraints.

/**
 * must be consistent with checkBleachROIViolatesConstraints() and checkBackgroundROIViolatesConstraints()
 * @return
 * @throws Exception
 */
public boolean fixROIConstraints() throws Exception {
    short[] cellPixels = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getPixelsXYZ();
    short[] bleachPixels = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getPixelsXYZ();
    short[] backgroundPixels = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()).getPixelsXYZ();
    boolean bFixedBleach = false;
    boolean bFixedBackground = false;
    for (int i = 0; i < cellPixels.length; i++) {
        if (cellPixels[i] == 0 && bleachPixels[i] != 0) {
            bFixedBleach = true;
            bleachPixels[i] = 0;
        }
        if (cellPixels[i] != 0 && backgroundPixels[i] != 0) {
            bFixedBackground = true;
            backgroundPixels[i] = 0;
        }
    }
    if (bFixedBackground || bFixedBleach) {
        if (bFixedBleach) {
            UShortImage ushortImage = new UShortImage(bleachPixels, getCurrentlyDisplayedROI().getRoiImages()[0].getOrigin(), getCurrentlyDisplayedROI().getRoiImages()[0].getExtent(), getCurrentlyDisplayedROI().getISize().getX(), getCurrentlyDisplayedROI().getISize().getY(), getCurrentlyDisplayedROI().getISize().getZ());
            ROI newBleachROI = new ROI(ushortImage, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
            addReplaceRoi(newBleachROI);
        }
        if (bFixedBackground) {
            UShortImage ushortImage = new UShortImage(backgroundPixels, getCurrentlyDisplayedROI().getRoiImages()[0].getOrigin(), getCurrentlyDisplayedROI().getRoiImages()[0].getExtent(), getCurrentlyDisplayedROI().getISize().getX(), getCurrentlyDisplayedROI().getISize().getY(), getCurrentlyDisplayedROI().getISize().getZ());
            ROI newBackgroundROI = new ROI(ushortImage, FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
            addReplaceRoi(newBackgroundROI);
        }
        return true;
    } else // nothing to fix
    {
        return true;
    }
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 73 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.

the class FluorescenceNoiseTest method generateTestData.

private ImageTimeSeries<UShortImage> generateTestData(Origin origin, Extent extent, int numX, int numY, int numParticles, double diffusionRate, double psfVar, double bleachRadius, boolean bNoise, boolean bConvolve) throws ImageException {
    double detectorGainAndQuantumYeild = 100;
    double totalSampleTime = 0.5;
    int numSampleSteps = 1;
    int numPrebleach = 2;
    ArrayList<UShortImage> images = new ArrayList<UShortImage>();
    ArrayList<Double> times = new ArrayList<Double>();
    final BrownianDynamics2DSolver solver = new BrownianDynamics2DSolver(origin, extent, numParticles);
    boolean initiallyFluorescent = true;
    solver.initializeUniform(initiallyFluorescent);
    // simulate and write prebleach images
    for (int i = 0; i < numPrebleach; i++) {
        images.add(solver.sampleImage(numX, numY, origin, extent, diffusionRate, totalSampleTime, numSampleSteps, psfVar, detectorGainAndQuantumYeild, bConvolve, bNoise));
        times.add(solver.currentTime());
    }
    // bleach
    double totalBleachTime = 0.1;
    int numBleachSteps = 5;
    double bleachCenterX = origin.getX() + 0.5 * extent.getX();
    double bleachCenterY = origin.getY() + 0.5 * extent.getY();
    double bleachPsfVariance = bleachRadius;
    double bleachFactor_K = 10;
    solver.bleachGuassian(diffusionRate, totalBleachTime, numBleachSteps, bleachCenterX, bleachCenterY, bleachPsfVariance, bleachFactor_K);
    // wait
    double postbleachDelay = 0.1;
    solver.step(diffusionRate, postbleachDelay);
    while (solver.currentTime() < 5) {
        double samplePsfVariance = psfVar;
        images.add(solver.sampleImage(numX, numY, origin, extent, diffusionRate, totalSampleTime, numSampleSteps, psfVar, detectorGainAndQuantumYeild, bConvolve, bNoise));
        times.add(solver.currentTime());
    // solver.step(diffusionRate, 1-totalSampleTime);
    }
    double[] timeArray = new double[times.size()];
    for (int i = 0; i < timeArray.length; i++) {
        timeArray[i] = times.get(i);
    }
    UShortImage[] imageArray = images.toArray(new UShortImage[images.size()]);
    return new ImageTimeSeries<UShortImage>(UShortImage.class, imageArray, timeArray, 1);
}
Also used : ArrayList(java.util.ArrayList) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) BrownianDynamics2DSolver(org.vcell.vmicro.op.BrownianDynamics2DSolver) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 74 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage 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 75 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage 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)

Aggregations

UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)98 ROI (cbit.vcell.VirtualMicroscopy.ROI)26 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)20 Point (java.awt.Point)16 File (java.io.File)14 Extent (org.vcell.util.Extent)13 ImageTimeSeries (org.vcell.vmicro.workflow.data.ImageTimeSeries)12 Origin (org.vcell.util.Origin)10 ImageException (cbit.image.ImageException)9 Element (org.jdom.Element)9 DataBufferByte (java.awt.image.DataBufferByte)8 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)7 ArrayList (java.util.ArrayList)7 ISize (org.vcell.util.ISize)7 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)6 ClientTaskStatusSupport (org.vcell.util.ClientTaskStatusSupport)6 UserCancelException (org.vcell.util.UserCancelException)6 ProfileDataElement (org.vcell.optimization.ProfileDataElement)5 ImportRawTimeSeriesFromVFrapOp (org.vcell.vmicro.op.ImportRawTimeSeriesFromVFrapOp)5 OptContext (org.vcell.vmicro.workflow.data.OptContext)5