use of org.vcell.util.Extent in project vcell by virtualcell.
the class FluorescenceNoiseTest method doit.
private void doit() throws ImageException {
int[] sizes = new int[] { 1, 2, 4, 8, 16, 32, 64, 128, 256 };
for (int imageSize : sizes) {
ISize size = new ISize(imageSize, imageSize, 1);
Extent extent = new Extent(1, 1, 1);
Origin origin = new Origin(0, 0, 0);
// NormalizedSampleFunction sampleFunction = NormalizedSampleFunction.createUniform("uniformROI", origin, extent, size);
NormalizedSampleFunction sampleFunction = NormalizedSampleFunction.fromGaussian("testGaussian", origin, extent, size, 0.5, 0.2, 0.1);
SampleStatistics[] samples = new SampleStatistics[NUM_TRIALS];
for (int i = 0; i < NUM_TRIALS; i++) {
UShortImage rawImage = getUniformFluorescenceImage(size, extent, origin, MEAN_INTENSITY);
samples[i] = sampleFunction.sample(rawImage);
}
Mean mean = new Mean();
Variance var = new Variance();
double[] weightedMeans = getWeightedMeans(samples);
double[] weightedVariances = getWeightedVariances(samples);
double weightedMeansVariance = var.evaluate(weightedMeans);
double weightedMeansMean = mean.evaluate(weightedMeans);
double weightedVarVariance = var.evaluate(weightedVariances);
double weightedVarMean = mean.evaluate(weightedVariances);
double V1 = samples[0].sumOfWeights;
double V2 = samples[0].sumOfWeightsSquared;
System.out.println("image is " + imageSize + "x" + imageSize + ", V1=" + V1 + ", V2=" + V2 + ", numTrials=" + NUM_TRIALS + ", sample means (mu=" + weightedMeansMean + ",s=" + weightedMeansVariance + "), sample variances (mu=" + weightedVarMean + ",s=" + weightedVarVariance);
}
}
use of org.vcell.util.Extent in project vcell by virtualcell.
the class FluorescenceNoiseTest method testImageTimeSeries.
private void testImageTimeSeries(boolean bNoise, boolean bConvolve) throws ImageException, IOException {
Origin origin = new Origin(0, 0, 0);
Extent extent = new Extent(10, 10, 1);
int numX = 30;
int numY = 30;
// typically 10000 or 100000;
int numParticles = 40000;
double diffusionRate = 1;
double bleachRadius = 5 * 5;
double psfVar = 0.6 * 0.6;
ImageTimeSeries<UShortImage> rawTimeSeries = generateTestData(origin, extent, numX, numY, numParticles, diffusionRate, psfVar, bleachRadius, bNoise, bConvolve);
new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeries, "time series", null);
}
use of org.vcell.util.Extent 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;
}
Aggregations