Search in sources :

Example 31 with UShortImage

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

the class RunFakeSim method compute0.

@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    // set input
    Simulation sim = context.getData(simulation_2D);
    Double max_intensity = context.getData(maxIntensity);
    Double bleachLockingBegin = context.getData(bleachBlackoutBeginTime);
    Double bleachLockoutEnd = context.getData(bleachBlackoutEndTime);
    Boolean hasNoise = context.getData(bNoise);
    // do op
    RunFakeSimOp op = new RunFakeSimOp();
    ImageTimeSeries<UShortImage> solution = op.runRefSimulation(context.getLocalWorkspace(), sim, max_intensity, bleachLockingBegin, bleachLockoutEnd, hasNoise, clientTaskStatusSupport);
    // set output
    context.setData(simTimeSeries, solution);
}
Also used : RunFakeSimOp(org.vcell.vmicro.op.RunFakeSimOp) Simulation(cbit.vcell.solver.Simulation) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 32 with UShortImage

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

the class GenerateActivationRoiOp method generateActivatedRoi.

public ROI generateActivatedRoi(Image firstPostactivation, ROI cellROI_2D, Double activationThreshold) throws ImageException {
    int numPixels = firstPostactivation.getNumXYZ();
    short[] scaledActivatedDataShort = new short[numPixels];
    short[] erodedCellUShort = cellROI_2D.getRoiImages()[0].getBinaryPixels(1);
    // input is already normalized to 1.0 ... if relative to max, then crazy values from outside cell can interfere.
    double activationThresholdValue = activationThreshold;
    double[] firstPostactivationImage = firstPostactivation.getDoublePixels();
    for (int j = 0; j < numPixels; j++) {
        boolean isCell = (erodedCellUShort[j] == 1);
        boolean isActivation = firstPostactivationImage[j] > activationThresholdValue;
        if (isCell && isActivation) {
            scaledActivatedDataShort[j] = 1;
        }
    }
    UShortImage activatedImage = new UShortImage(scaledActivatedDataShort, firstPostactivation.getOrigin(), firstPostactivation.getExtent(), firstPostactivation.getNumX(), firstPostactivation.getNumY(), firstPostactivation.getNumZ());
    ROI bleachedROI = new ROI(activatedImage, "bleachedROI");
    return bleachedROI;
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 33 with UShortImage

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

the class GenerateCellROIsFromRawFrapTimeSeriesOp method generate.

public GeometryRoisAndBleachTiming generate(ImageTimeSeries rawTimeSeriesImages, double cellThreshold) throws Exception {
    Image[] allImages = rawTimeSeriesImages.getAllImages();
    int numPixels = allImages[0].getNumXYZ();
    int numTimes = allImages.length;
    ImageStatistics[] imageStats = new ImageStatistics[numTimes];
    for (int i = 0; i < numTimes; i++) {
        imageStats[i] = allImages[i].getImageStatistics();
    }
    // 
    // find largest change in fluorescence (ratio of total[n]/total[n+1]
    // 
    int indexPostbleach = -1;
    double largestRatio = 0.0;
    for (int tIndex = 0; tIndex < numTimes - 1; tIndex++) {
        double currentRatio = imageStats[tIndex].meanValue / imageStats[tIndex + 1].meanValue;
        if (currentRatio > largestRatio) {
            largestRatio = currentRatio;
            indexPostbleach = tIndex + 1;
        }
    }
    double[] firstImagePixels = allImages[0].getDoublePixels();
    short[] scaledCellDataShort = new short[numPixels];
    short[] scaledBackgoundDataShort = new short[numPixels];
    short[] wholeDomainDataShort = new short[numPixels];
    // 
    // find cell and background by thresholding the first image
    // 
    double cellThresholdValue = cellThreshold * imageStats[0].maxValue;
    for (int j = 0; j < numPixels; j++) {
        boolean isCell = firstImagePixels[j] > cellThresholdValue;
        if (isCell) {
            scaledCellDataShort[j] = 1;
        } else {
            scaledBackgoundDataShort[j] = 1;
        }
    }
    UShortImage cellImage = new UShortImage(scaledCellDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    Arrays.fill(wholeDomainDataShort, (short) 1);
    UShortImage wholeDomainImage = new UShortImage(wholeDomainDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    UShortImage reverseCell = UShortImage.fastDilate(cellImage, 15, wholeDomainImage);
    reverseCell.reverse();
    reverseCell.and(backgroundImage);
    backgroundImage = reverseCell;
    ROI cellROI = new ROI(cellImage, "cellROI");
    ROI backgroundROI = new ROI(backgroundImage, "backgroundROI");
    GeometryRoisAndBleachTiming results = new GeometryRoisAndBleachTiming();
    results.cellROI_2D = cellROI;
    results.backgroundROI_2D = backgroundROI;
    results.indexOfFirstPostbleach = indexPostbleach;
    return results;
}
Also used : ImageStatistics(cbit.vcell.VirtualMicroscopy.Image.ImageStatistics) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Image(cbit.vcell.VirtualMicroscopy.Image) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 34 with UShortImage

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

the class GenerateDependentImageROIsOp method generate.

public ROI[] generate(ROI cellROI_2d, ROI bleachedROI_2d) throws Exception {
    UShortImage cellROI_2D = null;
    UShortImage bleachedROI_2D = null;
    UShortImage dilatedROI_2D_1 = null;
    UShortImage dilatedROI_2D_2 = null;
    UShortImage dilatedROI_2D_3 = null;
    UShortImage dilatedROI_2D_4 = null;
    UShortImage dilatedROI_2D_5 = null;
    UShortImage erodedROI_2D_0 = null;
    UShortImage erodedROI_2D_1 = null;
    UShortImage erodedROI_2D_2 = null;
    cellROI_2D = cellROI_2d.getRoiImages()[0];
    bleachedROI_2D = bleachedROI_2d.getRoiImages()[0];
    dilatedROI_2D_1 = UShortImage.fastDilate(bleachedROI_2D, 4, cellROI_2D);
    dilatedROI_2D_2 = UShortImage.fastDilate(bleachedROI_2D, 10, cellROI_2D);
    dilatedROI_2D_3 = UShortImage.fastDilate(bleachedROI_2D, 18, cellROI_2D);
    dilatedROI_2D_4 = UShortImage.fastDilate(bleachedROI_2D, 28, cellROI_2D);
    dilatedROI_2D_5 = UShortImage.fastDilate(bleachedROI_2D, 40, cellROI_2D);
    erodedROI_2D_0 = new UShortImage(bleachedROI_2D);
    // The erode always causes problems if eroding without checking the bleached length and height.
    // we have to check the min length of the bleached area to make sure erode within the length.
    Rectangle bleachRect = bleachedROI_2D.getNonzeroBoundingBox();
    if (bleachRect == null || bleachRect.isEmpty()) {
        throw new RuntimeException("bleach ROI is null or empty");
    }
    int minLen = Math.min(bleachRect.height, bleachRect.width);
    if ((minLen / 2.0) < 5) {
        erodedROI_2D_1 = UShortImage.erodeDilate(bleachedROI_2D, UShortImage.createCircularBinaryKernel(1), bleachedROI_2D, true);
        erodedROI_2D_2 = UShortImage.erodeDilate(bleachedROI_2D, UShortImage.createCircularBinaryKernel(2), bleachedROI_2D, true);
    } else {
        erodedROI_2D_1 = UShortImage.erodeDilate(bleachedROI_2D, UShortImage.createCircularBinaryKernel(2), bleachedROI_2D, true);
        erodedROI_2D_2 = UShortImage.erodeDilate(bleachedROI_2D, UShortImage.createCircularBinaryKernel(5), bleachedROI_2D, true);
    }
    UShortImage reverseErodeROI_2D_1 = new UShortImage(erodedROI_2D_1);
    reverseErodeROI_2D_1.reverse();
    erodedROI_2D_0.and(reverseErodeROI_2D_1);
    UShortImage reverseErodeROI_2D_2 = new UShortImage(erodedROI_2D_2);
    reverseErodeROI_2D_2.reverse();
    erodedROI_2D_1.and(reverseErodeROI_2D_2);
    UShortImage reverseDilateROI_2D_4 = new UShortImage(dilatedROI_2D_4);
    reverseDilateROI_2D_4.reverse();
    dilatedROI_2D_5.and(reverseDilateROI_2D_4);
    UShortImage reverseDilateROI_2D_3 = new UShortImage(dilatedROI_2D_3);
    reverseDilateROI_2D_3.reverse();
    dilatedROI_2D_4.and(reverseDilateROI_2D_3);
    UShortImage reverseDilateROI_2D_2 = new UShortImage(dilatedROI_2D_2);
    reverseDilateROI_2D_2.reverse();
    dilatedROI_2D_3.and(reverseDilateROI_2D_2);
    UShortImage reverseDilateROI_2D_1 = new UShortImage(dilatedROI_2D_1);
    reverseDilateROI_2D_1.reverse();
    dilatedROI_2D_2.and(reverseDilateROI_2D_1);
    UShortImage reverseBleach_2D = new UShortImage(bleachedROI_2D);
    reverseBleach_2D.reverse();
    dilatedROI_2D_1.and(reverseBleach_2D);
    ArrayList<ROI> rois = new ArrayList<ROI>();
    // rois.add(new ROI(this.bleachedROI_2D.getData())); // copy this one through
    rois.add(new ROI(erodedROI_2D_2, VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name()));
    rois.add(new ROI(erodedROI_2D_1, VFRAP_ROI_ENUM.ROI_BLEACHED_RING2.name()));
    rois.add(new ROI(erodedROI_2D_0, VFRAP_ROI_ENUM.ROI_BLEACHED_RING3.name()));
    rois.add(new ROI(dilatedROI_2D_1, VFRAP_ROI_ENUM.ROI_BLEACHED_RING4.name()));
    rois.add(new ROI(dilatedROI_2D_2, VFRAP_ROI_ENUM.ROI_BLEACHED_RING5.name()));
    rois.add(new ROI(dilatedROI_2D_3, VFRAP_ROI_ENUM.ROI_BLEACHED_RING6.name()));
    rois.add(new ROI(dilatedROI_2D_4, VFRAP_ROI_ENUM.ROI_BLEACHED_RING7.name()));
    rois.add(new ROI(dilatedROI_2D_5, VFRAP_ROI_ENUM.ROI_BLEACHED_RING8.name()));
    Iterator<ROI> roiIter = rois.iterator();
    while (roiIter.hasNext()) {
        ROI roi = roiIter.next();
        short[] roiPixels = roi.getBinaryPixelsXYZ(1);
        int numPixels = roiPixels.length;
        int count = 0;
        for (int p = 0; p < numPixels; p++) {
            if (roiPixels[p] != 0) {
                count++;
            }
        }
        if (count == 0) {
            roiIter.remove();
        }
    }
    return rois.toArray(new ROI[0]);
}
Also used : Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 35 with UShortImage

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

the class ComputeMeasurementErrorOp method computeNormalizedMeasurementError.

public RowColumnResultSet computeNormalizedMeasurementError(NormalizedSampleFunction[] rois, int indexPostbleach, ImageTimeSeries<UShortImage> rawImageDataset, FloatImage prebleachAvgImage, final ClientTaskStatusSupport clientTaskStatusSupport) throws ImageException {
    UShortImage[] rawImages = rawImageDataset.getAllImages();
    double[] timeStamps = rawImageDataset.getImageTimeStamps();
    double[][] sigma = refreshNormalizedMeasurementError(rawImages, timeStamps, prebleachAvgImage, rois, indexPostbleach);
    String[] columnNames = new String[rois.length + 1];
    columnNames[0] = "t";
    for (int i = 0; i < rois.length; i++) {
        columnNames[i + 1] = rois[i].getName();
    }
    RowColumnResultSet rowColumnResultSet = new RowColumnResultSet(columnNames);
    double[] allTimePoints = timeStamps;
    for (int time = 0; time < (allTimePoints.length - indexPostbleach); time++) {
        double[] rowValues = new double[rois.length + 1];
        rowValues[0] = allTimePoints[time + indexPostbleach];
        for (int col = 0; col < rois.length; col++) {
            rowValues[col + 1] = sigma[col][time];
        }
        rowColumnResultSet.addRow(rowValues);
    }
    return rowColumnResultSet;
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet)

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