Search in sources :

Example 1 with RandomAccessibleInterval

use of net.imglib2.RandomAccessibleInterval in project vcell by virtualcell.

the class DeconstructGeometryCommand method run.

@Override
public void run() {
    // Crop to get a z-stack over time (remove channel dimension)
    long maxX = fluorData.max(fluorData.dimensionIndex(Axes.X));
    long maxY = fluorData.max(fluorData.dimensionIndex(Axes.Y));
    long maxZ = fluorData.max(fluorData.dimensionIndex(Axes.Z));
    long maxTime = fluorData.max(fluorData.dimensionIndex(Axes.TIME));
    Img fluorImg = fluorData.getImgPlus().getImg();
    FinalInterval intervals = Intervals.createMinMax(0, 0, 0, 0, 0, maxX, maxY, maxZ, 0, maxTime);
    RandomAccessibleInterval fluorImgCropped = ops.transform().crop(fluorImg, intervals, true);
    // Calculate scale factors
    double[] scaleFactors = { 1, 1, 1, 1 };
    for (int i = 0; i < geomData.numDimensions(); i++) {
        scaleFactors[i] = geomData.dimension(i) / (double) fluorImgCropped.dimension(i);
    }
    // Scale the fluorescence dataset to match the geometry
    NLinearInterpolatorFactory interpolatorFactory = new NLinearInterpolatorFactory();
    RandomAccessibleInterval fluorScaled = ops.transform().scale(fluorImgCropped, scaleFactors, interpolatorFactory);
    // Crop out the first slice of each z-stack in time series
    intervals = Intervals.createMinMax(0, 0, 0, 0, fluorScaled.dimension(0) - 1, fluorScaled.dimension(1) - 1, 0, fluorScaled.dimension(3) - 1);
    IntervalView fluorXYT = (IntervalView) ops.transform().crop(fluorScaled, intervals, true);
    // Create a blank image of the same X-Y-Time dimensions
    long[] dimensions = { fluorXYT.dimension(0), fluorXYT.dimension(1), fluorXYT.dimension(2) };
    Img<DoubleType> result = ops.create().img(dimensions);
    // Calculate constant d in TIRF exponential decay function
    theta = theta * 2 * Math.PI / 360;
    double n1 = 1.52;
    double n2 = 1.38;
    double d = lambda * Math.pow((Math.pow(n1, 2) * Math.pow(Math.sin(theta), 2) - Math.pow(n2, 2)), -0.5) / (4 * Math.PI);
    // Iterate through each time point, using 3D geometry to generate 2D intensities
    Cursor<DoubleType> cursor = fluorXYT.localizingCursor();
    RandomAccess fluorRA = fluorScaled.randomAccess();
    RandomAccess<RealType<?>> geomRA = geomData.randomAccess();
    RandomAccess<DoubleType> resultRA = result.randomAccess();
    maxZ = geomData.dimension(2) - 1;
    while (cursor.hasNext()) {
        cursor.fwd();
        int[] positionXYZ = { cursor.getIntPosition(0), cursor.getIntPosition(1), (int) maxZ - 1 };
        int[] positionXYZT = { cursor.getIntPosition(0), cursor.getIntPosition(1), (int) maxZ - 1, cursor.getIntPosition(2) };
        resultRA.setPosition(cursor);
        geomRA.setPosition(positionXYZ);
        double sum = 0.0;
        while (positionXYZ[2] >= 0 && geomRA.get().getRealDouble() != 0.0) {
            fluorRA.setPosition(positionXYZT);
            geomRA.setPosition(positionXYZ);
            sum += geomRA.get().getRealDouble() * Math.exp(-zSpacing * positionXYZ[2] / d);
            positionXYZ[2]--;
        }
        resultRA.get().set(sum);
    }
    System.out.println("done");
    displayService.createDisplay(result);
}
Also used : Img(net.imglib2.img.Img) NLinearInterpolatorFactory(net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory) RandomAccess(net.imglib2.RandomAccess) RealType(net.imglib2.type.numeric.RealType) IntervalView(net.imglib2.view.IntervalView) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) DoubleType(net.imglib2.type.numeric.real.DoubleType) FinalInterval(net.imglib2.FinalInterval)

Example 2 with RandomAccessibleInterval

use of net.imglib2.RandomAccessibleInterval in project vcell by virtualcell.

the class PlotROIStats method run.

@Override
public void run() {
    Plot plot = new ColorPlot("ROI Mean Intensity", "Time", "Mean Intensity");
    StringBuilder legendLabels = new StringBuilder();
    for (RandomAccessibleInterval<T> data : datasetROIsMap.keySet()) {
        if (data instanceof Dataset) {
            legendLabels.append(((Dataset) data).getName());
            legendLabels.append(": ");
        }
        List<Overlay> overlays = datasetROIsMap.get(data);
        for (int i = 0; i < overlays.size(); i++) {
            Overlay overlay = overlays.get(i);
            RandomAccessibleInterval<T> cropped = crop(data, overlay);
            Pair<double[], double[]> xyPair = (Pair<double[], double[]>) ops.run("imageStatsForPlotting", ImageStatsForPlotting.MEAN, cropped);
            plot.addPoints(xyPair.getA(), xyPair.getB(), Plot.LINE);
            legendLabels.append("ROI ");
            legendLabels.append(i + 1);
            legendLabels.append("\n");
        }
    }
    plot.addLegend(legendLabels.toString());
    plot.show();
}
Also used : ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Dataset(net.imagej.Dataset) Plot(ij.gui.Plot) ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Overlay(net.imagej.overlay.Overlay) Pair(net.imglib2.util.Pair)

Example 3 with RandomAccessibleInterval

use of net.imglib2.RandomAccessibleInterval in project vcell by virtualcell.

the class PlotROIStats method crop.

private RandomAccessibleInterval<T> crop(RandomAccessibleInterval<T> data, Overlay overlay) {
    int numDimensions = data.numDimensions();
    long[] minDimensions = new long[numDimensions];
    long[] maxDimensions = new long[numDimensions];
    if (numDimensions > 0) {
        minDimensions[0] = (long) overlay.realMin(0);
        maxDimensions[0] = (long) overlay.realMax(0);
    }
    if (numDimensions > 1) {
        minDimensions[1] = (long) overlay.realMin(0);
        maxDimensions[1] = (long) overlay.realMax(0);
    }
    for (int i = 2; i < numDimensions; i++) {
        minDimensions[i] = 0;
        maxDimensions[i] = data.dimension(i) - 1;
    }
    FinalInterval interval = new FinalInterval(minDimensions, maxDimensions);
    RandomAccessibleInterval<T> cropped = ops.transform().crop(data, interval);
    return cropped;
}
Also used : FinalInterval(net.imglib2.FinalInterval)

Example 4 with RandomAccessibleInterval

use of net.imglib2.RandomAccessibleInterval in project vcell by virtualcell.

the class CompareController method getMaskFromGeometry.

private RandomAccessibleInterval<BitType> getMaskFromGeometry() {
    DatasetSelectionPanel panel = new DatasetSelectionPanel();
    List<Dataset> geometryList = model.getProject().getGeometry();
    final String description = "Geometry: ";
    panel.addComboBox(geometryList.toArray(new Dataset[geometryList.size()]), description);
    int returnVal = JOptionPane.showConfirmDialog(view, panel, "Select cell geometry", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
    if (returnVal == JOptionPane.OK_OPTION) {
        Dataset geometry = panel.getSelectedDatasetForDescription(description);
        @SuppressWarnings("unchecked") RandomAccessibleInterval<BitType> mask = (RandomAccessibleInterval<BitType>) opService.run("largestRegionSlice", geometry);
        return mask;
    }
    return null;
}
Also used : RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) BitType(net.imglib2.type.logic.BitType) Dataset(net.imagej.Dataset)

Example 5 with RandomAccessibleInterval

use of net.imglib2.RandomAccessibleInterval in project vcell by virtualcell.

the class PlotImageStats method run.

@Override
public void run() {
    Plot plot = new ColorPlot("Frame mean intensity", "Time", "Mean intensity");
    StringBuilder legendLabels = new StringBuilder();
    for (int i = 0; i < datasets.size(); i++) {
        RandomAccessibleInterval<T> data = datasets.get(i);
        if (data instanceof Dataset) {
            legendLabels.append(((Dataset) data).getName());
            legendLabels.append(": ");
        }
        Pair<double[], double[]> xyPair = (Pair<double[], double[]>) ops.run("imageStatsForPlotting", ImageStatsForPlotting.MEAN, data, mask);
        plot.addPoints(xyPair.getA(), xyPair.getB(), Plot.LINE);
        legendLabels.append("ROI ");
        legendLabels.append(i + 1);
        legendLabels.append("\n");
    }
    plot.addLegend(legendLabels.toString());
    plot.show();
}
Also used : ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Dataset(net.imagej.Dataset) Plot(ij.gui.Plot) ColorPlot(org.vcell.imagej.common.gui.ColorPlot) Pair(net.imglib2.util.Pair)

Aggregations

Dataset (net.imagej.Dataset)4 FinalInterval (net.imglib2.FinalInterval)4 BitType (net.imglib2.type.logic.BitType)4 RandomAccessibleInterval (net.imglib2.RandomAccessibleInterval)3 Plot (ij.gui.Plot)2 Img (net.imglib2.img.Img)2 DoubleType (net.imglib2.type.numeric.real.DoubleType)2 Pair (net.imglib2.util.Pair)2 ColorPlot (org.vcell.imagej.common.gui.ColorPlot)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CalibratedAxis (net.imagej.axis.CalibratedAxis)1 DefaultLinearAxis (net.imagej.axis.DefaultLinearAxis)1 Overlay (net.imagej.overlay.Overlay)1 Interval (net.imglib2.Interval)1 IterableInterval (net.imglib2.IterableInterval)1 RandomAccess (net.imglib2.RandomAccess)1 NLinearInterpolatorFactory (net.imglib2.interpolation.randomaccess.NLinearInterpolatorFactory)1 LabelRegion (net.imglib2.roi.labeling.LabelRegion)1