use of ij.measure.Calibration in project GDSC-SMLM by aherbert.
the class PCPALMMolecules method displayImage.
static ImagePlus displayImage(String title, ImageProcessor ip, double nmPerPixel) {
ImagePlus imp = Utils.display(title, ip);
Calibration cal = new Calibration();
cal.setUnit("um");
cal.pixelWidth = cal.pixelHeight = nmPerPixel / 1000;
imp.setCalibration(cal);
return imp;
}
use of ij.measure.Calibration 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.measure.Calibration in project GDSC-SMLM by aherbert.
the class YeastMask method createMask.
private void createMask() {
// Create the dimensions
final int hw = (int) Math.ceil(radius * 1000 / nmPerPixel);
final int hd = (int) Math.ceil(radius * 1000 / nmPerSlice);
final int width = 2 * hw + 1;
final int depth = 2 * hd + 1;
ImageStack stack = createHemiSphere(width, depth);
// Extend the centre circle of the sphere into a tube of the required length
final int h = (int) Math.ceil(length * 1000 / nmPerPixel);
if (h > 0) {
ImageStack newStack = new ImageStack(width, stack.getHeight() + h, stack.getSize());
for (int slice = 1; slice <= stack.getSize(); slice++) {
byte[] pixels = (byte[]) stack.getPixels(slice);
byte[] newPixels = new byte[width * newStack.getHeight()];
newStack.setPixels(newPixels, slice);
System.arraycopy(pixels, 0, newPixels, 0, pixels.length);
// Get the final strip to be extended
final int offset = pixels.length - width;
int target = pixels.length;
for (int i = 0; i < h; i++) {
System.arraycopy(pixels, offset, newPixels, target, width);
target += width;
}
}
stack = newStack;
}
// Copy the hemi-sphere onto the end
ImageStack newStack = new ImageStack(width, stack.getHeight() + hw, stack.getSize());
for (int slice = 1; slice <= stack.getSize(); slice++) {
byte[] pixels = (byte[]) stack.getPixels(slice);
byte[] newPixels = new byte[width * newStack.getHeight()];
newStack.setPixels(newPixels, slice);
System.arraycopy(pixels, 0, newPixels, 0, pixels.length);
// Copy the hemi-sphere
int source = 0;
int target = newPixels.length - width;
for (int i = 0; i < hw; i++) {
System.arraycopy(pixels, source, newPixels, target, width);
target -= width;
source += width;
}
}
stack = newStack;
if (excludeNucleus) {
ImageStack stack2 = createNucleusSphere(width, depth);
int xloc = (stack.getWidth() - stack2.getWidth()) / 2;
int yloc = (stack.getHeight() - stack2.getHeight()) / 2;
int offset = (stack.getSize() - stack2.getSize()) / 2;
for (int slice = 1; slice <= stack2.getSize(); slice++) {
ImageProcessor ip = stack.getProcessor(slice + offset);
ImageProcessor ip2 = stack2.getProcessor(slice);
ip.copyBits(ip2, xloc, yloc, Blitter.SUBTRACT);
}
}
if (squareOutput && stack.getWidth() != stack.getHeight()) {
ImageStack stack2 = new ImageStack(stack.getHeight(), stack.getHeight());
int end = stack.getHeight() - stack.getWidth();
for (int slice = 1; slice <= stack.getSize(); slice++) {
ImageProcessor ip = stack.getProcessor(slice);
ImageProcessor ip2 = new ByteProcessor(stack2.getWidth(), stack2.getHeight());
stack2.addSlice(ip2);
for (int xloc = 0; xloc <= end; xloc += stack.getWidth()) {
ip2.insert(ip, xloc, 0);
}
}
stack = stack2;
}
if (border > 0) {
ImageStack stack2 = new ImageStack(stack.getWidth() + 2 * border, stack.getHeight() + 2 * border);
for (int slice = 1; slice <= stack.getSize(); slice++) {
ImageProcessor ip = stack.getProcessor(slice);
ImageProcessor ip2 = new ByteProcessor(stack2.getWidth(), stack2.getHeight());
stack2.addSlice(ip2);
ip2.insert(ip, border, border);
}
stack = stack2;
}
ImagePlus imp;
if (is2D) {
// TODO - Remove this laziness since we should really just do a 2D image
int centre = stack.getSize() / 2;
imp = Utils.display(TITLE, stack.getProcessor(centre));
} else {
imp = Utils.display(TITLE, stack);
}
// Calibrate
Calibration cal = new Calibration();
cal.setUnit("um");
cal.pixelWidth = cal.pixelHeight = nmPerPixel / 1000;
cal.pixelDepth = nmPerSlice / 1000;
imp.setCalibration(cal);
}
use of ij.measure.Calibration in project GDSC-SMLM by aherbert.
the class TraceMolecules method addZeroCrossingPoints.
private void addZeroCrossingPoints(ImagePlus imp) {
PolygonRoi roi = null;
imp.setRoi(roi);
if (zeroCrossingPoints == null || zeroCrossingPoints.isEmpty())
return;
Calibration cal = imp.getCalibration();
int nPoints = zeroCrossingPoints.size();
float[] xPoints = new float[nPoints];
float[] yPoints = new float[nPoints];
for (int i = 0; i < nPoints; i++) {
double[] point = zeroCrossingPoints.get(i);
// Convert to pixel coordinates.
xPoints[i] = (float) (cal.xOrigin + (point[0] / cal.pixelWidth));
yPoints[i] = (float) (cal.yOrigin + (point[1] / cal.pixelHeight));
}
roi = new PolygonRoi(xPoints, yPoints, nPoints, PolygonRoi.POLYLINE);
imp.setRoi(roi);
}
use of ij.measure.Calibration in project GDSC-SMLM by aherbert.
the class TraceMolecules method createPlotResults.
/**
* Build an image using the values within the results to set X,Y and value
*
* @param results
*/
private void createPlotResults(List<double[]> results) {
int w = 400, h = 400;
switch(settings.getOptimiserPlot()) {
case NONE:
return;
case BILINEAR:
fp = createBilinearPlot(results, w, h);
break;
default:
fp = createNNPlot(results, w, h);
}
// Create a calibration to map the pixel position back to distance/time
cal = new Calibration();
double xRange = getRange(settings.maxTimeThreshold, settings.minTimeThreshold, origX, w);
double yRange = getRange(settings.maxDistanceThreshold, settings.minDistanceThreshold, origY, h);
cal.pixelWidth = xRange / w;
cal.pixelHeight = yRange / h;
cal.xOrigin = origX - settings.minTimeThreshold / cal.pixelWidth;
cal.yOrigin = origY - settings.minDistanceThreshold / cal.pixelHeight;
cal.setXUnit("frame");
cal.setYUnit("pixel");
showPlot();
}
Aggregations