Search in sources :

Example 61 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)

Example 62 with UShortImage

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

the class MicroscopyXmlReader method getROI.

/**
 * This method returns a Biomodel object from a XML Element.
 * Creation date: (3/13/2001 12:35:00 PM)
 * @param param org.jdom.Element
 * @return cbit.vcell.biomodel.BioModel
 * @throws XmlParseException
 */
private ROI getROI(Element param) throws XmlParseException {
    String roiName = param.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag);
    List<Element> ushortImageElementList = param.getChildren(MicroscopyXMLTags.UShortImageTag);
    Iterator<Element> imageElementIter = ushortImageElementList.iterator();
    UShortImage[] images = new UShortImage[ushortImageElementList.size()];
    int imageIndex = 0;
    while (imageElementIter.hasNext()) {
        images[imageIndex++] = getUShortImage(imageElementIter.next());
    }
    ROI roi = new ROI(images, roiName);
    return roi;
}
Also used : Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 63 with UShortImage

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

the class MicroscopyXmlReader method getImageDataset.

/**
 * This method returns a Biomodel object from a XML Element.
 * Creation date: (3/13/2001 12:35:00 PM)
 * @param param org.jdom.Element
 * @return cbit.vcell.biomodel.BioModel
 * @throws XmlParseException
 */
private ImageDataset getImageDataset(Element param, ClientTaskStatusSupport progressListener) throws XmlParseException {
    @SuppressWarnings("unchecked") List<Element> ushortImageElementList = param.getChildren(MicroscopyXMLTags.UShortImageTag);
    Iterator<Element> imageElementIter = ushortImageElementList.iterator();
    UShortImage[] images = new UShortImage[ushortImageElementList.size()];
    // added in Feb 2008, for counting loading progress
    int imageSize = ushortImageElementList.size();
    int imageCount = 0;
    while (imageElementIter.hasNext()) {
        images[imageCount++] = getUShortImage(imageElementIter.next());
        if (progressListener != null) {
            progressListener.setProgress((int) ((imageCount * 100.0) / imageSize));
        }
    }
    Element timeStampListElement = param.getChild(MicroscopyXMLTags.TimeStampListTag);
    double[] timestamps = null;
    if (timeStampListElement != null) {
        String timeStampListText = timeStampListElement.getTextTrim();
        StringTokenizer tokens = new StringTokenizer(timeStampListText, ",\n\r\t ", false);
        ArrayList<Double> times = new ArrayList<Double>();
        while (tokens.hasMoreTokens()) {
            String token = tokens.nextToken();
            times.add(Double.parseDouble(token));
        }
        timestamps = new double[times.size()];
        for (int i = 0; i < timestamps.length; i++) {
            timestamps[i] = times.get(i);
        }
    }
    int numTimeSteps = (timestamps != null) ? (timestamps.length) : (1);
    int numZ = images.length / numTimeSteps;
    ImageDataset imageDataset = new ImageDataset(images, timestamps, numZ);
    return imageDataset;
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) ArrayList(java.util.ArrayList) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) StringTokenizer(java.util.StringTokenizer) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer)

Example 64 with UShortImage

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

the class MicroscopyXmlReader method getUShortImage.

/**
 * This method returns a VCIMage object from a XML representation.
 * Creation date: (3/16/2001 3:41:24 PM)
 * @param param org.jdom.Element
 * @return VCImage
 * @throws XmlParseException
 */
private UShortImage getUShortImage(Element param) throws XmlParseException {
    // get the attributes
    Element tempelement = param.getChild(XMLTags.ImageDataTag);
    int aNumX = Integer.parseInt(tempelement.getAttributeValue(XMLTags.XAttrTag));
    int aNumY = Integer.parseInt(tempelement.getAttributeValue(XMLTags.YAttrTag));
    int aNumZ = Integer.parseInt(tempelement.getAttributeValue(XMLTags.ZAttrTag));
    int compressSize = Integer.parseInt(tempelement.getAttributeValue(XMLTags.CompressedSizeTag));
    final int BYTES_PER_SHORT = 2;
    int UNCOMPRESSED_SIZE_BYTES = aNumX * aNumY * aNumZ * BYTES_PER_SHORT;
    // getpixels
    String hexEncodedBytes = tempelement.getText();
    byte[] rawBytes = org.vcell.util.Hex.toBytes(hexEncodedBytes);
    ByteArrayInputStream rawByteArrayInputStream = new ByteArrayInputStream(rawBytes);
    InputStream rawInputStream = rawByteArrayInputStream;
    if (compressSize != UNCOMPRESSED_SIZE_BYTES) {
        rawInputStream = new InflaterInputStream(rawByteArrayInputStream);
    }
    byte[] shortsAsBytes = new byte[UNCOMPRESSED_SIZE_BYTES];
    int readCount = 0;
    try {
        while ((readCount += rawInputStream.read(shortsAsBytes, readCount, shortsAsBytes.length - readCount)) != shortsAsBytes.length) {
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new XmlParseException("error reading image pixels: ", e);
    } finally {
        if (rawInputStream != null) {
            try {
                rawInputStream.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
    ByteBuffer byteBuffer = ByteBuffer.wrap(shortsAsBytes);
    short[] shortPixels = new short[aNumX * aNumY * aNumZ];
    for (int i = 0; i < shortPixels.length; i++) {
        shortPixels[i] = byteBuffer.getShort();
    }
    Element extentElement = param.getChild(XMLTags.ExtentTag);
    Extent extent = null;
    if (extentElement != null) {
        extent = vcellXMLReader.getExtent(extentElement);
    }
    Element originElement = param.getChild(XMLTags.OriginTag);
    Origin origin = null;
    if (originElement != null) {
        origin = vcellXMLReader.getOrigin(originElement);
    }
    // //set attributes
    // String name = this.unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
    // String annotation = param.getChildText(XMLTags.AnnotationTag);
    UShortImage newimage;
    try {
        newimage = new UShortImage(shortPixels, origin, extent, aNumX, aNumY, aNumZ);
    } catch (ImageException e) {
        e.printStackTrace();
        throw new XmlParseException("error reading image", e);
    }
    return newimage;
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) XmlParseException(cbit.vcell.xml.XmlParseException) ByteBuffer(java.nio.ByteBuffer) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 65 with UShortImage

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

the class MicroscopyXmlReader method getROI.

/**
 * This method returns a Biomodel object from a XML Element.
 * Creation date: (3/13/2001 12:35:00 PM)
 * @param param org.jdom.Element
 * @return cbit.vcell.biomodel.BioModel
 * @throws XmlParseException
 */
private ROI getROI(Element param) throws XmlParseException {
    String roiName = param.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag);
    @SuppressWarnings("unchecked") List<Element> ushortImageElementList = param.getChildren(MicroscopyXMLTags.UShortImageTag);
    Iterator<Element> imageElementIter = ushortImageElementList.iterator();
    UShortImage[] images = new UShortImage[ushortImageElementList.size()];
    int imageIndex = 0;
    while (imageElementIter.hasNext()) {
        images[imageIndex++] = getUShortImage(imageElementIter.next());
    }
    ROI roi = new ROI(images, roiName);
    return roi;
}
Also used : ProfileDataElement(org.vcell.optimization.ProfileDataElement) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

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