use of ij.plugin.LutLoader in project GDSC-SMLM by aherbert.
the class DiffusionRateTest method showExample.
private void showExample(int totalSteps, double diffusionSigma, UniformRandomProvider rng) {
final MoleculeModel m = new MoleculeModel(0, new double[3]);
final float[] xValues = new float[totalSteps];
final float[] x = new float[totalSteps];
final float[] y = new float[totalSteps];
final DiffusionType diffusionType = CreateDataSettingsHelper.getDiffusionType(settings.getDiffusionType());
double[] axis;
if (diffusionType == DiffusionType.LINEAR_WALK) {
axis = nextVector(SamplerUtils.createNormalizedGaussianSampler(rng));
} else {
axis = null;
}
for (int j = 0; j < totalSteps; j++) {
if (diffusionType == DiffusionType.GRID_WALK) {
m.walk(diffusionSigma, rng);
} else if (diffusionType == DiffusionType.LINEAR_WALK) {
m.slide(diffusionSigma, axis, rng);
} else {
m.move(diffusionSigma, rng);
}
x[j] = (float) (m.getX());
y[j] = (float) (m.getY());
xValues[j] = (float) ((j + 1) / settings.getStepsPerSecond());
}
// Plot x and y coords on a timeline
final String title = TITLE + " example coordinates";
final Plot plot = new Plot(title, "Time (seconds)", "Distance (um)");
final float[] xUm = convertToUm(x);
final float[] yUm = convertToUm(y);
float[] limits = MathUtils.limits(xUm);
limits = MathUtils.limits(limits, yUm);
plot.setLimits(0, totalSteps / settings.getStepsPerSecond(), limits[0], limits[1]);
plot.setColor(Color.red);
plot.addPoints(xValues, xUm, Plot.LINE);
plot.setColor(Color.blue);
plot.addPoints(xValues, yUm, Plot.LINE);
ImageJUtils.display(title, plot);
// Scale up and draw 2D position
for (int j = 0; j < totalSteps; j++) {
x[j] *= pluginSettings.magnification;
y[j] *= pluginSettings.magnification;
}
final float[] limitsx = getLimits(x);
final float[] limitsy = getLimits(y);
int width = (int) (limitsx[1] - limitsx[0]);
int height = (int) (limitsy[1] - limitsy[0]);
// Ensure we draw something, even it is a simple dot at the centre for no diffusion
if (width == 0) {
width = (int) (32 * pluginSettings.magnification);
limitsx[0] = -width / 2.0f;
}
if (height == 0) {
height = (int) (32 * pluginSettings.magnification);
limitsy[0] = -height / 2.0f;
}
final ImageProcessor ip = new ByteProcessor(width, height);
// Adjust x and y using the minimum to centre
x[0] -= limitsx[0];
y[0] -= limitsy[0];
for (int j = 1; j < totalSteps; j++) {
// Adjust x and y using the minimum to centre
x[j] -= limitsx[0];
y[j] -= limitsy[0];
// Draw a line
ip.setColor(32 + (223 * j) / (totalSteps - 1));
ip.drawLine(round(x[j - 1]), round(y[j - 1]), round(x[j]), round(y[j]));
}
// Draw the final position
ip.putPixel(round(x[totalSteps - 1]), round(y[totalSteps - 1]), 255);
final ImagePlus imp = ImageJUtils.display(TITLE + " example", ip);
// Apply the fire lookup table
WindowManager.setTempCurrentImage(imp);
final LutLoader lut = new LutLoader();
lut.run("fire");
WindowManager.setTempCurrentImage(null);
}
use of ij.plugin.LutLoader in project GDSC-SMLM by aherbert.
the class IJImagePeakResults method begin.
/*
* (non-Javadoc)
*
* @see gdsc.utils.fitting.PeakResults#begin()
*/
public void begin() {
imageActive = false;
preBegin();
// Handle invalid bounds with an empty single pixel image
boolean validBounds = imageWidth > 0 && imageHeight > 0 && (double) imageWidth * (double) imageHeight < Integer.MAX_VALUE;
int w, h;
if (validBounds) {
w = imageWidth;
h = imageHeight;
} else {
Utils.log("ERROR: Unable to create image results '%s' due to invalid dimensions: width=%d, height=%d", title, imageWidth, imageHeight);
w = h = 1;
}
size = 0;
lastPaintSize = 0;
// Let some results appear before drawing
nextRepaintSize = 20;
nextPaintTime = System.currentTimeMillis() + repaintDelay;
imageLock = false;
data = new double[w * h];
// Use negative zero so that we know when positive zero has been written to the array.
if ((displayFlags & (DISPLAY_MAPPED | DISPLAY_MAP_ZERO)) == (DISPLAY_MAPPED | DISPLAY_MAP_ZERO))
EMPTY = -0.0f;
resetData();
imp = WindowManager.getImage(title);
currentFrame = 1;
ImageProcessor ip = createNewProcessor(w, h);
if (imp == null) {
imp = new ImagePlus(title, ip);
// Apply the fire lookup table
WindowManager.setTempCurrentImage(imp);
LutLoader lut = new LutLoader();
lut.run(lutName);
WindowManager.setTempCurrentImage(null);
if (displayImage)
imp.show();
} else {
// Copy the lookup table
ip.setColorModel(imp.getProcessor().getColorModel());
ImageStack stack = createNewImageStack(w, h);
stack.addSlice(null, ip);
// If resizing then remove adornments
if (stack.getWidth() != imp.getWidth() || stack.getHeight() != imp.getHeight()) {
imp.setOverlay(null);
imp.setRoi((Roi) null);
}
imp.setStack(stack);
if (displayImage)
imp.show();
else
imp.hide();
}
imp.setProperty("Info", createInfo());
if (calibration != null) {
Calibration cal = new Calibration();
String unit = "nm";
double unitPerPixel = calibration.getNmPerPixel() / scale;
if (unitPerPixel > 100) {
unit = "um";
unitPerPixel /= 1000.0;
}
cal.setUnit(unit);
cal.pixelHeight = cal.pixelWidth = unitPerPixel;
imp.setCalibration(cal);
}
// We cannot draw anything with no bounds
imageActive = validBounds;
}
use of ij.plugin.LutLoader in project GDSC-SMLM by aherbert.
the class DiffusionRateTest method showExample.
private void showExample(int totalSteps, double diffusionSigma, RandomGenerator[] random) {
MoleculeModel m = new MoleculeModel(0, new double[3]);
float[] xValues = new float[totalSteps];
float[] x = new float[totalSteps];
float[] y = new float[totalSteps];
final double[] axis = (settings.getDiffusionType() == DiffusionType.LINEAR_WALK) ? nextVector() : null;
for (int j = 0; j < totalSteps; j++) {
if (settings.getDiffusionType() == DiffusionType.GRID_WALK)
m.walk(diffusionSigma, random);
else if (settings.getDiffusionType() == DiffusionType.LINEAR_WALK)
m.slide(diffusionSigma, axis, random[0]);
else
m.move(diffusionSigma, random);
x[j] = (float) (m.getX());
y[j] = (float) (m.getY());
xValues[j] = (float) ((j + 1) / settings.stepsPerSecond);
}
// Plot x and y coords on a timeline
String title = TITLE + " example coordinates";
Plot2 plot = new Plot2(title, "Time (seconds)", "Distance (um)");
float[] xUm = convertToUm(x);
float[] yUm = convertToUm(y);
float[] limits = Maths.limits(xUm);
limits = Maths.limits(limits, yUm);
plot.setLimits(0, totalSteps / settings.stepsPerSecond, limits[0], limits[1]);
plot.setColor(Color.red);
plot.addPoints(xValues, xUm, Plot2.LINE);
plot.setColor(Color.blue);
plot.addPoints(xValues, yUm, Plot2.LINE);
Utils.display(title, plot);
// Scale up and draw 2D position
for (int j = 0; j < totalSteps; j++) {
x[j] *= magnification;
y[j] *= magnification;
}
float[] limitsx = getLimits(x);
float[] limitsy = getLimits(y);
int width = (int) (limitsx[1] - limitsx[0]);
int height = (int) (limitsy[1] - limitsy[0]);
// Ensure we draw something, even it is a simple dot at the centre for no diffusion
if (width == 0) {
width = (int) (32 * magnification);
limitsx[0] = -width / 2;
}
if (height == 0) {
height = (int) (32 * magnification);
limitsy[0] = -height / 2;
}
ImageProcessor ip = new ByteProcessor(width, height);
// Adjust x and y using the minimum to centre
x[0] -= limitsx[0];
y[0] -= limitsy[0];
for (int j = 1; j < totalSteps; j++) {
// Adjust x and y using the minimum to centre
x[j] -= limitsx[0];
y[j] -= limitsy[0];
// Draw a line
ip.setColor(32 + (223 * j) / (totalSteps - 1));
ip.drawLine(round(x[j - 1]), round(y[j - 1]), round(x[j]), round(y[j]));
}
// Draw the final position
ip.putPixel((int) round(x[totalSteps - 1]), (int) round(y[totalSteps - 1]), 255);
ImagePlus imp = Utils.display(TITLE + " example", ip);
// Apply the fire lookup table
WindowManager.setTempCurrentImage(imp);
LutLoader lut = new LutLoader();
lut.run("fire");
WindowManager.setTempCurrentImage(null);
}
use of ij.plugin.LutLoader in project GDSC-SMLM by aherbert.
the class TraceMolecules method showPlot.
/**
* Shows the plot
*/
private void showPlot() {
if (settings.getOptimiserPlot() == OptimiserPlot.NONE)
return;
// Display the image
String title = TITLE + ": | N - N_actual | / N_actual";
ImagePlus imp = WindowManager.getImage(title);
if (imp != null) {
fp.setColorModel(imp.getProcessor().getColorModel());
imp.setProcessor(fp);
} else {
imp = new ImagePlus(title, fp);
imp.show();
WindowManager.setTempCurrentImage(imp);
LutLoader lut = new LutLoader();
lut.run("fire");
WindowManager.setTempCurrentImage(null);
}
imp.setCalibration(cal);
addZeroCrossingPoints(imp);
imp.updateAndDraw();
}
use of ij.plugin.LutLoader in project GDSC-SMLM by aherbert.
the class TraceMolecules method showPlot.
/**
* Shows the plot.
*/
private void showPlot() {
if (OptimiserPlot.get(settings.getOptimiserPlot()) == OptimiserPlot.NONE) {
return;
}
// Display the image
final String title = pluginTitle + ": | N - N_actual | / N_actual";
ImagePlus imp = WindowManager.getImage(title);
if (imp != null) {
fp.setColorModel(imp.getProcessor().getColorModel());
imp.setProcessor(fp);
} else {
imp = new ImagePlus(title, fp);
imp.show();
WindowManager.setTempCurrentImage(imp);
final LutLoader lut = new LutLoader();
lut.run("fire");
WindowManager.setTempCurrentImage(null);
}
imp.setCalibration(cal);
addZeroCrossingPoints(imp);
imp.updateAndDraw();
}
Aggregations