Search in sources :

Example 1 with NormalizedSampleFunction

use of org.vcell.vmicro.workflow.data.NormalizedSampleFunction in project vcell by virtualcell.

the class FitBleachSpot method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    // get inputs
    NormalizedSampleFunction bleach_roi = context.getData(bleachROI);
    FloatImage normImage = (FloatImage) context.getData(normalizedImages).getAllImages()[0];
    // do operation
    FitBleachSpotOp fitBleachSpotOp = new FitBleachSpotOp();
    FitBleachSpotOpResults opResults = fitBleachSpotOp.fit(bleach_roi, normImage);
    // set outputs
    context.setData(bleachRadius_ROI, opResults.bleachRadius_ROI);
    context.setData(centerX_ROI, opResults.centerX_ROI);
    context.setData(centerY_ROI, opResults.centerY_ROI);
    context.setData(bleachFactorK_GaussianFit, opResults.bleachFactorK_GaussianFit);
    context.setData(bleachRadius_GaussianFit, opResults.bleachRadius_ROI);
    context.setData(centerX_GaussianFit, opResults.centerX_GaussianFit);
    context.setData(centerY_GaussianFit, opResults.centerY_GaussianFit);
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) FitBleachSpotOpResults(org.vcell.vmicro.op.FitBleachSpotOp.FitBleachSpotOpResults) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) FitBleachSpotOp(org.vcell.vmicro.op.FitBleachSpotOp)

Example 2 with NormalizedSampleFunction

use of org.vcell.vmicro.workflow.data.NormalizedSampleFunction in project vcell by virtualcell.

the class ComputeMeasurementErrorOp method refreshNormalizedMeasurementError.

/*
	 * Calculate Measurement error for data that is normalized 
	 * and averaged at each ROI ring.
	 * The first dimension is ROI rings(according to the Enum in FRAPData)
	 * The second dimension is time points (from starting index to the end) 
	 */
double[][] refreshNormalizedMeasurementError(UShortImage[] rawImages, double[] timeStamps, FloatImage prebleachAverage, NormalizedSampleFunction[] rois, int indexFirstPostbleach) throws ImageException {
    int startIndexRecovery = indexFirstPostbleach;
    int roiLen = rois.length;
    double[][] sigma = new double[roiLen][timeStamps.length - startIndexRecovery];
    double[] prebleachAvg = prebleachAverage.getDoublePixels();
    for (int roiIdx = 0; roiIdx < roiLen; roiIdx++) {
        NormalizedSampleFunction roi = rois[roiIdx];
        short[] roiData = roi.toROI(1e-5).getPixelsXYZ();
        for (int timeIdx = startIndexRecovery; timeIdx < timeStamps.length; timeIdx++) {
            double[] rawTimeData = rawImages[timeIdx].getDoublePixels();
            if (roiData.length != rawTimeData.length || roiData.length != prebleachAvg.length || rawTimeData.length != prebleachAvg.length) {
                throw new RuntimeException("ROI data and image data are not in the same length.");
            } else {
                // loop through ROI
                int roiPixelCounter = 0;
                double sigmaVal = 0;
                for (int i = 0; i < roiData.length; i++) {
                    if (roiData[i] != 0) {
                        sigmaVal = sigmaVal + rawTimeData[i] / (prebleachAvg[i] * prebleachAvg[i]);
                        roiPixelCounter++;
                    }
                }
                if (roiPixelCounter == 0) {
                    sigmaVal = 0;
                } else {
                    sigmaVal = Math.sqrt(sigmaVal) / roiPixelCounter;
                }
                sigma[roiIdx][timeIdx - startIndexRecovery] = sigmaVal;
            }
        }
    }
    return sigma;
}
Also used : NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction)

Example 3 with NormalizedSampleFunction

use of org.vcell.vmicro.workflow.data.NormalizedSampleFunction in project vcell by virtualcell.

the class BrownianDynamicsTest method main.

public static void main(String[] args) {
    try {
        Options commandOptions = new Options();
        Option noiseOption = new Option(OPTION_NOISE, false, "sampled images use Poisson statistics for photons, default is to count particles");
        commandOptions.addOption(noiseOption);
        Option psfOption = new Option(OPTION_PSF, false, "sampled images are convolve with microscope psf, default is to bin");
        commandOptions.addOption(psfOption);
        Option imageFileOption = new Option(OPTION_IMAGEFILE, true, "file to store image time series");
        imageFileOption.setArgName("filename");
        imageFileOption.setValueSeparator('=');
        commandOptions.addOption(imageFileOption);
        Option plotFileOption = new Option(OPTION_PLOTFILE, true, "file to store CSV time series (reduced data for ROIs)");
        plotFileOption.setArgName("filename");
        plotFileOption.setValueSeparator('=');
        commandOptions.addOption(plotFileOption);
        Option displayImageOption = new Option(OPTION_DISPLAY_IMAGE, false, "display image time series");
        commandOptions.addOption(displayImageOption);
        Option displayPlotOption = new Option(OPTION_DISPLAY_PLOT, false, "display plot of bleach roi");
        commandOptions.addOption(displayPlotOption);
        Option extentOption = new Option(OPTION_EXTENT, true, "extent of entire domain (default " + DEFAULT_EXTENT_SCALE + ")");
        extentOption.setArgName("extent");
        extentOption.setValueSeparator('=');
        commandOptions.addOption(extentOption);
        Option imageSizeOption = new Option(OPTION_IMAGE_SIZE, true, "num pixels in x and y (default " + DEFAULT_IMAGE_SIZE + ")");
        imageSizeOption.setArgName("numPixels");
        imageSizeOption.setValueSeparator('=');
        commandOptions.addOption(imageSizeOption);
        Option numParticlesOption = new Option(OPTION_NUM_PARTICLES, true, "num particles (default " + DEFAULT_NUM_PARTICLES + ")");
        numParticlesOption.setArgName("num");
        numParticlesOption.setValueSeparator('=');
        commandOptions.addOption(numParticlesOption);
        Option diffusionOption = new Option(OPTION_DIFFUSION, true, "diffusion rate (default " + DEFAULT_DIFFUSION + ")");
        diffusionOption.setArgName("rate");
        diffusionOption.setValueSeparator('=');
        commandOptions.addOption(diffusionOption);
        Option bleachRadiusOption = new Option(OPTION_BLEACH_RADIUS, true, "bleach radius (default " + DEFAULT_BLEACH_RADIUS + ")");
        bleachRadiusOption.setArgName("radius");
        bleachRadiusOption.setValueSeparator('=');
        commandOptions.addOption(bleachRadiusOption);
        Option psfRadiusOption = new Option(OPTION_PSF_RADIUS, true, "psf radius (default " + DEFAULT_PSF_RADIUS + ")");
        psfRadiusOption.setArgName("radius");
        psfRadiusOption.setValueSeparator('=');
        commandOptions.addOption(psfRadiusOption);
        Option bleachDurationOption = new Option(OPTION_BLEACH_DURATION, true, "psf radius (default " + DEFAULT_BLEACH_DURATION + ")");
        bleachDurationOption.setArgName("duration");
        bleachDurationOption.setValueSeparator('=');
        commandOptions.addOption(bleachDurationOption);
        Option endTimeOption = new Option(OPTION_ENDTIME, true, "end time (default " + DEFAULT_ENDTIME + ")");
        endTimeOption.setArgName("time");
        endTimeOption.setValueSeparator('=');
        commandOptions.addOption(endTimeOption);
        CommandLine cmdLine = null;
        try {
            Parser parser = new BasicParser();
            cmdLine = parser.parse(commandOptions, args);
        } catch (ParseException e1) {
            e1.printStackTrace();
            HelpFormatter hf = new HelpFormatter();
            hf.printHelp("BrownianDynamicsTest", commandOptions);
            System.exit(2);
        }
        boolean bNoise = cmdLine.hasOption(OPTION_NOISE);
        boolean bConvolve = cmdLine.hasOption(OPTION_PSF);
        File imageFile = null;
        if (cmdLine.hasOption(OPTION_IMAGEFILE)) {
            imageFile = new File(cmdLine.getOptionValue(OPTION_IMAGEFILE));
        }
        File plotFile = null;
        if (cmdLine.hasOption(OPTION_PLOTFILE)) {
            plotFile = new File(cmdLine.getOptionValue(OPTION_PLOTFILE));
        }
        boolean bDisplayImage = cmdLine.hasOption(OPTION_DISPLAY_IMAGE);
        boolean bDisplayPlot = cmdLine.hasOption(OPTION_DISPLAY_PLOT);
        double extentScale = DEFAULT_EXTENT_SCALE;
        if (cmdLine.hasOption(OPTION_EXTENT)) {
            extentScale = Double.parseDouble(cmdLine.getOptionValue(OPTION_EXTENT));
        }
        int imageSize = DEFAULT_IMAGE_SIZE;
        if (cmdLine.hasOption(OPTION_IMAGE_SIZE)) {
            imageSize = Integer.parseInt(cmdLine.getOptionValue(OPTION_IMAGE_SIZE));
        }
        int numParticles = DEFAULT_NUM_PARTICLES;
        if (cmdLine.hasOption(OPTION_NUM_PARTICLES)) {
            numParticles = Integer.parseInt(cmdLine.getOptionValue(OPTION_NUM_PARTICLES));
        }
        double diffusionRate = DEFAULT_DIFFUSION;
        if (cmdLine.hasOption(OPTION_DIFFUSION)) {
            diffusionRate = Double.parseDouble(cmdLine.getOptionValue(OPTION_DIFFUSION));
        }
        double bleachRadius = DEFAULT_BLEACH_RADIUS;
        if (cmdLine.hasOption(OPTION_BLEACH_RADIUS)) {
            bleachRadius = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_RADIUS));
        }
        double psfRadius = DEFAULT_PSF_RADIUS;
        if (cmdLine.hasOption(OPTION_PSF_RADIUS)) {
            psfRadius = Double.parseDouble(cmdLine.getOptionValue(OPTION_PSF_RADIUS));
        }
        double bleachDuration = DEFAULT_BLEACH_DURATION;
        if (cmdLine.hasOption(OPTION_BLEACH_DURATION)) {
            bleachDuration = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_DURATION));
        }
        double endTime = DEFAULT_ENDTIME;
        if (cmdLine.hasOption(OPTION_ENDTIME)) {
            endTime = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_DURATION));
        }
        // 
        // hard coded parameters
        // 
        Origin origin = new Origin(0, 0, 0);
        Extent extent = new Extent(extentScale, extentScale, 1);
        int numX = imageSize;
        int numY = imageSize;
        double psfVar = psfRadius * psfRadius;
        BrownianDynamicsTest test = new BrownianDynamicsTest();
        ImageTimeSeries<UShortImage> rawTimeSeries = test.generateTestData(origin, extent, numX, numY, numParticles, diffusionRate, psfVar, bleachRadius * bleachRadius, bNoise, bConvolve, bleachDuration, endTime);
        // 
        if (imageFile != null) {
            new ExportRawTimeSeriesToVFrapOp().exportToVFRAP(imageFile, rawTimeSeries, null);
        }
        // 
        if (bDisplayImage) {
            new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeries, "time series", null);
        }
        // 
        // compute reduced data if needed for plotting or saving.
        // 
        RowColumnResultSet reducedData = null;
        if (bDisplayPlot || plotFile != null) {
            double muX = origin.getX() + 0.5 * extent.getX();
            double muY = origin.getY() + 0.5 * extent.getY();
            double sigma = Math.sqrt(psfVar);
            NormalizedSampleFunction gaussian = NormalizedSampleFunction.fromGaussian("psf", origin, extent, new ISize(numX, numY, 1), muX, muY, sigma);
            reducedData = new GenerateReducedDataOp().generateReducedData(rawTimeSeries, new NormalizedSampleFunction[] { gaussian });
        }
        // 
        if (plotFile != null) {
            FileOutputStream fos = new FileOutputStream(plotFile);
            new CSV().exportTo(fos, reducedData);
        }
        if (bDisplayPlot) {
            new DisplayPlotOp().displayPlot(reducedData, "bleached roi", null);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Origin(org.vcell.util.Origin) Options(org.apache.commons.cli.Options) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) HelpFormatter(org.apache.commons.cli.HelpFormatter) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) CSV(cbit.vcell.math.CSV) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ExportRawTimeSeriesToVFrapOp(org.vcell.vmicro.op.ExportRawTimeSeriesToVFrapOp) ImageException(cbit.image.ImageException) ParseException(org.apache.commons.cli.ParseException) Parser(org.apache.commons.cli.Parser) BasicParser(org.apache.commons.cli.BasicParser) BasicParser(org.apache.commons.cli.BasicParser) CommandLine(org.apache.commons.cli.CommandLine) FileOutputStream(java.io.FileOutputStream) Option(org.apache.commons.cli.Option) ParseException(org.apache.commons.cli.ParseException) File(java.io.File)

Example 4 with NormalizedSampleFunction

use of org.vcell.vmicro.workflow.data.NormalizedSampleFunction 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;
}
Also used : OptModelOneDiff(org.vcell.vmicro.workflow.data.OptModelOneDiff) GenerateCellROIsFromRawFrapTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp) GenerateDependentImageROIsOp(org.vcell.vmicro.op.GenerateDependentImageROIsOp) RunProfileLikelihoodGeneralOp(org.vcell.vmicro.op.RunProfileLikelihoodGeneralOp) ErrorFunctionNoiseWeightedL2(org.vcell.vmicro.workflow.data.ErrorFunctionNoiseWeightedL2) OptContext(org.vcell.vmicro.workflow.data.OptContext) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) OptModelTwoDiffWithPenalty(org.vcell.vmicro.workflow.data.OptModelTwoDiffWithPenalty) GenerateTrivial2DPsfOp(org.vcell.vmicro.op.GenerateTrivial2DPsfOp) 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) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ProfileData(org.vcell.optimization.ProfileData) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) RunRefSimulationFastOp(org.vcell.vmicro.op.RunRefSimulationFastOp) GenerateNormalizedFrapDataOp(org.vcell.vmicro.op.GenerateNormalizedFrapDataOp)

Example 5 with NormalizedSampleFunction

use of org.vcell.vmicro.workflow.data.NormalizedSampleFunction 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)

Aggregations

NormalizedSampleFunction (org.vcell.vmicro.workflow.data.NormalizedSampleFunction)9 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)5 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)4 OptContext (org.vcell.vmicro.workflow.data.OptContext)4 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)3 ROI (cbit.vcell.VirtualMicroscopy.ROI)3 ISize (org.vcell.util.ISize)3 ComputeMeasurementErrorOp (org.vcell.vmicro.op.ComputeMeasurementErrorOp)3 Generate2DOptContextOp (org.vcell.vmicro.op.Generate2DOptContextOp)3 GenerateReducedDataOp (org.vcell.vmicro.op.GenerateReducedDataOp)3 DisplayInteractiveModelOp (org.vcell.vmicro.op.display.DisplayInteractiveModelOp)3 DisplayTimeSeriesOp (org.vcell.vmicro.op.display.DisplayTimeSeriesOp)3 ErrorFunction (org.vcell.vmicro.workflow.data.ErrorFunction)3 ProfileData (org.vcell.optimization.ProfileData)2 Extent (org.vcell.util.Extent)2 Origin (org.vcell.util.Origin)2 FitBleachSpotOp (org.vcell.vmicro.op.FitBleachSpotOp)2 FitBleachSpotOpResults (org.vcell.vmicro.op.FitBleachSpotOp.FitBleachSpotOpResults)2 GenerateBleachRoiOp (org.vcell.vmicro.op.GenerateBleachRoiOp)2 GenerateCellROIsFromRawFrapTimeSeriesOp (org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp)2