Search in sources :

Example 1 with DisplayImageOp

use of org.vcell.vmicro.op.display.DisplayImageOp in project vcell by virtualcell.

the class FluorescenceNoiseTest method testBrownianDynamics.

private void testBrownianDynamics() throws ImageException {
    Origin origin = new Origin(0, 0, 0);
    Extent extent = new Extent(10, 10, 1);
    double psfVar = 0.25 * 0.25;
    // typically 10000 or 100000;
    int numParticles = 10000;
    double diffusionRate = 1;
    double bleachRadius = 0.25;
    final double bleachAmplitude = 0.5;
    final double bleachRadius2 = bleachRadius * bleachRadius;
    double endTime = 10;
    int numTimes = 1000;
    final BrownianDynamics2DSolver solver = new BrownianDynamics2DSolver(origin, extent, numParticles);
    boolean initiallyFluorescent = true;
    solver.initializeUniform(initiallyFluorescent);
    double totalBleachTime = 0.00001;
    int numBleachSteps = 1;
    double bleachCenterX = origin.getX() + 0.5 * extent.getX();
    double bleachCenterY = origin.getY() + 0.5 * extent.getY();
    double bleachPsfVariance = psfVar;
    double bleachFactor_K = 1000000;
    solver.bleachGuassian(diffusionRate, totalBleachTime, numBleachSteps, bleachCenterX, bleachCenterY, bleachPsfVariance, bleachFactor_K);
    // ParticleVisitor bleachGaussian = new ParticleVisitor() {
    // UniformRealDistribution uniform = new UniformRealDistribution();
    // 
    // @Override
    // public void visit(double x, double y, boolean bFluorescent, int index) {
    // // TODO Auto-generated method stub
    // double radius2 = x*x + y*y;
    // double bleachProb = bleachAmplitude * FastMath.exp(-radius2/bleachRadius2);
    // if (uniform.sample() < bleachProb){
    // solver.setFluorescence(index,false);
    // }else{
    // solver.setFluorescence(index,true);
    // }
    // }
    // };
    // solver.visit(bleachGaussian);
    double totalSampleTime = 0.1;
    int numSampleSteps = 1;
    double samplePsfVariance = psfVar;
    double detectorGainAndQuantumYeild = 100;
    boolean bNoise = true;
    boolean bConvolve = true;
    UShortImage sampledImage = solver.sampleImage(100, 100, origin, extent, diffusionRate, totalSampleTime, numSampleSteps, samplePsfVariance, detectorGainAndQuantumYeild, bConvolve, bNoise);
    new DisplayImageOp().displayImage(sampledImage, "initialBleach", null);
}
Also used : Origin(org.vcell.util.Origin) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) Extent(org.vcell.util.Extent) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) BrownianDynamics2DSolver(org.vcell.vmicro.op.BrownianDynamics2DSolver)

Example 2 with DisplayImageOp

use of org.vcell.vmicro.op.display.DisplayImageOp in project vcell by virtualcell.

the class VFrapProcess method main.

public static void main(String[] args) {
    try {
        File baseDir = new File(".");
        // File baseDir = new File("/Users/schaff/Documents/workspace/VCell_5.4");
        // initialize computing environment
        // 
        File workingDirectory = new File(baseDir, "workingDir");
        LocalWorkspace localWorkspace = new LocalWorkspace(workingDirectory);
        // 
        // import raw image time series data from VFRAP file format (can have noise, background, etc ... can be actual microscopy data)
        // 
        ClientTaskStatusSupport progressListener = new ClientTaskStatusSupport() {

            String message = "";

            int progress = 0;

            @Override
            public void setProgress(int progress) {
                this.progress = progress;
            }

            @Override
            public void setMessage(String message) {
                this.message = message;
            }

            @Override
            public boolean isInterrupted() {
                return false;
            }

            @Override
            public int getProgress() {
                return progress;
            }

            @Override
            public void addProgressDialogListener(ProgressDialogListener progressDialogListener) {
            }
        };
        // 
        // generate fake data (and save?)
        // 
        // ImageTimeSeries<UShortImage> simulatedFluorescence = generateFakeData(localWorkspace, progressListener);
        // new ExportRawTimeSeriesToVFrapOp().exportToVFRAP(vfrapFile, simulatedFluorescence, null);
        // 
        // analyze raw data (from file?) using Keyworthy method.
        // 
        File vfrapFile = new File(baseDir, "vfrapPaper/rawData/sim3/workflow.txt.save");
        ImageTimeSeries<UShortImage> fluorTimeSeriesImages = new ImportRawTimeSeriesFromVFrapOp().importRawTimeSeriesFromVFrap(vfrapFile);
        VFrapProcessResults results = compute(fluorTimeSeriesImages, 0.85, 0.4, localWorkspace, progressListener);
        new DisplayTimeSeriesOp().displayImageTimeSeries(fluorTimeSeriesImages, "raw data", null);
        new DisplayImageOp().displayImage(results.cellROI_2D.getRoiImages()[0], "cell ROI", null);
        new DisplayImageOp().displayImage(results.bleachROI_2D.getRoiImages()[0], "bleach ROI", null);
        new DisplayDependentROIsOp().displayDependentROIs(results.imageDataROIs, results.cellROI_2D, "data rois", null);
        new DisplayTimeSeriesOp().displayImageTimeSeries(results.normalizedTimeSeries, "normalized data", null);
        new DisplayProfileLikelihoodPlotsOp().displayProfileLikelihoodPlots(results.profileDataOne, "one fluorescent pool", null);
        new DisplayProfileLikelihoodPlotsOp().displayProfileLikelihoodPlots(results.profileDataTwoWithPenalty, "too pools", null);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : DisplayProfileLikelihoodPlotsOp(org.vcell.vmicro.op.display.DisplayProfileLikelihoodPlotsOp) LocalWorkspace(org.vcell.vmicro.workflow.data.LocalWorkspace) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) ProgressDialogListener(org.vcell.util.ProgressDialogListener) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) ClientTaskStatusSupport(org.vcell.util.ClientTaskStatusSupport) ImportRawTimeSeriesFromVFrapOp(org.vcell.vmicro.op.ImportRawTimeSeriesFromVFrapOp) DisplayDependentROIsOp(org.vcell.vmicro.op.display.DisplayDependentROIsOp) File(java.io.File)

Example 3 with DisplayImageOp

use of org.vcell.vmicro.op.display.DisplayImageOp in project vcell by virtualcell.

the class PhotoactivationExperimentTest method analyzePhotoactivation.

/**
 * Fits raw image time series data to uniform disk models (with Guassian or Uniform fluorescence).
 *
 * @param rawTimeSeriesImages
 * @param localWorkspace
 * @throws Exception
 */
private static void analyzePhotoactivation(ImageTimeSeries<UShortImage> rawTimeSeriesImages, LocalWorkspace localWorkspace) throws Exception {
    // 
    // correct the timestamps (1 per second).
    // 
    double[] timeStamps = rawTimeSeriesImages.getImageTimeStamps();
    for (int i = 0; i < timeStamps.length; i++) {
        timeStamps[i] = i;
    }
    new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeriesImages, "raw images", (WindowListener) null);
    ImageTimeSeries<UShortImage> blurredRaw = blurTimeSeries(rawTimeSeriesImages);
    new DisplayTimeSeriesOp().displayImageTimeSeries(blurredRaw, "blurred raw images", (WindowListener) null);
    double cellThreshold = 0.4;
    GeometryRoisAndActivationTiming cellROIresults = new GenerateCellROIsFromRawPhotoactivationTimeSeriesOp().generate(blurredRaw, cellThreshold);
    ROI backgroundROI = cellROIresults.backgroundROI_2D;
    ROI cellROI = cellROIresults.cellROI_2D;
    int indexOfFirstPostactivation = cellROIresults.indexOfFirstPostactivation;
    boolean backgroundSubtract = false;
    boolean normalizeByPreActivation = false;
    NormalizedPhotoactivationDataResults normResults = new GenerateNormalizedPhotoactivationDataOp().generate(rawTimeSeriesImages, backgroundROI, indexOfFirstPostactivation, backgroundSubtract, normalizeByPreActivation);
    ImageTimeSeries<FloatImage> normalizedTimeSeries = normResults.normalizedPhotoactivationData;
    FloatImage preactivationAvg = normResults.preactivationAverageImage;
    FloatImage normalizedPostactivation = normalizedTimeSeries.getAllImages()[0];
    new DisplayTimeSeriesOp().displayImageTimeSeries(normalizedTimeSeries, "normalized images", (WindowListener) null);
    // 
    // create a single bleach ROI by thresholding
    // 
    double activatedThreshold = 1000;
    ROI activatedROI = new GenerateActivationRoiOp().generateActivatedRoi(blurredRaw.getAllImages()[indexOfFirstPostactivation], cellROI, activatedThreshold);
    new DisplayImageOp().displayImage(activatedROI.getRoiImages()[0], "activated roi", null);
    new DisplayImageOp().displayImage(cellROI.getRoiImages()[0], "cell roi", null);
    new DisplayImageOp().displayImage(backgroundROI.getRoiImages()[0], "background roi", null);
    {
        // 
        // only use bleach ROI for fitting etc.
        // 
        NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI) };
        // 
        // get reduced data and errors for each ROI
        // 
        RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
        RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
        DisplayPlotOp displayReducedData = new DisplayPlotOp();
        displayReducedData.displayPlot(reducedData, "reduced data", null);
        DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
        displayMeasurementError.displayPlot(measurementErrors, "measurement error", null);
        // 
        // 2 parameter uniform disk model
        // 
        Parameter tau = new Parameter("tau", 0.001, 200.0, 1.0, 0.1);
        Parameter f_init = new Parameter("f_init", 0.5, 4000, 1.0, 1.0);
        Parameter f_final = new Parameter("f_final", 0.01, 4000, 1.0, 0.5);
        Parameter[] parameters = new Parameter[] { tau, f_init, f_final };
        OptModel optModel = new OptModel("photoactivation (activated roi)", parameters) {

            @Override
            public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
                double tau = newParams[0];
                double max = newParams[1];
                double offset = newParams[2];
                double[][] solution = new double[1][solutionTimePoints.length];
                for (int i = 0; i < solution[0].length; i++) {
                    double t = solutionTimePoints[i];
                    solution[0][i] = offset + (max - offset) * Math.exp(-t / tau);
                }
                return solution;
            }

            @Override
            public double getPenalty(double[] parameters2) {
                return 0;
            }
        };
        ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
        OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
        new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated ROI only", null);
    }
    {
        // 
        // only activation ROI for chemistry, cellROI for bleaching
        // 
        NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI), NormalizedSampleFunction.fromROI(cellROI) };
        // 
        // get reduced data and errors for each ROI
        // 
        RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
        RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
        DisplayPlotOp displayReducedData = new DisplayPlotOp();
        displayReducedData.displayPlot(reducedData, "reduced data (2)", null);
        DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
        displayMeasurementError.displayPlot(measurementErrors, "measurement error (2)", null);
        // 
        // 2 parameter uniform disk model
        // 
        Parameter tau_active = new Parameter("tau_active", 0.001, 200.0, 1.0, 0.1);
        Parameter f_active_init = new Parameter("f_active_init", 0.5, 4000, 1.0, 1.0);
        Parameter f_active_amplitude = new Parameter("f_active_amplitude", 0.01, 4000, 1.0, 0.5);
        Parameter f_cell_init = new Parameter("f_cell_init", 0.01, 4000, 1.0, 0.1);
        Parameter f_cell_amplitude = new Parameter("f_cell_amplitude", 0.01, 4000, 1.0, 0.1);
        Parameter tau_cell = new Parameter("tau_cell", 0.00001, 200, 1.0, 1);
        Parameter[] parameters = new Parameter[] { tau_active, f_active_init, f_active_amplitude, tau_cell, f_cell_init, f_cell_amplitude };
        OptModel optModel = new OptModel("photoactivation (activated and cell rois)", parameters) {

            @Override
            public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
                double tau_active = newParams[0];
                double max_active = newParams[1];
                double amplitude_active = newParams[2];
                double tau_cell = newParams[3];
                double max_cell = newParams[4];
                double amplitude_cell = newParams[5];
                final int ACTIVE_ROI = 0;
                final int CELL_ROI = 1;
                final int NUM_ROIS = 2;
                double[][] solution = new double[NUM_ROIS][solutionTimePoints.length];
                for (int i = 0; i < solution[0].length; i++) {
                    double t = solutionTimePoints[i];
                    solution[ACTIVE_ROI][i] = (max_active - amplitude_active) + (amplitude_active) * Math.exp(-t / tau_active) * Math.exp(-t / tau_cell);
                    solution[CELL_ROI][i] = (max_cell - amplitude_cell) + (amplitude_cell) * Math.exp(-t / tau_cell);
                }
                return solution;
            }

            @Override
            public double getPenalty(double[] parameters2) {
                return 0;
            }
        };
        ErrorFunctionNoiseWeightedL2 errorFunction = new ErrorFunctionNoiseWeightedL2();
        OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
        new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated and cell ROIs", null);
    }
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) GenerateCellROIsFromRawPhotoactivationTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawPhotoactivationTimeSeriesOp) ErrorFunctionNoiseWeightedL2(org.vcell.vmicro.workflow.data.ErrorFunctionNoiseWeightedL2) OptContext(org.vcell.vmicro.workflow.data.OptContext) OptModel(org.vcell.vmicro.workflow.data.OptModel) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) NormalizedPhotoactivationDataResults(org.vcell.vmicro.op.GenerateNormalizedPhotoactivationDataOp.NormalizedPhotoactivationDataResults) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) GeometryRoisAndActivationTiming(org.vcell.vmicro.op.GenerateCellROIsFromRawPhotoactivationTimeSeriesOp.GeometryRoisAndActivationTiming) DisplayInteractiveModelOp(org.vcell.vmicro.op.display.DisplayInteractiveModelOp) GenerateActivationRoiOp(org.vcell.vmicro.op.GenerateActivationRoiOp) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ErrorFunction(org.vcell.vmicro.workflow.data.ErrorFunction) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) Parameter(cbit.vcell.opt.Parameter) GenerateNormalizedPhotoactivationDataOp(org.vcell.vmicro.op.GenerateNormalizedPhotoactivationDataOp)

Example 4 with DisplayImageOp

use of org.vcell.vmicro.op.display.DisplayImageOp in project vcell by virtualcell.

the class WorkflowObjectsPanel method displayData.

private void displayData(TaskContext taskContext, WorkflowObject workflowObject) {
    if (workflowObject instanceof DataInput || workflowObject instanceof DataOutput) {
        String title = parametersFunctionsTableModel.getName(workflowObject);
        WindowListener listener = new WindowAdapter() {
        };
        Object data = null;
        if (workflowObject instanceof WorkflowDataSource) {
            WorkflowDataSource dataHolder = (WorkflowDataSource) workflowObject;
            data = taskContext.getRepository().getData(dataHolder);
        } else if (workflowObject instanceof DataInput) {
            DataInput dataInput = (DataInput) workflowObject;
            data = taskContext.getData(dataInput);
        }
        if (data instanceof RowColumnResultSet) {
            RowColumnResultSet rc = (RowColumnResultSet) data;
            try {
                new DisplayPlotOp().displayPlot(rc, title, listener);
            } catch (ExpressionException e) {
                e.printStackTrace();
            }
        } else if (data instanceof ROI) {
            ROI roi = (ROI) data;
            Image image = roi.getRoiImages()[0];
            new DisplayImageOp().displayImage(image, title, listener);
        } else if (data instanceof ProfileData[]) {
            ProfileData[] profileData = (ProfileData[]) data;
            new DisplayProfileLikelihoodPlotsOp().displayProfileLikelihoodPlots(profileData, title, listener);
        } else if (data instanceof Image) {
            Image image = (Image) data;
            new DisplayImageOp().displayImage(image, title, listener);
        } else if (data instanceof ImageTimeSeries) {
            ImageTimeSeries imageTimeSeries = (ImageTimeSeries) data;
            try {
                DisplayTimeSeries.displayImageTimeSeries(imageTimeSeries, title, listener);
            } catch (ImageException | IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : DataOutput(org.vcell.workflow.DataOutput) DisplayProfileLikelihoodPlotsOp(org.vcell.vmicro.op.display.DisplayProfileLikelihoodPlotsOp) WindowListener(java.awt.event.WindowListener) ImageException(cbit.image.ImageException) WindowAdapter(java.awt.event.WindowAdapter) ProfileData(org.vcell.optimization.ProfileData) IOException(java.io.IOException) Image(cbit.vcell.VirtualMicroscopy.Image) ROI(cbit.vcell.VirtualMicroscopy.ROI) WorkflowDataSource(org.vcell.workflow.WorkflowDataSource) ExpressionException(cbit.vcell.parser.ExpressionException) DataInput(org.vcell.workflow.DataInput) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) WorkflowObject(org.vcell.workflow.WorkflowObject) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 5 with DisplayImageOp

use of org.vcell.vmicro.op.display.DisplayImageOp in project vcell by virtualcell.

the class DisplayImage method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    DisplayImageOp op = new DisplayImageOp();
    op.displayImage(context.getData(image), context.getDataWithDefault(title, "no title"), null);
    context.setData(displayed, true);
}
Also used : DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp)

Aggregations

DisplayImageOp (org.vcell.vmicro.op.display.DisplayImageOp)6 ROI (cbit.vcell.VirtualMicroscopy.ROI)3 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)3 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)3 DisplayTimeSeriesOp (org.vcell.vmicro.op.display.DisplayTimeSeriesOp)3 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)2 ComputeMeasurementErrorOp (org.vcell.vmicro.op.ComputeMeasurementErrorOp)2 Generate2DOptContextOp (org.vcell.vmicro.op.Generate2DOptContextOp)2 GenerateReducedDataOp (org.vcell.vmicro.op.GenerateReducedDataOp)2 DisplayInteractiveModelOp (org.vcell.vmicro.op.display.DisplayInteractiveModelOp)2 DisplayPlotOp (org.vcell.vmicro.op.display.DisplayPlotOp)2 DisplayProfileLikelihoodPlotsOp (org.vcell.vmicro.op.display.DisplayProfileLikelihoodPlotsOp)2 ErrorFunction (org.vcell.vmicro.workflow.data.ErrorFunction)2 OptContext (org.vcell.vmicro.workflow.data.OptContext)2 OptModel (org.vcell.vmicro.workflow.data.OptModel)2 ImageException (cbit.image.ImageException)1 Image (cbit.vcell.VirtualMicroscopy.Image)1 Parameter (cbit.vcell.opt.Parameter)1 ExpressionException (cbit.vcell.parser.ExpressionException)1 WindowAdapter (java.awt.event.WindowAdapter)1