use of org.vcell.vmicro.op.GenerateNormalizedFrapDataOp.NormalizedFrapDataResults in project vcell by virtualcell.
the class VFrapProcess method compute.
public static VFrapProcessResults compute(ImageTimeSeries rawTimeSeriesImages, double bleachThreshold, double cellThreshold, LocalWorkspace localWorkspace, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
GenerateCellROIsFromRawFrapTimeSeriesOp generateCellROIs = new GenerateCellROIsFromRawFrapTimeSeriesOp();
GeometryRoisAndBleachTiming geometryAndTiming = generateCellROIs.generate(rawTimeSeriesImages, cellThreshold);
GenerateNormalizedFrapDataOp generateNormalizedFrapData = new GenerateNormalizedFrapDataOp();
NormalizedFrapDataResults normalizedFrapResults = generateNormalizedFrapData.generate(rawTimeSeriesImages, geometryAndTiming.backgroundROI_2D, geometryAndTiming.indexOfFirstPostbleach);
GenerateBleachRoiOp generateROIs = new GenerateBleachRoiOp();
ROI bleachROI = generateROIs.generateBleachRoi(normalizedFrapResults.normalizedFrapData.getAllImages()[0], geometryAndTiming.cellROI_2D, bleachThreshold);
GenerateDependentImageROIsOp generateDependentROIs = new GenerateDependentImageROIsOp();
ROI[] dataROIs = generateDependentROIs.generate(geometryAndTiming.cellROI_2D, bleachROI);
NormalizedSampleFunction[] roiSampleFunctions = new NormalizedSampleFunction[dataROIs.length];
for (int i = 0; i < dataROIs.length; i++) {
roiSampleFunctions[i] = NormalizedSampleFunction.fromROI(dataROIs[i]);
}
GenerateReducedDataOp generateReducedNormalizedData = new GenerateReducedDataOp();
RowColumnResultSet reducedData = generateReducedNormalizedData.generateReducedData(normalizedFrapResults.normalizedFrapData, roiSampleFunctions);
ComputeMeasurementErrorOp computeMeasurementError = new ComputeMeasurementErrorOp();
RowColumnResultSet measurementError = computeMeasurementError.computeNormalizedMeasurementError(roiSampleFunctions, geometryAndTiming.indexOfFirstPostbleach, rawTimeSeriesImages, normalizedFrapResults.prebleachAverage, clientTaskStatusSupport);
GenerateTrivial2DPsfOp psf_2D = new GenerateTrivial2DPsfOp();
UShortImage psf = psf_2D.generateTrivial2D_Psf();
// RunRefSimulationOp runRefSimulationFull = new RunRefSimulationOp();
// GenerateReducedROIDataOp generateReducedRefSimData = new GenerateReducedROIDataOp();
RunRefSimulationFastOp runRefSimulationFast = new RunRefSimulationFastOp();
RowColumnResultSet refData = runRefSimulationFast.runRefSimFast(geometryAndTiming.cellROI_2D, normalizedFrapResults.normalizedFrapData, dataROIs, psf, localWorkspace, clientTaskStatusSupport);
final double refDiffusionRate = 1.0;
double[] refSimTimePoints = refData.extractColumn(0);
int numRois = refData.getDataColumnCount() - 1;
int numRefSimTimes = refData.getRowCount();
double[][] refSimData = new double[numRois][numRefSimTimes];
for (int roi = 0; roi < numRois; roi++) {
double[] roiData = refData.extractColumn(roi + 1);
for (int t = 0; t < numRefSimTimes; t++) {
refSimData[roi][t] = roiData[t];
}
}
ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
OptModelOneDiff optModelOneDiff = new OptModelOneDiff(refSimData, refSimTimePoints, refDiffusionRate);
Generate2DOptContextOp generate2DOptContextOne = new Generate2DOptContextOp();
OptContext optContextOneDiff = generate2DOptContextOne.generate2DOptContext(optModelOneDiff, reducedData, measurementError, errorFunction);
RunProfileLikelihoodGeneralOp runProfileLikelihoodOne = new RunProfileLikelihoodGeneralOp();
ProfileData[] profileDataOne = runProfileLikelihoodOne.runProfileLikihood(optContextOneDiff, clientTaskStatusSupport);
// OptModelTwoDiffWithoutPenalty optModelTwoDiffWithoutPenalty = new OptModelTwoDiffWithoutPenalty(refSimData, refSimTimePoints, refDiffusionRate);
// Generate2DOptContextOp generate2DOptContextTwoWithoutPenalty = new Generate2DOptContextOp();
// OptContext optContextTwoDiffWithoutPenalty = generate2DOptContextTwoWithoutPenalty.generate2DOptContext(optModelTwoDiffWithoutPenalty, reducedData, measurementError);
// RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithoutPenalty = new RunProfileLikelihoodGeneralOp();
// ProfileData[] profileDataTwoWithoutPenalty = runProfileLikelihoodTwoWithoutPenalty.runProfileLikihood(optContextTwoDiffWithoutPenalty, clientTaskStatusSupport);
OptModelTwoDiffWithPenalty optModelTwoDiffWithPenalty = new OptModelTwoDiffWithPenalty(refSimData, refSimTimePoints, refDiffusionRate);
Generate2DOptContextOp generate2DOptContextTwoWithPenalty = new Generate2DOptContextOp();
OptContext optContextTwoDiffWithPenalty = generate2DOptContextTwoWithPenalty.generate2DOptContext(optModelTwoDiffWithPenalty, reducedData, measurementError, errorFunction);
RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithPenalty = new RunProfileLikelihoodGeneralOp();
ProfileData[] profileDataTwoWithPenalty = runProfileLikelihoodTwoWithPenalty.runProfileLikihood(optContextTwoDiffWithPenalty, clientTaskStatusSupport);
//
// SLOW WAY
//
// runRefSimulationFull.cellROI_2D,generateCellROIs.cellROI_2D);
// runRefSimulationFull.normalizedTimeSeries,generateNormalizedFrapData.normalizedFrapData);
// workflow.addTask(runRefSimulationFull);
// generateReducedRefSimData.imageTimeSeries,runRefSimulationFull.refSimTimeSeries);
// generateReducedRefSimData.imageDataROIs,generateDependentROIs.imageDataROIs);
// workflow.addTask(generateReducedRefSimData);
// DataHolder<RowColumnResultSet> reducedROIData = generateReducedRefSimData.reducedROIData;
// DataHolder<Double> refSimDiffusionRate = runRefSimulationFull.refSimDiffusionRate;
VFrapProcessResults results = new VFrapProcessResults(dataROIs, geometryAndTiming.cellROI_2D, bleachROI, normalizedFrapResults.normalizedFrapData, reducedData, profileDataOne, profileDataTwoWithPenalty);
return results;
}
use of org.vcell.vmicro.op.GenerateNormalizedFrapDataOp.NormalizedFrapDataResults in project vcell by virtualcell.
the class GenerateNormalizedFrapData method compute0.
@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
// get input
ImageTimeSeries<UShortImage> rawTimeSeries = context.getData(rawImageTimeSeries);
ROI backgroundROI = context.getData(backgroundROI_2D);
Integer indexPostbleach = context.getData(indexOfFirstPostbleach);
// do op
GenerateNormalizedFrapDataOp op = new GenerateNormalizedFrapDataOp();
NormalizedFrapDataResults results = op.generate(rawTimeSeries, backgroundROI, indexPostbleach);
// set output
context.setData(normalizedFrapData, results.normalizedFrapData);
context.setData(this.prebleachAverage, results.prebleachAverage);
}
use of org.vcell.vmicro.op.GenerateNormalizedFrapDataOp.NormalizedFrapDataResults 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);
}
Aggregations