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;
}
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;
}
Aggregations