Search in sources :

Example 66 with UShortImage

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

the class MicroscopyXmlproducer method getXML.

/**
 * This method returns a XML representation for a Biomodel object.
 * Creation date: (2/14/2001 3:41:13 PM)
 * @param param cbit.vcell.biomodel.BioModel
 * @return Element
 * @throws XmlParseException
 * @throws cbit.vcell.parser.ExpressionException
 */
public static Element getXML(ImageDataset param, Xmlproducer vcellXMLProducer, ClientTaskStatusSupport progressListener, boolean bSaveCompressed) throws XmlParseException, cbit.vcell.parser.ExpressionException {
    Element imageDatasetNode = new Element(MicroscopyXMLTags.ImageDatasetTag);
    // Get ImageDataset
    UShortImage[] images = param.getAllImages();
    // added in Feb 2008, for counting saving progress
    int imageSize = images.length;
    int imageCount = 0;
    for (int i = 0; i < images.length; i++) {
        imageDatasetNode.addContent(getXML(images[i], vcellXMLProducer, bSaveCompressed));
        imageCount++;
        // suppose image data set takes 95% and roi takes 5% of total progress.
        if (progressListener != null) {
            progressListener.setProgress(((int) ((imageCount * 95) / (double) imageSize)));
        }
    }
    if (param.getImageTimeStamps() != null) {
        Element timeStampListNode = new Element(MicroscopyXMLTags.TimeStampListTag);
        double[] timeStamps = param.getImageTimeStamps();
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append(timeStamps[0]);
        for (int i = 1; i < timeStamps.length; i++) {
            stringBuilder.append(",");
            stringBuilder.append(timeStamps[i]);
        }
        timeStampListNode.addContent(stringBuilder.toString());
        imageDatasetNode.addContent(timeStampListNode);
    }
    return imageDatasetNode;
}
Also used : ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 67 with UShortImage

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

the class MicroscopyXmlproducer method getXML.

/**
 * This method returns a XML representation for a Biomodel object.
 * Creation date: (2/14/2001 3:41:13 PM)
 * @param param cbit.vcell.biomodel.BioModel
 * @return Element
 * @throws XmlParseException
 * @throws cbit.vcell.parser.ExpressionException
 */
private static Element getXML(ROI param, Xmlproducer vcellXMLProducer, boolean bSaveCompressed) throws XmlParseException, cbit.vcell.parser.ExpressionException {
    Element roiNode = new Element(MicroscopyXMLTags.ROITag);
    UShortImage[] images = param.getRoiImages();
    for (int i = 0; i < images.length; i++) {
        roiNode.addContent(getXML(param.getRoiImages()[i], vcellXMLProducer, bSaveCompressed));
    }
    roiNode.setAttribute(MicroscopyXMLTags.ROITypeAttrTag, param.getROIName());
    return roiNode;
}
Also used : ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 68 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage 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 69 with UShortImage

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

Example 70 with UShortImage

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

the class AnnotatedImageDataset method verifyROIdimensions.

/**
 * Method verifyROIdimensions.
 * @param argImageDataset ImageDataset
 * @param argROIs ArrayList<ROI>
 */
private void verifyROIdimensions(ImageDataset argImageDataset, ArrayList<ROI> argROIs) {
    if (rois != null) {
        int imgNumX = argImageDataset.getImage(0, 0, 0).getNumX();
        int imgNumY = argImageDataset.getImage(0, 0, 0).getNumY();
        int imgNumZ = argImageDataset.getSizeZ();
        for (int i = 0; i < argROIs.size(); i++) {
            UShortImage firstROIImage = argROIs.get(i).getRoiImages()[0];
            int roiNumX = firstROIImage.getNumX();
            int roiNumY = firstROIImage.getNumY();
            int roiNumZ = argROIs.get(i).getRoiImages().length;
            if (roiNumX != imgNumX || roiNumY != imgNumY || roiNumZ != imgNumZ) {
                throw new RuntimeException("ROI size (" + roiNumX + "," + roiNumY + "," + roiNumZ + ") doesn't match image size (" + imgNumX + "," + imgNumY + "," + imgNumZ + ")");
            }
        }
    }
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

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