use of com.jmatio.types.MLDouble in project vcell by virtualcell.
the class FrapDataUtils method saveImageDatasetAsExternalMatlabData.
// export the frap data to matlab file. The matlab file contains timestamps(1*Tn) , mask(numImgX * numImgY),
// ImageDataSet(1*Tn) each cell of (1*Tn) point to a 2d image(numImgX * numImgY)
public static void saveImageDatasetAsExternalMatlabData(FRAPData frapData, LocalWorkspace localWorkspace, String matlabFileName, int startingIndexForRecovery, CartesianMesh cartesianMesh) throws IOException {
ImageDataset imageDataset = frapData.getImageDataset();
if (imageDataset.getSizeC() > 1) {
throw new RuntimeException("FRAPData.saveImageDatasetAsExternalMatlabData(): multiple channels not yet supported");
}
int numX = cartesianMesh.getSizeX();
int numY = cartesianMesh.getSizeY();
// prepare variable to write into matlab file, listOfVars is the outmost structure to write to Matlab file.
ArrayList<MLArray> listOfVars = new ArrayList<MLArray>();
double[] timeArray = imageDataset.getImageTimeStamps();
ROI cellROI = frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
short[] shortCellMask = cellROI.getPixelsXYZ();
// add image data set to Matlab cell, each cell points to a numX*numY array
MLCell imageCell = new MLCell("ImageDataSet", new int[] { timeArray.length, 1 });
for (int tIndex = 0; tIndex < imageDataset.getSizeT(); tIndex++) {
// images according to zIndex at specific time points(tIndex)
short[] originalData = imageDataset.getPixelsZ(0, tIndex);
double[] doubleImgData = new double[originalData.length];
for (int i = 0; i < originalData.length; i++) {
doubleImgData[i] = 0x0000ffff & originalData[i];
}
MLDouble mlDoublImgData = new MLDouble("ImageDataAtTime_" + tIndex, doubleImgData, numX);
imageCell.set(mlDoublImgData, tIndex, 0);
}
listOfVars.add(imageCell);
// create mask in a Matlab 2D double(numX*numY)
double[] doubleCellMask = new double[shortCellMask.length];
for (int i = 0; i < shortCellMask.length; i++) {
doubleCellMask[i] = 0x0000ffff & shortCellMask[i];
}
MLDouble cellMask = new MLDouble("CellMask", doubleCellMask, numX);
listOfVars.add(cellMask);
// create times in a Matlab 2D double(1*numTimePoints)
MLDouble times = new MLDouble("ExperimentalTimeStamps", new double[][] { timeArray });
listOfVars.add(times);
MatFileWriter writer = new MatFileWriter();
writer.write(matlabFileName, listOfVars);
}
Aggregations