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 + ")");
}
}
}
}
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;
}
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;
}
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;
}
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;
}
Aggregations