Search in sources :

Example 96 with UShortImage

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

the class ImportRawTimeSeriesFromVFrapOp method importRawTimeSeriesFromVFrap.

public ImageTimeSeries<UShortImage> importRawTimeSeriesFromVFrap(File vfrapFile) throws Exception {
    String xmlString = XmlUtil.getXMLString(vfrapFile.getAbsolutePath());
    MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
    Element vFrapRoot = XmlUtil.stringToXML(xmlString, null).getRootElement();
    // loading frap images and a ROIs subset for display purposes only (see next task)
    AnnotatedImageDataset annotatedImages = xmlReader.getAnnotatedImageDataset(vFrapRoot, null);
    ImageDataset imageDataset = annotatedImages.getImageDataset();
    UShortImage[] allImages = imageDataset.getAllImages();
    double[] imageTimeStamps = imageDataset.getImageTimeStamps();
    ImageTimeSeries<UShortImage> imageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, allImages, imageTimeStamps, 1);
    return imageTimeSeries;
}
Also used : MicroscopyXmlReader(cbit.vcell.VirtualMicroscopy.importer.MicroscopyXmlReader) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) AnnotatedImageDataset(cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) AnnotatedImageDataset(cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 97 with UShortImage

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

the class RunFakeSimOp method runRefSimulation.

public ImageTimeSeries<UShortImage> runRefSimulation(LocalWorkspace localWorkspace, Simulation simulation, double max_intensity, double bleachBlackoutStartTime, double bleachBlackoutStopTime, boolean hasNoise, ClientTaskStatusSupport progressListener) throws Exception {
    User owner = LocalWorkspace.getDefaultOwner();
    KeyValue simKey = LocalWorkspace.createNewKeyValue();
    runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), simulation, progressListener);
    Extent extent = simulation.getMathDescription().getGeometry().getExtent();
    Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
    VCDataIdentifier vcDataIdentifier = new VCSimulationDataIdentifier(new VCSimulationIdentifier(simulation.getKey(), simulation.getVersion().getOwner()), 0);
    CartesianMesh mesh = localWorkspace.getDataSetControllerImpl().getMesh(vcDataIdentifier);
    ISize isize = new ISize(mesh.getSizeX(), mesh.getSizeY(), mesh.getSizeZ());
    double[] dataTimes = localWorkspace.getDataSetControllerImpl().getDataSetTimes(vcDataIdentifier);
    DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) localWorkspace.getDataSetControllerImpl().doDataOperation(new DataProcessingOutputDataValuesOP(vcDataIdentifier, SimulationContext.FLUOR_DATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null));
    ArrayList<SourceDataInfo> sourceDataInfoArr = dataProcessingOutputDataValues.createSourceDataInfos(new ISize(mesh.getSizeX(), mesh.getSizeY(), 1), origin, extent);
    // find scale factor to scale up the data to avoid losing precision when casting double to short
    double maxDataValue = 0;
    for (int i = 0; i < dataTimes.length; i++) {
        if (sourceDataInfoArr.get(i).getMinMax() != null) {
            maxDataValue = Math.max(maxDataValue, sourceDataInfoArr.get(i).getMinMax().getMax());
        } else {
            double[] doubleData = (double[]) sourceDataInfoArr.get(i).getData();
            for (int j = 0; j < doubleData.length; j++) {
                maxDataValue = Math.max(maxDataValue, doubleData[j]);
            }
        }
    }
    double scale = max_intensity / maxDataValue;
    ArrayList<UShortImage> outputImages = new ArrayList<UShortImage>();
    ArrayList<Double> outputTimes = new ArrayList<Double>();
    for (int i = 0; i < dataTimes.length; i++) {
        if (dataTimes[i] < bleachBlackoutStartTime || dataTimes[i] > bleachBlackoutStopTime) {
            // saving each time step 2D double array to a UShortImage
            double[] doubleData = (double[]) sourceDataInfoArr.get(i).getData();
            short[] shortData = new short[isize.getX() * isize.getY()];
            for (int j = 0; j < shortData.length; j++) {
                double dData = doubleData[j] * scale;
                if (dData < 0 || dData > 65535.0) {
                    throw new RuntimeException("scaled pixel out of range of unsigned 16 bit integer, original simulated value = " + doubleData[j] + ", scale = " + scale + ", scaled value = " + dData);
                }
                short sData = (short) (0x0000ffff & ((int) dData));
                if (hasNoise && dData > 0.0) {
                    if (dData > 20) {
                        shortData[j] = (short) (0x0000ffff & (int) RandomVariable.normal(dData, Math.sqrt(dData)));
                    } else {
                        shortData[j] = (short) (0x0000ffff & RandomVariable.poisson(dData));
                    }
                } else {
                    shortData[j] = sData;
                }
            }
            outputTimes.add(dataTimes[i]);
            outputImages.add(new UShortImage(shortData, sourceDataInfoArr.get(i).getOrigin(), sourceDataInfoArr.get(i).getExtent(), sourceDataInfoArr.get(i).getXSize(), sourceDataInfoArr.get(i).getYSize(), 1));
            if (progressListener != null) {
                int progress = (int) (((i + 1) * 1.0 / dataTimes.length) * 100);
                progressListener.setProgress(progress);
            }
        }
    }
    double[] outputTimesArray = new double[outputTimes.size()];
    for (int i = 0; i < outputTimes.size(); i++) {
        outputTimesArray[i] = outputTimes.get(i);
    }
    ImageTimeSeries<UShortImage> fakeFluorTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, outputImages.toArray(new UShortImage[0]), outputTimesArray, 1);
    return fakeFluorTimeSeries;
}
Also used : Origin(org.vcell.util.Origin) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) SourceDataInfo(cbit.image.SourceDataInfo) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) CartesianMesh(cbit.vcell.solvers.CartesianMesh) DataProcessingOutputDataValuesOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) File(java.io.File) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 98 with UShortImage

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

the class ImportRawTimeSeriesFromHdf5FluorOp method importTimeSeriesFromHDF5Data.

public ImageTimeSeries<UShortImage> importTimeSeriesFromHDF5Data(File inputHDF5File, String fluorDataName, Double maxIntensity, boolean bNoise, int zSliceIndex) throws Exception {
    // if(progressListener != null){
    // progressListener.setMessage("Loading HDF5 file " + inputHDF5File.getAbsolutePath() + "...");
    // }
    DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(null, /*no vcDataIdentifier OK*/
    false, null), inputHDF5File);
    DataOperationResults.DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataOperationResults.DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputDataValuesOP(null, /*no vcDataIdentifier OK*/
    SimulationContext.FLUOR_DATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null), inputHDF5File);
    ArrayList<SourceDataInfo> sdiArr = dataProcessingOutputDataValues.createSourceDataInfos(dataProcessingOutputInfo.getVariableISize(SimulationContext.FLUOR_DATA_NAME), dataProcessingOutputInfo.getVariableOrigin(SimulationContext.FLUOR_DATA_NAME), dataProcessingOutputInfo.getVariableExtent(SimulationContext.FLUOR_DATA_NAME));
    double[] times = dataProcessingOutputInfo.getVariableTimePoints();
    if (sdiArr.size() != times.length) {
        throw new ImageException("Error FRAPData.createFrapData: times array length must equal SourceDataInfo vector size");
    }
    // construct
    int XY_SIZE = sdiArr.get(0).getXSize() * sdiArr.get(0).getYSize();
    int SLICE_OFFSET = 0 * XY_SIZE;
    // slice always 2D data
    int Z_SIZE = 1;
    // find scale factor to scale up the data to avoid losing precision when casting double to short
    double linearScaleFactor = 1;
    if (maxIntensity != null) {
        double maxDataValue = 0;
        for (int i = 0; i < times.length; i++) {
            if (sdiArr.get(i).getMinMax() != null) {
                maxDataValue = Math.max(maxDataValue, sdiArr.get(i).getMinMax().getMax());
            } else {
                double[] doubleData = (double[]) sdiArr.get(i).getData();
                for (int j = 0; j < doubleData.length; j++) {
                    maxDataValue = Math.max(maxDataValue, doubleData[j]);
                }
            }
        }
        linearScaleFactor = maxIntensity.doubleValue() / maxDataValue;
    }
    // saving each time step 2D double array to a UShortImage
    UShortImage[] dataImages1 = new UShortImage[times.length];
    for (int i = 0; i < times.length; i++) {
        double[] doubleData = (double[]) sdiArr.get(i).getData();
        short[] shortData = new short[XY_SIZE];
        for (int j = 0; j < shortData.length; j++) {
            shortData[j] = (short) (doubleData[j + (SLICE_OFFSET)] * linearScaleFactor);
        }
        dataImages1[i] = new UShortImage(shortData, sdiArr.get(i).getOrigin(), sdiArr.get(i).getExtent(), sdiArr.get(i).getXSize(), sdiArr.get(i).getYSize(), Z_SIZE);
    // if(progressListener != null){
    // int progress = (int)(((i+1)*1.0/times.length)*100);
    // progressListener.setProgress(progress);
    // }
    }
    ImageDataset imageDataSet = new ImageDataset(dataImages1, times, Z_SIZE);
    UShortImage[] dataImages = imageDataSet.getAllImages();
    double[] timeStamps = imageDataSet.getImageTimeStamps();
    ImageTimeSeries<UShortImage> rawImageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, dataImages, timeStamps, 1);
    return rawImageTimeSeries;
}
Also used : ImageException(cbit.image.ImageException) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) SourceDataInfo(cbit.image.SourceDataInfo) DataOperationResults(cbit.vcell.simdata.DataOperationResults) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

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