use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class GenerateBleachRoiOp method generateBleachRoi.
public ROI generateBleachRoi(Image firstPostbleach, ROI cellROI_2D, Double bleachThreshold) throws ImageException {
int numPixels = firstPostbleach.getNumXYZ();
short[] scaledBleachedDataShort = new short[numPixels];
short[] erodedCellUShort = cellROI_2D.getRoiImages()[0].getBinaryPixels(1);
// input is already normalized to 1.0 ... if relative to max, then crazy values from outside cell can interfere.
double bleachThresholdValue = bleachThreshold;
double[] firstPostbleachImage = firstPostbleach.getDoublePixels();
for (int j = 0; j < numPixels; j++) {
boolean isCell = (erodedCellUShort[j] == 1);
boolean isBleach = firstPostbleachImage[j] < bleachThresholdValue;
if (isCell && isBleach) {
scaledBleachedDataShort[j] = 1;
}
}
UShortImage bleachedImage = new UShortImage(scaledBleachedDataShort, firstPostbleach.getOrigin(), firstPostbleach.getExtent(), firstPostbleach.getNumX(), firstPostbleach.getNumY(), firstPostbleach.getNumZ());
ROI bleachedROI = new ROI(bleachedImage, "bleachedROI");
return bleachedROI;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class GenerateCellROIsFromRawPhotoactivationTimeSeriesOp method generate.
public GeometryRoisAndActivationTiming generate(ImageTimeSeries rawTimeSeriesImages, double cellThreshold) throws Exception {
Image[] allImages = rawTimeSeriesImages.getAllImages();
int numPixels = allImages[0].getNumXYZ();
int numTimes = allImages.length;
ImageStatistics[] imageStats = new ImageStatistics[numTimes];
for (int i = 0; i < numTimes; i++) {
imageStats[i] = allImages[i].getImageStatistics();
}
//
// find largest change in fluorescence (ratio of total[n+1]/total[n]
//
int indexPostactivation = -1;
double largestRatio = 0.0;
for (int tIndex = 0; tIndex < numTimes - 1; tIndex++) {
double currentRatio = imageStats[tIndex + 1].meanValue / imageStats[tIndex].meanValue;
if (currentRatio > largestRatio) {
largestRatio = currentRatio;
indexPostactivation = tIndex + 1;
}
}
double[] firstImagePixels = allImages[0].getDoublePixels();
short[] scaledCellDataShort = new short[numPixels];
short[] scaledBackgoundDataShort = new short[numPixels];
short[] wholeDomainDataShort = new short[numPixels];
//
// find cell and background by thresholding the first image
//
double cellThresholdValue = cellThreshold * imageStats[0].maxValue;
for (int j = 0; j < numPixels; j++) {
boolean isCell = firstImagePixels[j] > cellThresholdValue;
if (isCell) {
scaledCellDataShort[j] = 1;
} else {
scaledBackgoundDataShort[j] = 1;
}
}
UShortImage cellImage = new UShortImage(scaledCellDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
Arrays.fill(wholeDomainDataShort, (short) 1);
UShortImage wholeDomainImage = new UShortImage(wholeDomainDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
UShortImage reverseCell = UShortImage.fastDilate(cellImage, 10, wholeDomainImage);
reverseCell.reverse();
reverseCell.and(backgroundImage);
backgroundImage = reverseCell;
cellImage = new UShortImage(backgroundImage);
cellImage.reverse();
ROI cellROI = new ROI(cellImage, "cellROI");
ROI backgroundROI = new ROI(backgroundImage, "backgroundROI");
GeometryRoisAndActivationTiming results = new GeometryRoisAndActivationTiming();
results.cellROI_2D = cellROI;
results.backgroundROI_2D = backgroundROI;
results.indexOfFirstPostactivation = indexPostactivation;
return results;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class ImportRawTimeSeriesFromExperimentImageOp method importRawTimeSeries.
public ImageTimeSeries<UShortImage> importRawTimeSeries(File expTimeSeriesFile) throws Exception {
ClientTaskStatusSupport clientTaskStatusSupport = null;
ImageDataset rawTimeData = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDataset(expTimeSeriesFile.getAbsolutePath(), clientTaskStatusSupport);
ImageTimeSeries<UShortImage> imageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, rawTimeData.getAllImages(), rawTimeData.getImageTimeStamps(), 1);
return imageTimeSeries;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class BioformatsImageDatasetReader method getImageDataset.
private ImageDataset getImageDataset(org.vcell.imagedataset.ImageDataset t_imageDataset) throws ImageException {
List<org.vcell.imagedataset.UShortImage> t_images = t_imageDataset.getImages();
UShortImage[] images = new UShortImage[t_images.size()];
for (int i = 0; i < t_images.size(); i++) {
org.vcell.imagedataset.UShortImage t_image = t_images.get(i);
short[] pixels = new short[t_image.getPixels().size()];
for (int p = 0; p < t_image.getPixelsSize(); p++) {
pixels[p] = t_image.getPixels().get(p);
}
Origin origin = new Origin(t_image.getOrigin().x, t_image.getOrigin().y, t_image.getOrigin().z);
Extent extent = new Extent(t_image.getExtent().x, t_image.getExtent().y, t_image.getExtent().z);
int numX = t_image.getSize().x;
int numY = t_image.getSize().y;
int numZ = t_image.getSize().z;
UShortImage image = new UShortImage(pixels, origin, extent, numX, numY, numZ);
images[i] = image;
}
;
List<Double> t_imageTimeStamps = t_imageDataset.getImageTimeStamps();
double[] timestamps = new double[t_imageTimeStamps.size()];
for (int t = 0; t < t_imageTimeStamps.size(); t++) {
timestamps[t] = t_imageTimeStamps.get(t);
}
ImageDataset imageDataset = new ImageDataset(images, timestamps, t_imageDataset.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;
}
Aggregations