Search in sources :

Example 31 with ImageDataset

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

the class NonGUIFRAPTest method runSolver.

/**
 * @param args
 */
public static void runSolver(String[] args) throws Exception {
    String startingIndexForRecovery = args[0];
    String freeDiffusionRateStr = args[1];
    String freeMobileFractionStr = args[2];
    String complexDiffusionRateStr = args[3];
    String complexMobileFractionStr = args[4];
    String bleachWhileMonitoringRateString = args[5];
    String immobileFractionStr = args[6];
    String bindingSiteConcentrationStr = args[7];
    String reacOnRateStr = args[8];
    String reacOffRateStr = args[9];
    String workingDirectoryPath = args[10];
    String inputFRAPDataFileName = args[11];
    String inputCellROIFileName = args[12];
    String inputBleachROIFileName = args[13];
    String inputBackgroundROIFileName = args[14];
    String outputXMLFileName = args[15];
    String commaSepTimeStamps = args[16];
    String commaSepExtentXYZ = args[17];
    LocalWorkspace localWorkspace = new LocalWorkspace(new File(workingDirectoryPath));
    ExternalDataFileContents extDataFileContents = readExternalDataContents(inputFRAPDataFileName, inputCellROIFileName, inputBleachROIFileName, inputBackgroundROIFileName);
    ROI cellROI = new ROI(extDataFileContents.cellROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
    ROI bleachROI = new ROI(extDataFileContents.bleachROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
    ROI backgroundROI = new ROI(extDataFileContents.backgroundROIData.getImage(0, 0, 0), FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
    // Insert Time information
    double[] timeStamps = new double[extDataFileContents.imageData.getAllImages().length];
    StringTokenizer commaStringTokenizer = new StringTokenizer(commaSepTimeStamps, ",");
    int timeCount = 0;
    while (commaStringTokenizer.hasMoreTokens()) {
        timeStamps[timeCount] = Double.parseDouble(commaStringTokenizer.nextToken());
        timeCount++;
    }
    ImageDataset frapDataImageDataSet = new ImageDataset(extDataFileContents.imageData.getAllImages(), timeStamps, 1);
    // Insert Extent information
    commaStringTokenizer = new StringTokenizer(commaSepExtentXYZ, ",");
    Extent extent = new Extent(Double.parseDouble(commaStringTokenizer.nextToken()), Double.parseDouble(commaStringTokenizer.nextToken()), Double.parseDouble(commaStringTokenizer.nextToken()));
    frapDataImageDataSet.setExtent(extent);
    bleachROI.getRoiImages()[0].setExtent(extent);
    cellROI.getRoiImages()[0].setExtent(extent);
    backgroundROI.getRoiImages()[0].setExtent(extent);
    FRAPData frapData = FrapDataUtils.importFRAPDataFromImageDataSet(frapDataImageDataSet);
    frapData.addReplaceRoi(bleachROI);
    frapData.addReplaceRoi(cellROI);
    frapData.addReplaceRoi(backgroundROI);
    FRAPStudy frapStudy = new FRAPStudy();
    frapStudy.setFrapData(frapData);
    // old model parameters, need to rewrite
    // FRAPStudy.FRAPModelParameters frapModelParameters = new FRAPStudy.FRAPModelParameters(
    // new FRAPStudy.InitialModelParameters(freeDiffusionRateStr, freeMobileFractionStr, bleachWhileMonitoringRateString, startingIndexForRecovery),
    // null,
    // null);
    // frapStudy.setFrapModelParameters(frapModelParameters);
    frapStudy.refreshDependentROIs();
    ExternalDataInfo imageDatasetExternalDataInfo = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME);
    ExternalDataInfo roiExternalDataInfo = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME);
    frapStudy.setFrapDataExternalDataInfo(imageDatasetExternalDataInfo);
    frapStudy.setRoiExternalDataInfo(roiExternalDataInfo);
    frapStudy.saveImageDatasetAsExternalData(localWorkspace, frapStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
    frapStudy.saveROIsAsExternalData(localWorkspace, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), frapStudy.getStartingIndexForRecovery());
    // Double bleachWhileMonitoringRate =
    // (!bleachWhileMonitoringRateString.equals("-")
    // ?Double.parseDouble(bleachWhileMonitoringRateString)
    // :null);
    double fd, ff, bwmr, cd, cf, imf, bs, on, off;
    try {
        fd = Double.parseDouble(freeDiffusionRateStr);
        ff = Double.parseDouble(freeMobileFractionStr);
        bwmr = Double.parseDouble(bleachWhileMonitoringRateString);
        cd = Double.parseDouble(complexDiffusionRateStr);
        cf = Double.parseDouble(complexMobileFractionStr);
        imf = Double.parseDouble(immobileFractionStr);
        bs = Double.parseDouble(bindingSiteConcentrationStr);
        on = Double.parseDouble(reacOnRateStr);
        off = Double.parseDouble(reacOffRateStr);
    } catch (NumberFormatException e) {
        throw new Exception("Input parameters are not all valid. Check if they are empty or in illegal forms.");
    }
    BioModel bioModel = FRAPStudy.createNewSimBioModel(frapStudy, createParameterArray(fd, ff, bwmr, cd, cf, imf, bs, on, off), null, LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), new Integer(frapStudy.getStartingIndexForRecovery()));
    frapStudy.setBioModel(bioModel);
    // no progress listener, need to change
    MicroscopyXmlproducer.writeXMLFile(frapStudy, new File(outputXMLFileName), true, null, false);
    FRAPStudy.runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), bioModel.getSimulation(0), imageDatasetExternalDataInfo.getExternalDataIdentifier(), roiExternalDataInfo.getExternalDataIdentifier(), null);
    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(bioModel.getSimulations()[0].getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
    PDEDataManager simulationDataManager = new PDEDataManager(null, localWorkspace.getVCDataManager(), vcSimulationDataIdentifier);
    double[] frapDataTimeStamps = frapData.getImageDataset().getImageTimeStamps();
    VCDataManager testVCDataManager = localWorkspace.getVCDataManager();
    double[] prebleachAverage = testVCDataManager.getSimDataBlock(null, frapStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), "prebleach_avg", 0).getData();
    // TODO: need to create parameters here.
    Parameter[] parameters = null;
    SpatialAnalysisResults spatialAnalysisResults = FRAPStudy.spatialAnalysis(simulationDataManager, new Integer(frapStudy.getStartingIndexForRecovery()), frapDataTimeStamps[new Integer(frapStudy.getStartingIndexForRecovery())], parameters, frapData, prebleachAverage);
    dumpSummaryReport(spatialAnalysisResults, frapDataTimeStamps, new Integer(startingIndexForRecovery).intValue(), new File(workingDirectoryPath, "nonguiSpatialResults.txt"));
    dumpSpatialResults(spatialAnalysisResults, frapDataTimeStamps, new File(workingDirectoryPath, "nonguiSpatialResults.txt"));
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) ROI(cbit.vcell.VirtualMicroscopy.ROI) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) StringTokenizer(java.util.StringTokenizer) PDEDataManager(cbit.vcell.simdata.PDEDataManager) BioModel(cbit.vcell.biomodel.BioModel) Parameter(cbit.vcell.opt.Parameter) File(java.io.File) VCDataManager(cbit.vcell.simdata.VCDataManager)

Example 32 with ImageDataset

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

the class NonGUIFRAPTest method runXMLFile.

public static void runXMLFile(String xmlFileName, String testDirectoryPath) throws Exception {
    String xmlString = XmlUtil.getXMLString(xmlFileName);
    // System.out.println(xmlString);
    MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
    FRAPStudy frapStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
    if (frapStudy == null || frapStudy.getFrapData() == null) {
        throw new Exception("no FrapData in file " + xmlFileName);
    }
    if (frapStudy.getFrapData().getImageDataset().getSizeC() != 1 || frapStudy.getFrapData().getImageDataset().getSizeZ() != 1) {
        throw new Exception("Only single channel, single z test implemented");
    }
    File imageDataSetZipFile = getCanonicalFilename(testDirectoryPath, null);
    File cellROIFile = getCanonicalFilename(testDirectoryPath, FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
    File bleachROIFile = getCanonicalFilename(testDirectoryPath, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
    File backgroundROIFile = getCanonicalFilename(testDirectoryPath, FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
    FileOutputStream fos = new FileOutputStream(imageDataSetZipFile);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    ZipOutputStream zos = new ZipOutputStream(bos);
    ImageDataset imageDataset = frapStudy.getFrapData().getImageDataset();
    System.out.println(imageDataset.getISize());
    StringBuffer timeStampsSB = new StringBuffer();
    for (int i = 0; i < imageDataset.getSizeT(); i++) {
        // ZipEntry zipEntry = new ZipEntry((i<10?"00":(i<100?"0":""))+i+".bmp");
        ZipEntry zipEntry = new ZipEntry((i < 10 ? "00" : (i < 100 ? "0" : "")) + i + ".tif");
        zos.putNextEntry(zipEntry);
        UShortImage timePointImage = imageDataset.getImage(0, 0, i);
        File tempF = writeTempTiff(timePointImage.getPixels(), timePointImage.getNumX(), timePointImage.getNumY());
        FileInputStream fis = new FileInputStream(tempF);
        byte[] tempbytes = new byte[(int) tempF.length()];
        int offset = 0;
        while ((offset += fis.read(tempbytes, offset, tempbytes.length - offset)) != tempbytes.length) {
        }
        zos.write(tempbytes);
        // writeUShortFile(timePointImage, zos);
        timeStampsSB.append((i != 0 ? "," : "") + imageDataset.getImageTimeStamps()[i]);
        zos.closeEntry();
        fis.close();
        tempF.delete();
    }
    zos.close();
    fos.close();
    // fos = new FileOutputStream(cellROIFile);
    ROI cellROI = frapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
    File cellTempF = writeTempTiff(cellROI.getRoiImages()[0].getPixels(), cellROI.getRoiImages()[0].getNumX(), cellROI.getRoiImages()[0].getNumY());
    FileUtils.copyFile(cellTempF, cellROIFile);
    cellTempF.delete();
    // writeUShortFile(cellROI.getRoiImages()[0], fos);
    // fos.close();
    // fos = new FileOutputStream(bleachROIFile);
    ROI bleachROI = frapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
    File bleachTempf = writeTempTiff(bleachROI.getRoiImages()[0].getPixels(), bleachROI.getRoiImages()[0].getNumX(), bleachROI.getRoiImages()[0].getNumY());
    FileUtils.copyFile(bleachTempf, bleachROIFile);
    bleachTempf.delete();
    // writeUShortFile(bleachROI.getRoiImages()[0],fos);
    // fos.close();
    // fos = new FileOutputStream(backgroundROIFile);
    ROI backgroundROI = frapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
    File backgroundTempf = writeTempTiff(backgroundROI.getRoiImages()[0].getPixels(), backgroundROI.getRoiImages()[0].getNumX(), backgroundROI.getRoiImages()[0].getNumY());
    FileUtils.copyFile(backgroundTempf, backgroundROIFile);
    backgroundTempf.delete();
    // writeUShortFile(backgroundROI.getRoiImages()[0],fos);
    // fos.close();
    checkExternalDataSameAsOriginal(frapStudy, testDirectoryPath);
    // if(true){System.exit(0);}
    String[] args = new String[] { // frapStudy.getFrapModelParameters().getPureDiffModelParameters().secondaryMobileFraction,
    testDirectoryPath, imageDataSetZipFile.getAbsolutePath(), cellROIFile.getAbsolutePath(), bleachROIFile.getAbsolutePath(), backgroundROIFile.getAbsolutePath(), new File(testDirectoryPath, "testCreated.xml").getAbsolutePath(), timeStampsSB.toString(), imageDataset.getExtent().getX() + "," + imageDataset.getExtent().getY() + "," + imageDataset.getExtent().getZ() };
    NonGUIFRAPTest.runSolver(args);
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) ZipEntry(java.util.zip.ZipEntry) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI) FileInputStream(java.io.FileInputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 33 with ImageDataset

use of cbit.vcell.VirtualMicroscopy.ImageDataset 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);
}
Also used : MLDouble(com.jmatio.types.MLDouble) MLArray(com.jmatio.types.MLArray) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) MLCell(com.jmatio.types.MLCell) ArrayList(java.util.ArrayList) ROI(cbit.vcell.VirtualMicroscopy.ROI) MatFileWriter(com.jmatio.io.MatFileWriter)

Example 34 with ImageDataset

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

the class FrapDataUtils method saveROIsAsExternalData.

public static void saveROIsAsExternalData(FRAPData frapData, LocalWorkspace localWorkspace, ExternalDataIdentifier newROIExtDataID, int startingIndexForRecovery, CartesianMesh cartesianMesh) throws ObjectNotFoundException, FileNotFoundException {
    ImageDataset imageDataset = frapData.getImageDataset();
    Extent extent = imageDataset.getExtent();
    ISize isize = imageDataset.getISize();
    int NumTimePoints = 1;
    // actually it is total number of ROIs(cell,bleached + 8 rings)+prebleach+firstPostBleach+lastPostBleach
    int NumChannels = 13;
    // dimensions: time points, channels, whole image ordered by z slices.
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    double[] temp_background = frapData.getAvgBackGroundIntensity();
    double[] avgPrebleachDouble = calculatePreBleachAverageXYZ(frapData, startingIndexForRecovery);
    // average of prebleach with background subtracted
    pixData[0][0] = avgPrebleachDouble;
    // first post-bleach with background subtracted
    pixData[0][1] = createDoubleArray(imageDataset.getPixelsZ(0, startingIndexForRecovery), temp_background[startingIndexForRecovery], true);
    // adjustPrebleachAndPostbleachData(avgPrebleachDouble, pixData[0][1]);
    // last post-bleach image (at last time point) with background subtracted
    pixData[0][2] = createDoubleArray(imageDataset.getPixelsZ(0, imageDataset.getSizeT() - 1), temp_background[imageDataset.getSizeT() - 1], true);
    // below are ROIs, we don't need to subtract background for them.
    pixData[0][3] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getBinaryPixelsXYZ(1), 0, false);
    pixData[0][4] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getBinaryPixelsXYZ(1), 0, false);
    if (frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name()) == null) {
        // throw new RuntimeException("must first generate \"derived masks\"");
        pixData[0][5] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][6] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][7] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][8] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][9] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][10] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][11] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][12] = new double[imageDataset.getISize().getXYZ()];
    } else {
        pixData[0][5] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][6] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING2.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][7] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING3.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][8] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING4.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][9] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING5.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][10] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING6.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][11] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING7.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][12] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING8.name()).getBinaryPixelsXYZ(1), 0, false);
    }
    Origin origin = new Origin(0, 0, 0);
    FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
    fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
    fdos.cartesianMesh = cartesianMesh;
    fdos.doubleSpecData = pixData;
    fdos.specEDI = newROIExtDataID;
    fdos.varNames = new String[] { "prebleach_avg", "postbleach_first", "postbleach_last", "bleached_mask", "cell_mask", "ring1_mask", "ring2_mask", "ring3_mask", "ring4_mask", "ring5_mask", "ring6_mask", "ring7_mask", "ring8_mask" };
    fdos.owner = LocalWorkspace.getDefaultOwner();
    fdos.times = new double[] { 0.0 };
    fdos.variableTypes = new VariableType[] { VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME };
    fdos.origin = origin;
    fdos.extent = extent;
    fdos.isize = isize;
    localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
Also used : Origin(org.vcell.util.Origin) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec)

Example 35 with ImageDataset

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

the class FrapDataUtils method createFrapData.

public static FRAPData createFrapData(ArrayList<SourceDataInfo> sourceDataInfoArr, double[] times, int slice, Double maxIntensity, ClientTaskStatusSupport progressListener) throws ImageException {
    if (sourceDataInfoArr.size() != times.length) {
        throw new ImageException("Error FRAPData.createFrapData: times array length must equal SourceDataInfo vector size");
    }
    // construct
    int XY_SIZE = sourceDataInfoArr.get(0).getXSize() * sourceDataInfoArr.get(0).getYSize();
    int SLICE_OFFSET = slice * 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 (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]);
                }
            }
        }
        linearScaleFactor = maxIntensity.doubleValue() / maxDataValue;
    }
    // saving each time step 2D double array to a UShortImage
    UShortImage[] dataImages = new UShortImage[times.length];
    for (int i = 0; i < times.length; i++) {
        double[] doubleData = (double[]) sourceDataInfoArr.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);
        }
        dataImages[i] = new UShortImage(shortData, sourceDataInfoArr.get(i).getOrigin(), sourceDataInfoArr.get(i).getExtent(), sourceDataInfoArr.get(i).getXSize(), sourceDataInfoArr.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(dataImages, times, Z_SIZE);
    FRAPData frapData = new FRAPData(imageDataSet, new String[] { FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name(), FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name(), FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name() });
    return frapData;
}
Also used : ImageException(cbit.image.ImageException) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) FRAPData(cbit.vcell.microscopy.FRAPData) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

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