use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class GenerateNormalizedFrapDataOp method generate.
public NormalizedFrapDataResults generate(ImageTimeSeries<UShortImage> rawImageTimeSeries, ROI backgroundROI_2D, Integer indexPostbleach) throws Exception {
UShortImage firstImage = rawImageTimeSeries.getAllImages()[0];
ISize isize = firstImage.getISize();
int nX = isize.getX();
int nY = isize.getY();
int nZ = isize.getZ();
int numTimes = rawImageTimeSeries.getSizeT();
Extent extent = firstImage.getExtent();
org.vcell.util.Origin origin = firstImage.getOrigin();
if (indexPostbleach == 0) {
throw new RuntimeException("no prebleach images found - indexOfFirstPostbleach is 0");
}
//
// find average "dark count" in background of pre-bleach images (for background subtraction)
//
float avgBackground = 0.0f;
int numPrebleach = indexPostbleach;
for (int i = 0; i < numPrebleach; i++) {
avgBackground += getAverage(rawImageTimeSeries.getAllImages()[i], backgroundROI_2D);
}
avgBackground /= numPrebleach;
//
// find averaged prebleach image (corrected for background).
//
int numPostbleachImages = numTimes - numPrebleach;
// holds new averaged image pixels
float[] prebleachAveragePixels = new float[nX * nY * nZ];
for (int i = 0; i < numPrebleach; i++) {
short[] currPrebleachImage = rawImageTimeSeries.getAllImages()[i].getPixels();
for (int j = 0; j < isize.getXYZ(); j++) {
float intPixel = 0x0000ffff & ((int) currPrebleachImage[j]);
prebleachAveragePixels[j] += intPixel / numPrebleach;
}
}
FloatImage prebleachAverageImage = new FloatImage(prebleachAveragePixels, origin, extent, nX, nY, nZ);
//
// create normalized dataset
//
// normalized postbleach = (origPostbleach - background)/(prebleach - background)
//
FloatImage[] normalizedImages = new FloatImage[numPostbleachImages];
double[] postbleachTimeStamps = new double[numPostbleachImages];
for (int i = 0; i < numPostbleachImages; i++) {
double[] origTimeStamps = rawImageTimeSeries.getImageTimeStamps();
postbleachTimeStamps[i] = origTimeStamps[indexPostbleach + i] - origTimeStamps[indexPostbleach];
float[] normalizedPixels = new float[isize.getXYZ()];
normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
short[] uncorrectedPixels = rawImageTimeSeries.getAllImages()[i + indexPostbleach].getPixels();
for (int j = 0; j < isize.getXYZ(); j++) {
int intPixel = 0x0000ffff & ((int) uncorrectedPixels[j]);
normalizedPixels[j] = (intPixel - avgBackground) / (Math.max(1, prebleachAveragePixels[j] - avgBackground));
}
normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
}
ImageTimeSeries<FloatImage> normalizedData = new ImageTimeSeries<FloatImage>(FloatImage.class, normalizedImages, postbleachTimeStamps, nZ);
NormalizedFrapDataResults results = new NormalizedFrapDataResults();
results.normalizedFrapData = normalizedData;
results.prebleachAverage = prebleachAverageImage;
return results;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class ImportImageROIsFrom2DVCellOp method importROIs.
public ImageROIs importROIs(File vcellSimLogFile, String bleachedMaskVarName, String cellSubvolumeName, String ecSubvolumeName) throws Exception {
VCSimulationIdentifier vcSimulationIdentifier = VCellSimReader.getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
DataSetControllerImpl dataSetControllerImpl = VCellSimReader.getDataSetControllerImplFromVCellSimulationData(vcellSimLogFile);
CartesianMesh cartesianMesh = dataSetControllerImpl.getMesh(vcSimulationDataIdentifier);
// get rois from log file
if (bleachedMaskVarName == null) {
throw new RuntimeException("bleachedMathVarName not set");
}
double[] rawROIBleached = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, bleachedMaskVarName, 0).getData();
short[] scaledCellDataShort = new short[rawROIBleached.length];
short[] scaledBleachedDataShort = new short[rawROIBleached.length];
short[] scaledBackgoundDataShort = new short[rawROIBleached.length];
for (int j = 0; j < scaledCellDataShort.length; j++) {
boolean isCell = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals(cellSubvolumeName);
boolean isBackground = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals(ecSubvolumeName);
if (isCell) {
scaledCellDataShort[j] = 1;
}
if (isBackground) {
scaledBackgoundDataShort[j] = 1;
}
if (rawROIBleached[j] > 0.2) {
scaledBleachedDataShort[j] = 1;
}
}
UShortImage cellImage = new UShortImage(scaledCellDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
UShortImage bleachedImage = new UShortImage(scaledBleachedDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
ROI cellROI = new ROI(cellImage, "cellROI");
ROI bleachedROI = new ROI(bleachedImage, "bleachedROI");
ROI backgroundROI = new ROI(backgroundImage, "backgroundROI");
ImageROIs imageRois = new ImageROIs();
imageRois.cellROI_2D = cellROI;
imageRois.bleachedROI_2D = bleachedROI;
imageRois.backgroundROI_2D = backgroundROI;
return imageRois;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class ImportRawTimeSeriesFrom2DVCellConcentrationsOp method importRawTimeSeries.
private static ImageDataset importRawTimeSeries(File vcellSimLogFile, String fluorFunctionName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
VCSimulationIdentifier vcSimulationIdentifier = VCellSimReader.getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
DataSetControllerImpl dataSetControllerImpl = VCellSimReader.getDataSetControllerImplFromVCellSimulationData(vcellSimLogFile);
final DataJobEvent[] bStatus = new DataJobEvent[] { null };
DataJobListener dataJobListener = new DataJobListener() {
public void dataJobMessage(DataJobEvent event) {
bStatus[0] = event;
if (progressListener != null) {
progressListener.setProgress((int) (event.getProgress() / 100.0 * .75));
}
}
};
dataSetControllerImpl.addDataJobListener(dataJobListener);
DataIdentifier[] dataIdentifiers = VCellSimReader.getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
DataIdentifier variableNameDataIdentifier = null;
for (int i = 0; i < dataIdentifiers.length; i++) {
if (dataIdentifiers[i].getName().equals(fluorFunctionName)) {
variableNameDataIdentifier = dataIdentifiers[i];
break;
}
}
if (variableNameDataIdentifier == null) {
throw new IllegalArgumentException("Variable " + fluorFunctionName + " not found.");
}
if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
throw new IllegalArgumentException("Variable " + fluorFunctionName + " is not VOLUME type.");
}
double[] times = dataSetControllerImpl.getDataSetTimes(vcSimulationDataIdentifier);
CartesianMesh cartesianMesh = dataSetControllerImpl.getMesh(vcSimulationDataIdentifier);
BitSet allBitset = new BitSet(cartesianMesh.getNumVolumeElements());
allBitset.set(0, cartesianMesh.getNumVolumeElements() - 1);
TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { fluorFunctionName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(VCellSimReader.getDotUser(), true));
TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) dataSetControllerImpl.getTimeSeriesValues(null, vcSimulationDataIdentifier, timeSeriesJobSpec);
// wait for job to finish
while (bStatus[0] == null || bStatus[0].getEventTypeID() != DataJobEvent.DATA_COMPLETE) {
Thread.sleep(100);
}
double allTimesMin = tsJobResultsSpaceStats.getMinimums()[0][0];
double allTimesMax = allTimesMin;
for (int i = 0; i < times.length; i++) {
allTimesMin = Math.min(allTimesMin, tsJobResultsSpaceStats.getMinimums()[0][i]);
allTimesMax = Math.max(allTimesMax, tsJobResultsSpaceStats.getMaximums()[0][i]);
}
// double SCALE_MAX = maxIntensity.doubleValue();/*Math.pow(2,16)-1;*///Scale to 16 bits
double linearScaleFactor = 1;
if (maxIntensity != null) {
linearScaleFactor = maxIntensity.doubleValue() / allTimesMax;
}
System.out.println("alltimesMin=" + allTimesMin + " allTimesMax=" + allTimesMax + " linearScaleFactor=" + linearScaleFactor);
UShortImage[] scaledDataImages = new UShortImage[times.length];
Random rnd = new Random();
int shortMax = 65535;
// set messge to load variable
if (progressListener != null) {
progressListener.setMessage("Loading variable " + fluorFunctionName + "...");
}
for (int i = 0; i < times.length; i++) {
double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, fluorFunctionName, times[i]).getData();
short[] scaledDataShort = new short[rawData.length];
for (int j = 0; j < scaledDataShort.length; j++) {
double scaledRawDataJ = rawData[j] * linearScaleFactor;
if (bNoise) {
double ran = rnd.nextGaussian();
double scaledRawDataJ_withNoise = Math.max(0, (scaledRawDataJ + ran * Math.sqrt(scaledRawDataJ)));
scaledRawDataJ_withNoise = Math.min(shortMax, scaledRawDataJ_withNoise);
int scaledValue = (int) (scaledRawDataJ_withNoise);
scaledDataShort[j] &= 0x0000;
scaledDataShort[j] |= 0x0000FFFF & scaledValue;
} else {
int scaledValue = (int) (scaledRawDataJ);
scaledDataShort[j] &= 0x0000;
scaledDataShort[j] |= 0x0000FFFF & scaledValue;
}
}
scaledDataImages[i] = new UShortImage(scaledDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
if (progressListener != null) {
int progress = (int) (((i + 1) * 1.0 / times.length) * 100);
progressListener.setProgress(progress);
}
}
ImageDataset rawImageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
return rawImageDataSet;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class ImportRawTimeSeriesFrom2DVCellConcentrationsOp method importRawTimeSeries.
public ImageTimeSeries<UShortImage> importRawTimeSeries(File vcellSimLogFile, String fluorFunctionName, double maxIntensity, boolean bNoise) throws Exception {
ClientTaskStatusSupport clientTaskStatusSupport = null;
ImageDataset timeRawData = importRawTimeSeries(vcellSimLogFile, fluorFunctionName, maxIntensity, bNoise, clientTaskStatusSupport);
ImageTimeSeries<UShortImage> imageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, timeRawData.getAllImages(), timeRawData.getImageTimeStamps(), 1);
return imageTimeSeries;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class ImportRawTimeSeriesFromExperimentImagesOp method importRawTimeSeries.
public ImageTimeSeries<UShortImage> importRawTimeSeries(File[] expTimeSeriesFiles, double timeInterval) throws Exception {
boolean isTimeSeries = true;
ClientTaskStatusSupport clientTaskStatusSupport = null;
ImageDataset rawTimeData = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDatasetFromMultiFiles(expTimeSeriesFiles, clientTaskStatusSupport, isTimeSeries, timeInterval);
ImageTimeSeries<UShortImage> imageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, rawTimeData.getAllImages(), rawTimeData.getImageTimeStamps(), 1);
return imageTimeSeries;
}
Aggregations