Search in sources :

Example 11 with FloatImage

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

the class KenworthyWorkflowTest method analyzeKeyworthy.

/**
 * Fits raw image time series data to uniform disk models (with Guassian or Uniform fluorescence).
 *
 * @param rawTimeSeriesImages
 * @param localWorkspace
 * @throws Exception
 */
private static void analyzeKeyworthy(ImageTimeSeries<UShortImage> rawTimeSeriesImages, LocalWorkspace localWorkspace) throws Exception {
    new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeriesImages, "raw images", (WindowListener) null);
    double cellThreshold = 0.5;
    GeometryRoisAndBleachTiming cellROIresults = new GenerateCellROIsFromRawFrapTimeSeriesOp().generate(rawTimeSeriesImages, cellThreshold);
    ROI backgroundROI = cellROIresults.backgroundROI_2D;
    ROI cellROI = cellROIresults.cellROI_2D;
    int indexOfFirstPostbleach = cellROIresults.indexOfFirstPostbleach;
    new DisplayImageOp().displayImage(backgroundROI.getRoiImages()[0], "background ROI", null);
    new DisplayImageOp().displayImage(cellROI.getRoiImages()[0], "cell ROI", null);
    NormalizedFrapDataResults normResults = new GenerateNormalizedFrapDataOp().generate(rawTimeSeriesImages, backgroundROI, indexOfFirstPostbleach);
    ImageTimeSeries<FloatImage> normalizedTimeSeries = normResults.normalizedFrapData;
    FloatImage prebleachAvg = normResults.prebleachAverage;
    FloatImage normalizedPostbleach = normalizedTimeSeries.getAllImages()[0];
    new DisplayTimeSeriesOp().displayImageTimeSeries(normalizedTimeSeries, "normalized images", (WindowListener) null);
    // 
    // create a single bleach ROI by thresholding
    // 
    double bleachThreshold = 0.80;
    ROI bleachROI = new GenerateBleachRoiOp().generateBleachRoi(normalizedPostbleach, cellROI, bleachThreshold);
    // 
    // only use bleach ROI for fitting etc.
    // 
    // ROI[] dataROIs = new ROI[] { bleachROI };
    // 
    // fit 2D Gaussian to normalized data to determine center, radius and K factor of bleach (assuming exp(-exp
    // 
    FitBleachSpotOpResults fitSpotResults = new FitBleachSpotOp().fit(NormalizedSampleFunction.fromROI(bleachROI), normalizedTimeSeries.getAllImages()[0]);
    double bleachFactorK_GaussianFit = fitSpotResults.bleachFactorK_GaussianFit;
    double bleachRadius_GaussianFit = fitSpotResults.bleachRadius_GaussianFit;
    double bleachRadius_ROI = fitSpotResults.bleachRadius_ROI;
    double centerX_GaussianFit = fitSpotResults.centerX_GaussianFit;
    double centerX_ROI = fitSpotResults.centerX_ROI;
    double centerY_GaussianFit = fitSpotResults.centerY_GaussianFit;
    double centerY_ROI = fitSpotResults.centerY_ROI;
    NormalizedSampleFunction[] sampleFunctions = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(bleachROI) };
    // 
    // get reduced data and errors for each ROI
    // 
    RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, sampleFunctions);
    RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(sampleFunctions, indexOfFirstPostbleach, rawTimeSeriesImages, prebleachAvg, null);
    ErrorFunction errorFunction = new ErrorFunctionKenworthy(reducedData);
    // 
    // 2 parameter uniform disk model
    // 
    OptModel uniformDisk2OptModel = new OptModelKenworthyUniformDisk2P(bleachRadius_ROI);
    String title_u2 = "Uniform Disk Model - 2 parameters, (Rn=" + bleachRadius_ROI + ")";
    OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(uniformDisk2OptModel, reducedData, measurementErrors, errorFunction);
    new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, sampleFunctions, localWorkspace, title_u2, null);
    // 
    // 3 parameter uniform disk model
    // 
    OptModel uniformDisk3OptModel = new OptModelKenworthyUniformDisk3P(bleachRadius_ROI);
    OptContext uniformDisk3Context = new Generate2DOptContextOp().generate2DOptContext(uniformDisk3OptModel, reducedData, measurementErrors, errorFunction);
    String title_u3 = "Uniform Disk Model - 3 parameters, (Rn=" + bleachRadius_ROI + ")";
    new DisplayInteractiveModelOp().displayOptModel(uniformDisk3Context, sampleFunctions, localWorkspace, title_u3, null);
    // 
    // GaussianFit parameter uniform disk model
    // 
    FloatImage prebleachBleachAreaImage = new FloatImage(prebleachAvg);
    // mask-out all but the bleach area
    prebleachBleachAreaImage.and(bleachROI.getRoiImages()[0]);
    double prebleachAvgInROI = prebleachBleachAreaImage.getImageStatistics().meanValue;
    OptModel gaussian2OptModel = new OptModelKenworthyGaussian(prebleachAvgInROI, bleachFactorK_GaussianFit, bleachRadius_GaussianFit, bleachRadius_ROI);
    OptContext gaussianDisk2Context = new Generate2DOptContextOp().generate2DOptContext(gaussian2OptModel, reducedData, measurementErrors, errorFunction);
    String title_g2 = "Gaussian Disk Model - 2 parameters (prebleach=" + prebleachAvgInROI + ",K=" + bleachFactorK_GaussianFit + ",Re=" + bleachRadius_GaussianFit + ",Rnom=" + bleachRadius_ROI + ")";
    new DisplayInteractiveModelOp().displayOptModel(gaussianDisk2Context, sampleFunctions, localWorkspace, title_g2, null);
}
Also used : OptModelKenworthyGaussian(org.vcell.vmicro.workflow.data.OptModelKenworthyGaussian) GenerateCellROIsFromRawFrapTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp) FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) OptContext(org.vcell.vmicro.workflow.data.OptContext) OptModel(org.vcell.vmicro.workflow.data.OptModel) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) DisplayInteractiveModelOp(org.vcell.vmicro.op.display.DisplayInteractiveModelOp) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) OptModelKenworthyUniformDisk2P(org.vcell.vmicro.workflow.data.OptModelKenworthyUniformDisk2P) FitBleachSpotOp(org.vcell.vmicro.op.FitBleachSpotOp) ErrorFunctionKenworthy(org.vcell.vmicro.workflow.data.ErrorFunctionKenworthy) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ErrorFunction(org.vcell.vmicro.workflow.data.ErrorFunction) GeometryRoisAndBleachTiming(org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp.GeometryRoisAndBleachTiming) NormalizedFrapDataResults(org.vcell.vmicro.op.GenerateNormalizedFrapDataOp.NormalizedFrapDataResults) GenerateBleachRoiOp(org.vcell.vmicro.op.GenerateBleachRoiOp) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) FitBleachSpotOpResults(org.vcell.vmicro.op.FitBleachSpotOp.FitBleachSpotOpResults) GenerateNormalizedFrapDataOp(org.vcell.vmicro.op.GenerateNormalizedFrapDataOp) OptModelKenworthyUniformDisk3P(org.vcell.vmicro.workflow.data.OptModelKenworthyUniformDisk3P)

Example 12 with FloatImage

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

the class ComputeMeasurementError method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    ROI[] rois = context.getData(imageDataROIs);
    int indexPostbleach = context.getData(indexFirstPostbleach);
    ImageTimeSeries<UShortImage> rawImageDataset = context.getData(rawImageTimeSeries);
    FloatImage prebleachAvgImage = context.getData(prebleachAverage);
    ArrayList<NormalizedSampleFunction> roiSampleFunctions = new ArrayList<NormalizedSampleFunction>();
    for (int i = 0; i < rois.length; i++) {
        roiSampleFunctions.add(NormalizedSampleFunction.fromROI(rois[i]));
    }
    // do op
    ComputeMeasurementErrorOp op = new ComputeMeasurementErrorOp();
    NormalizedSampleFunction[] roiSampleFunctionArray = roiSampleFunctions.toArray(new NormalizedSampleFunction[0]);
    RowColumnResultSet rowColumnResultSet = op.computeNormalizedMeasurementError(roiSampleFunctionArray, indexPostbleach, rawImageDataset, prebleachAvgImage, clientTaskStatusSupport);
    // set output
    context.setData(normalizedMeasurementError, rowColumnResultSet);
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) ArrayList(java.util.ArrayList) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

Example 13 with FloatImage

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

the class RunSimulation2D method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    // get input
    LocalWorkspace localWorkspace = context.getLocalWorkspace();
    Simulation sim = context.getData(simulation_2D);
    String dataVar = context.getData(dataVarName);
    // do op
    RunSimulation2DOp op = new RunSimulation2DOp();
    ImageTimeSeries<FloatImage> solution = op.runRefSimulation(localWorkspace, sim, dataVar, clientTaskStatusSupport);
    // set output
    context.setData(simTimeSeries, solution);
}
Also used : LocalWorkspace(org.vcell.vmicro.workflow.data.LocalWorkspace) FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) Simulation(cbit.vcell.solver.Simulation) RunSimulation2DOp(org.vcell.vmicro.op.RunSimulation2DOp)

Example 14 with FloatImage

use of cbit.vcell.VirtualMicroscopy.FloatImage 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 15 with FloatImage

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

the class FitTimeSeries method main.

public static void main(String[] args) {
    try {
        int numX = 100;
        int numY = 100;
        double center_i = 52.44;
        double center_j = 51.39;
        double K = 30;
        double high = 0.9;
        double sigma2 = 4;
        float[] pixels = new float[numX * numY];
        Origin origin = new Origin(0, 0, 0);
        Extent extent = new Extent(1, 1, 1);
        FloatImage image = new FloatImage(pixels, origin, extent, numX, numY, 1);
        int index = 0;
        for (int j = 0; j < numY; j++) {
            for (int i = 0; i < numX; i++) {
                double radius = ((i - center_i) * (i - center_i) + (j - center_j) * (j - center_j));
                pixels[index++] = (float) (high - FastMath.exp(-K * FastMath.exp(-radius / sigma2)));
            }
        }
        double init_center_i = 50;
        double init_center_j = 50;
        double init_sigma2 = 2;
        GaussianFitResults fitResults = fitToGaussian(init_center_i, init_center_j, init_sigma2, image);
        System.out.println(fitResults);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Origin(org.vcell.util.Origin) FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) Extent(org.vcell.util.Extent)

Aggregations

FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)18 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)6 Extent (org.vcell.util.Extent)6 ROI (cbit.vcell.VirtualMicroscopy.ROI)5 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)5 ISize (org.vcell.util.ISize)4 Origin (org.vcell.util.Origin)4 ImageTimeSeries (org.vcell.vmicro.workflow.data.ImageTimeSeries)4 ComputeMeasurementErrorOp (org.vcell.vmicro.op.ComputeMeasurementErrorOp)3 NormalizedSampleFunction (org.vcell.vmicro.workflow.data.NormalizedSampleFunction)3 SimDataBlock (cbit.vcell.simdata.SimDataBlock)2 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)2 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)2 File (java.io.File)2 KeyValue (org.vcell.util.document.KeyValue)2 User (org.vcell.util.document.User)2 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)2 FitBleachSpotOp (org.vcell.vmicro.op.FitBleachSpotOp)2 FitBleachSpotOpResults (org.vcell.vmicro.op.FitBleachSpotOp.FitBleachSpotOpResults)2 Generate2DOptContextOp (org.vcell.vmicro.op.Generate2DOptContextOp)2