Search in sources :

Example 86 with UShortImage

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

the class ImportRawTimeSeriesFromVFrap method compute0.

@Override
protected void compute0(TaskContext context, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    // get input
    File vfrap_file = context.getData(vfrapFile);
    // do op
    ImportRawTimeSeriesFromVFrapOp op = new ImportRawTimeSeriesFromVFrapOp();
    ImageTimeSeries<UShortImage> imageTimeSeries = op.importRawTimeSeriesFromVFrap(vfrap_file);
    // set output
    context.setData(rawTimeSeriesImages, imageTimeSeries);
}
Also used : ImportRawTimeSeriesFromVFrapOp(org.vcell.vmicro.op.ImportRawTimeSeriesFromVFrapOp) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) File(java.io.File)

Example 87 with UShortImage

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

the class RunRefSimulationFast method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    ImageTimeSeries<FloatImage> normTimeSeries = context.getData(normalizedTimeSeries);
    ROI cellROI = context.getData(cellROI_2D);
    ROI[] imageDataRois = context.getData(imageDataROIs);
    UShortImage psf = context.getData(this.psf);
    // do op
    RunRefSimulationFastOp op = new RunRefSimulationFastOp();
    RowColumnResultSet reducedData = op.runRefSimFast(cellROI, normTimeSeries, imageDataRois, psf, context.getLocalWorkspace(), clientTaskStatusSupport);
    // set output
    context.setData(reducedROIData, reducedData);
    // always D = 1,
    context.setData(refSimDiffusionRate, op.getReferenceDiffusionCoef());
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) RunRefSimulationFastOp(org.vcell.vmicro.op.RunRefSimulationFastOp) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 88 with UShortImage

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

the class BrownianDynamics2DSolver method sampleImage.

public UShortImage sampleImage(int numX, int numY, Origin origin, Extent extent, double diffusion, double integrationTime, int numSteps, double psfVar, double detectorGainAndQuantumYeild, boolean bConvolve, boolean bNoise) throws ImageException {
    double deltaT = integrationTime / (numSteps);
    // 
    // sample the x and y coordinates for the structured grid (pixel coordinates). .. coordinates will be used lots of times (let's precompute).
    // 
    double[] imageX = new double[numX];
    double[] imageY = new double[numY];
    for (int i = 0; i < numX; i++) {
        imageX[i] = origin.getX() + (0.5 + i) * extent.getX() / numX;
    }
    for (int j = 0; j < numY; j++) {
        imageY[j] = origin.getY() + (0.5 + j) * extent.getY() / numY;
    }
    // apply point spread function to gather poisson rates from all particles to all pixels.
    // then we roll the dice to sample from poission later.
    double[] particleImage = new double[numX * numY];
    Arrays.fill(particleImage, 0);
    for (int step = 0; step < numSteps; step++) {
        if (bConvolve) {
            // 
            // convolve all particles with normalized psf (each particle integrates to one over neighboring pixels) for each pixel and accumulate in lambda array
            // (lambda is not reset so we can repeat and integrate over time)
            // 
            System.out.println("convolving particles, step=" + step + ", time=" + currTime);
            addConvolved(numX, numY, psfVar, imageX, imageY, particleImage);
        } else {
            // 
            // count particles in each pixel
            // 
            System.out.println("binning particles, step=" + step + ", time=" + currTime);
            addBinned(numX, numY, origin.getX(), origin.getY(), extent.getX(), extent.getY(), particleImage);
        }
        // 
        // let diffusion happen during sampling
        // 
        System.out.println("simulating particles, step=" + step + ", time=" + currTime);
        step(diffusion, deltaT);
    }
    // 
    // generate sample image by generating fluorescence intensity
    // need to rescale to consider detector gain and expected number of photons from each particle. (ignore detector noise)
    // 
    float[] pixels = new float[particleImage.length];
    double totalGain = detectorGainAndQuantumYeild * integrationTime / numSteps;
    for (int i = 0; i < pixels.length; i++) {
        float rate = (float) (particleImage[i] * totalGain);
        if (rate > 1e-5) {
            if (bNoise) {
                pixels[i] = new PoissonDistribution(imagingRng, rate, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS).sample();
            } else {
                pixels[i] = rate;
            }
        }
    }
    // 
    // create unsigned short sample image
    // 
    short[] ushortPixels = new short[pixels.length];
    for (int i = 0; i < ushortPixels.length; i++) {
        if (pixels[i] > 32767) {
            throw new RuntimeException("pixel overflow of signed short, value = " + pixels[i]);
        }
        if (pixels[i] < 0) {
            throw new RuntimeException("unexpected negative pixel, value = " + pixels[i]);
        }
        ushortPixels[i] = (short) (0xffff & (int) pixels[i]);
    }
    UShortImage sampledImage = new UShortImage(ushortPixels, origin, extent, numX, numY, 1);
    return sampledImage;
}
Also used : PoissonDistribution(org.apache.commons.math3.distribution.PoissonDistribution) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 89 with UShortImage

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

Example 90 with UShortImage

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

the class GenerateTrivial2DPsfOp method generateTrivial2D_Psf.

public UShortImage generateTrivial2D_Psf() {
    // psf image is now expecting a 3x3 image that are all zeros with a 1 in the middle (Kronecker delta)
    short[] pixels = new short[] { 0, 0, 0, 0, 1, 0, 0, 0, 0 };
    Origin origin = new Origin(0, 0, 0);
    Extent extent = new Extent(1, 1, 1);
    ISize isize = new ISize(3, 3, 1);
    UShortImage psfImage;
    try {
        psfImage = new UShortImage(pixels, origin, extent, isize.getX(), isize.getY(), isize.getZ());
    } catch (ImageException e) {
        e.printStackTrace();
        throw new RuntimeException("unexpected image exception: " + e.getMessage(), e);
    }
    return psfImage;
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

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