Search in sources :

Example 41 with ImageDataset

use of cbit.vcell.VirtualMicroscopy.ImageDataset 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 42 with ImageDataset

use of cbit.vcell.VirtualMicroscopy.ImageDataset 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

ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)42 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)20 ROI (cbit.vcell.VirtualMicroscopy.ROI)9 Extent (org.vcell.util.Extent)9 File (java.io.File)8 Element (org.jdom.Element)8 ISize (org.vcell.util.ISize)8 Origin (org.vcell.util.Origin)7 CartesianMesh (cbit.vcell.solvers.CartesianMesh)6 UserCancelException (org.vcell.util.UserCancelException)6 ImageException (cbit.image.ImageException)5 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)5 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)5 Hashtable (java.util.Hashtable)5 Component (java.awt.Component)4 ArrayList (java.util.ArrayList)4 ImageTimeSeries (org.vcell.vmicro.workflow.data.ImageTimeSeries)4 VCImageUncompressed (cbit.image.VCImageUncompressed)3 AnnotatedImageDataset (cbit.vcell.VirtualMicroscopy.importer.AnnotatedImageDataset)3 MicroscopyXmlReader (cbit.vcell.VirtualMicroscopy.importer.MicroscopyXmlReader)3