use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class FRAPData method fastDilate.
private UShortImage fastDilate(UShortImage dilateSource, int radius, UShortImage mask) throws ImageException {
short[] sourcePixels = dilateSource.getPixels();
short[] targetPixels = dilateSource.getPixels().clone();
KernelJAI dilateKernel = createCircularBinaryKernel(radius);
float[] kernelData = dilateKernel.getKernelData();
BitSet kernelBitSet = new BitSet(kernelData.length);
for (int i = 0; i < kernelData.length; i++) {
if (kernelData[i] == 1.0f) {
kernelBitSet.set(i);
}
}
boolean bNeedsFill = false;
for (int y = 0; y < dilateSource.getNumY(); y++) {
int yOffset = y * dilateSource.getNumX();
int yMinus = yOffset - dilateSource.getNumX();
int yPlus = yOffset + dilateSource.getNumX();
for (int x = 0; x < dilateSource.getNumX(); x++) {
bNeedsFill = false;
if (sourcePixels[x + yOffset] != 0) {
if (x - 1 >= 0 && sourcePixels[(x - 1) + yOffset] == 0) {
bNeedsFill = true;
} else if (y - 1 >= 0 && sourcePixels[x + yMinus] == 0) {
bNeedsFill = true;
} else if (x + 1 < dilateSource.getNumX() && sourcePixels[(x + 1) + yOffset] == 0) {
bNeedsFill = true;
} else if (y + 1 < dilateSource.getNumY() && sourcePixels[x + yPlus] == 0) {
bNeedsFill = true;
}
if (bNeedsFill) {
int masterKernelIndex = 0;
for (int y2 = y - radius; y2 <= y + radius; y2++) {
if (y2 >= 0 && y2 < dilateSource.getNumY()) {
int kernelIndex = masterKernelIndex;
int targetYIndex = y2 * dilateSource.getNumX();
for (int x2 = x - radius; x2 <= x + radius; x2++) {
if (kernelBitSet.get(kernelIndex) && x2 >= 0 && x2 < dilateSource.getNumX()) {
targetPixels[targetYIndex + x2] = 1;
}
kernelIndex++;
}
}
masterKernelIndex += dilateKernel.getWidth();
}
}
}
}
}
UShortImage resultImage = new UShortImage(targetPixels, dilateSource.getOrigin(), dilateSource.getExtent(), dilateSource.getNumX(), dilateSource.getNumY(), dilateSource.getNumZ());
resultImage.and(mask);
return resultImage;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class FRAPData method fixROIConstraints.
/**
* must be consistent with checkBleachROIViolatesConstraints() and checkBackgroundROIViolatesConstraints()
* @return
* @throws Exception
*/
public boolean fixROIConstraints() throws Exception {
short[] cellPixels = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getPixelsXYZ();
short[] bleachPixels = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getPixelsXYZ();
short[] backgroundPixels = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()).getPixelsXYZ();
boolean bFixedBleach = false;
boolean bFixedBackground = false;
for (int i = 0; i < cellPixels.length; i++) {
if (cellPixels[i] == 0 && bleachPixels[i] != 0) {
bFixedBleach = true;
bleachPixels[i] = 0;
}
if (cellPixels[i] != 0 && backgroundPixels[i] != 0) {
bFixedBackground = true;
backgroundPixels[i] = 0;
}
}
if (bFixedBackground || bFixedBleach) {
if (bFixedBleach) {
UShortImage ushortImage = new UShortImage(bleachPixels, getCurrentlyDisplayedROI().getRoiImages()[0].getOrigin(), getCurrentlyDisplayedROI().getRoiImages()[0].getExtent(), getCurrentlyDisplayedROI().getISize().getX(), getCurrentlyDisplayedROI().getISize().getY(), getCurrentlyDisplayedROI().getISize().getZ());
ROI newBleachROI = new ROI(ushortImage, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
addReplaceRoi(newBleachROI);
}
if (bFixedBackground) {
UShortImage ushortImage = new UShortImage(backgroundPixels, getCurrentlyDisplayedROI().getRoiImages()[0].getOrigin(), getCurrentlyDisplayedROI().getRoiImages()[0].getExtent(), getCurrentlyDisplayedROI().getISize().getX(), getCurrentlyDisplayedROI().getISize().getY(), getCurrentlyDisplayedROI().getISize().getZ());
ROI newBackgroundROI = new ROI(ushortImage, FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
addReplaceRoi(newBackgroundROI);
}
return true;
} else // nothing to fix
{
return true;
}
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class FluorescenceNoiseTest method generateTestData.
private ImageTimeSeries<UShortImage> generateTestData(Origin origin, Extent extent, int numX, int numY, int numParticles, double diffusionRate, double psfVar, double bleachRadius, boolean bNoise, boolean bConvolve) throws ImageException {
double detectorGainAndQuantumYeild = 100;
double totalSampleTime = 0.5;
int numSampleSteps = 1;
int numPrebleach = 2;
ArrayList<UShortImage> images = new ArrayList<UShortImage>();
ArrayList<Double> times = new ArrayList<Double>();
final BrownianDynamics2DSolver solver = new BrownianDynamics2DSolver(origin, extent, numParticles);
boolean initiallyFluorescent = true;
solver.initializeUniform(initiallyFluorescent);
// simulate and write prebleach images
for (int i = 0; i < numPrebleach; i++) {
images.add(solver.sampleImage(numX, numY, origin, extent, diffusionRate, totalSampleTime, numSampleSteps, psfVar, detectorGainAndQuantumYeild, bConvolve, bNoise));
times.add(solver.currentTime());
}
// bleach
double totalBleachTime = 0.1;
int numBleachSteps = 5;
double bleachCenterX = origin.getX() + 0.5 * extent.getX();
double bleachCenterY = origin.getY() + 0.5 * extent.getY();
double bleachPsfVariance = bleachRadius;
double bleachFactor_K = 10;
solver.bleachGuassian(diffusionRate, totalBleachTime, numBleachSteps, bleachCenterX, bleachCenterY, bleachPsfVariance, bleachFactor_K);
// wait
double postbleachDelay = 0.1;
solver.step(diffusionRate, postbleachDelay);
while (solver.currentTime() < 5) {
double samplePsfVariance = psfVar;
images.add(solver.sampleImage(numX, numY, origin, extent, diffusionRate, totalSampleTime, numSampleSteps, psfVar, detectorGainAndQuantumYeild, bConvolve, bNoise));
times.add(solver.currentTime());
// solver.step(diffusionRate, 1-totalSampleTime);
}
double[] timeArray = new double[times.size()];
for (int i = 0; i < timeArray.length; i++) {
timeArray[i] = times.get(i);
}
UShortImage[] imageArray = images.toArray(new UShortImage[images.size()]);
return new ImageTimeSeries<UShortImage>(UShortImage.class, imageArray, timeArray, 1);
}
use of cbit.vcell.VirtualMicroscopy.UShortImage 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 cbit.vcell.VirtualMicroscopy.UShortImage 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);
}
}
Aggregations