use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class ImportRawTimeSeriesFromVFrap method compute0.
@Override
protected void compute0(TaskContext context, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
// get input
File vfrap_file = context.getData(vfrapFile);
// do op
ImportRawTimeSeriesFromVFrapOp op = new ImportRawTimeSeriesFromVFrapOp();
ImageTimeSeries<UShortImage> imageTimeSeries = op.importRawTimeSeriesFromVFrap(vfrap_file);
// set output
context.setData(rawTimeSeriesImages, imageTimeSeries);
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class RunRefSimulationFast method compute0.
@Override
protected void compute0(TaskContext context, final ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
ImageTimeSeries<FloatImage> normTimeSeries = context.getData(normalizedTimeSeries);
ROI cellROI = context.getData(cellROI_2D);
ROI[] imageDataRois = context.getData(imageDataROIs);
UShortImage psf = context.getData(this.psf);
// do op
RunRefSimulationFastOp op = new RunRefSimulationFastOp();
RowColumnResultSet reducedData = op.runRefSimFast(cellROI, normTimeSeries, imageDataRois, psf, context.getLocalWorkspace(), clientTaskStatusSupport);
// set output
context.setData(reducedROIData, reducedData);
// always D = 1,
context.setData(refSimDiffusionRate, op.getReferenceDiffusionCoef());
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class BrownianDynamics2DSolver method sampleImage.
public UShortImage sampleImage(int numX, int numY, Origin origin, Extent extent, double diffusion, double integrationTime, int numSteps, double psfVar, double detectorGainAndQuantumYeild, boolean bConvolve, boolean bNoise) throws ImageException {
double deltaT = integrationTime / (numSteps);
//
// sample the x and y coordinates for the structured grid (pixel coordinates). .. coordinates will be used lots of times (let's precompute).
//
double[] imageX = new double[numX];
double[] imageY = new double[numY];
for (int i = 0; i < numX; i++) {
imageX[i] = origin.getX() + (0.5 + i) * extent.getX() / numX;
}
for (int j = 0; j < numY; j++) {
imageY[j] = origin.getY() + (0.5 + j) * extent.getY() / numY;
}
// apply point spread function to gather poisson rates from all particles to all pixels.
// then we roll the dice to sample from poission later.
double[] particleImage = new double[numX * numY];
Arrays.fill(particleImage, 0);
for (int step = 0; step < numSteps; step++) {
if (bConvolve) {
//
// convolve all particles with normalized psf (each particle integrates to one over neighboring pixels) for each pixel and accumulate in lambda array
// (lambda is not reset so we can repeat and integrate over time)
//
System.out.println("convolving particles, step=" + step + ", time=" + currTime);
addConvolved(numX, numY, psfVar, imageX, imageY, particleImage);
} else {
//
// count particles in each pixel
//
System.out.println("binning particles, step=" + step + ", time=" + currTime);
addBinned(numX, numY, origin.getX(), origin.getY(), extent.getX(), extent.getY(), particleImage);
}
//
// let diffusion happen during sampling
//
System.out.println("simulating particles, step=" + step + ", time=" + currTime);
step(diffusion, deltaT);
}
//
// generate sample image by generating fluorescence intensity
// need to rescale to consider detector gain and expected number of photons from each particle. (ignore detector noise)
//
float[] pixels = new float[particleImage.length];
double totalGain = detectorGainAndQuantumYeild * integrationTime / numSteps;
for (int i = 0; i < pixels.length; i++) {
float rate = (float) (particleImage[i] * totalGain);
if (rate > 1e-5) {
if (bNoise) {
pixels[i] = new PoissonDistribution(imagingRng, rate, PoissonDistribution.DEFAULT_EPSILON, PoissonDistribution.DEFAULT_MAX_ITERATIONS).sample();
} else {
pixels[i] = rate;
}
}
}
//
// create unsigned short sample image
//
short[] ushortPixels = new short[pixels.length];
for (int i = 0; i < ushortPixels.length; i++) {
if (pixels[i] > 32767) {
throw new RuntimeException("pixel overflow of signed short, value = " + pixels[i]);
}
if (pixels[i] < 0) {
throw new RuntimeException("unexpected negative pixel, value = " + pixels[i]);
}
ushortPixels[i] = (short) (0xffff & (int) pixels[i]);
}
UShortImage sampledImage = new UShortImage(ushortPixels, origin, extent, numX, numY, 1);
return sampledImage;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class GenerateNormalizedPhotoactivationDataOp method generate.
public NormalizedPhotoactivationDataResults generate(ImageTimeSeries<UShortImage> rawImageTimeSeries, ROI backgroundROI_2D, Integer indexPostactivation, boolean backgroundSubtract, boolean normalizedByPreactivation) throws Exception {
UShortImage preactivationImage = rawImageTimeSeries.getAllImages()[0];
ISize isize = preactivationImage.getISize();
int nX = isize.getX();
int nY = isize.getY();
int nZ = isize.getZ();
int numTimes = rawImageTimeSeries.getSizeT();
Extent extent = preactivationImage.getExtent();
org.vcell.util.Origin origin = preactivationImage.getOrigin();
if (indexPostactivation == 0) {
throw new RuntimeException("no preactivation images found - indexOfFirstPostactivation is 0");
}
//
// find average "dark count" in background of pre-activation images (for background subtraction)
//
float avgBackground = 0.0f;
int numPreactivation = indexPostactivation;
for (int i = 0; i < numPreactivation; i++) {
avgBackground += getAverage(rawImageTimeSeries.getAllImages()[i], backgroundROI_2D);
}
avgBackground /= numPreactivation;
//
// find averaged preactivation image (corrected for background).
//
int numPostactivationImages = numTimes - numPreactivation;
// holds new averaged image pixels
float[] preactivationAveragePixels = new float[nX * nY * nZ];
for (int i = 0; i < numPreactivation; i++) {
short[] currPreactivationImage = rawImageTimeSeries.getAllImages()[i].getPixels();
for (int j = 0; j < isize.getXYZ(); j++) {
float intPixel = 0x0000ffff & ((int) currPreactivationImage[j]);
preactivationAveragePixels[j] += intPixel / numPreactivation;
}
}
FloatImage preactivationAverageImage = new FloatImage(preactivationAveragePixels, origin, extent, nX, nY, nZ);
UShortImage firstPostactivationImage = rawImageTimeSeries.getAllImages()[indexPostactivation];
//
// create normalized dataset
//
// normalized postbleach = (origPostbleach - background)/(prebleach - background)
//
FloatImage[] normalizedImages = new FloatImage[numPostactivationImages];
double[] postactivationTimeStamps = new double[numPostactivationImages];
for (int i = 0; i < numPostactivationImages; i++) {
double[] origTimeStamps = rawImageTimeSeries.getImageTimeStamps();
postactivationTimeStamps[i] = origTimeStamps[indexPostactivation + i] - origTimeStamps[indexPostactivation];
float[] normalizedPixels = new float[isize.getXYZ()];
normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
short[] uncorrectedPixels = rawImageTimeSeries.getAllImages()[i + indexPostactivation].getPixels();
for (int j = 0; j < isize.getXYZ(); j++) {
int intUncorrectedPixel = 0x0000ffff & ((int) uncorrectedPixels[j]);
float background = 0;
if (backgroundSubtract) {
background = avgBackground;
}
if (normalizedByPreactivation) {
int intPreactivationAvgPixel = 0x0000ffff & ((int) preactivationAveragePixels[j]);
normalizedPixels[j] = (intUncorrectedPixel - background) / (Math.max(1, intPreactivationAvgPixel - background));
} else {
normalizedPixels[j] = (intUncorrectedPixel - background);
}
}
normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
}
ImageTimeSeries<FloatImage> normalizedData = new ImageTimeSeries<FloatImage>(FloatImage.class, normalizedImages, postactivationTimeStamps, nZ);
NormalizedPhotoactivationDataResults results = new NormalizedPhotoactivationDataResults();
results.normalizedPhotoactivationData = normalizedData;
results.preactivationAverageImage = preactivationAverageImage;
results.normalizedPostactivationImage = normalizedData.getAllImages()[0];
return results;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class GenerateTrivial2DPsfOp method generateTrivial2D_Psf.
public UShortImage generateTrivial2D_Psf() {
// psf image is now expecting a 3x3 image that are all zeros with a 1 in the middle (Kronecker delta)
short[] pixels = new short[] { 0, 0, 0, 0, 1, 0, 0, 0, 0 };
Origin origin = new Origin(0, 0, 0);
Extent extent = new Extent(1, 1, 1);
ISize isize = new ISize(3, 3, 1);
UShortImage psfImage;
try {
psfImage = new UShortImage(pixels, origin, extent, isize.getX(), isize.getY(), isize.getZ());
} catch (ImageException e) {
e.printStackTrace();
throw new RuntimeException("unexpected image exception: " + e.getMessage(), e);
}
return psfImage;
}
Aggregations