use of ij.gui.Plot in project GDSC-SMLM by aherbert.
the class PSFCreator method subtractBackgroundAndWindow.
/**
* Subtract the background from the spot, compute the intensity within half the box region distance from the centre
* and smooth the intensity profile. In interactive mode the user must choose to accept the profile or reject.
* If accepted the smoothed profile is user to normalise the image and then the image is rolled off to zero
* using a Tukey window function.
*
* @param spot
* @param background
* The minimum level, all below this is background and set to zero
* @param spotWidth
* @param spotHeight
* @param n
* The spot number
* @param loess
* The smoothing interpolator
* @return True if accepted
*/
private boolean subtractBackgroundAndWindow(float[][] spot, final float background, final int spotWidth, final int spotHeight, double[] centre, LoessInterpolator loess) {
//ImageWindow imageWindow = new ImageWindow();
for (int i = 0; i < spot.length; i++) {
for (int j = 0; j < spot[i].length; j++) spot[i][j] = FastMath.max(spot[i][j] - background, 0);
}
// Create a distance map from the centre
if (lastWidth != spotWidth || lastHeight != spotHeight) {
final double cx = spotWidth * 0.5;
final double cy = spotHeight * 0.5;
minx = FastMath.max(0, (int) (cx - boxRadius * 0.5));
maxx = FastMath.min(spotWidth, (int) Math.ceil(cx + boxRadius * 0.5));
miny = FastMath.max(0, (int) (cy - boxRadius * 0.5));
maxy = FastMath.min(spotHeight, (int) Math.ceil(cy + boxRadius * 0.5));
// Precompute square distances
double[] dx2 = new double[maxx - minx + 1];
for (int x = minx, i = 0; x < maxx; x++, i++) {
// Use pixel centres with 0.5 offset
final double dx = x + 0.5 - cx;
dx2[i] = dx * dx;
}
dmap = new boolean[dx2.length * (maxy - miny + 1)];
final double d2 = boxRadius * boxRadius / 4;
for (int y = miny, j = 0; y < maxy; y++) {
final double dy = (y + 0.5 - cy);
final double dy2 = dy * dy;
final double limit = d2 - dy2;
for (int x = minx, i = 0; x < maxx; x++, i++, j++) {
dmap[j] = (dx2[i] < limit);
}
}
lastWidth = spotWidth;
lastHeight = spotHeight;
}
// Calculate the intensity profile within half the box radius from the centre
double[] xValues = new double[spot.length];
double[] yValues = new double[spot.length];
for (int i = 0; i < spot.length; i++) {
xValues[i] = i + 1;
double sum = 0;
for (int y = miny, j = 0; y < maxy; y++) {
int index = y * spotWidth + minx;
for (int x = minx; x < maxx; x++, index++, j++) if (dmap[j])
sum += spot[i][index];
}
yValues[i] = sum;
}
double[] newY = loess.smooth(xValues, yValues);
// falls towards zero at the ends)
for (int i = 0; i < newY.length; i++) if (newY[i] < 0)
newY[i] = yValues[i];
if (interactiveMode) {
Utils.hide(TITLE_AMPLITUDE);
Utils.hide(TITLE_PSF_PARAMETERS);
final int n = (int) centre[4];
String title = TITLE_INTENSITY;
Plot plot = new Plot(title, "Slice", "Sum", xValues, yValues);
plot.setColor(Color.red);
plot.addPoints(xValues, newY, Plot.LINE);
plot.setColor(Color.green);
double[] limits = Maths.limits(yValues);
plot.drawLine(centre[2], limits[0], centre[2], limits[1]);
plot.setColor(Color.black);
plot.addLabel(0, 0, "Spot " + n);
Utils.display(title, plot);
GenericDialog gd = new GenericDialog(TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.addMessage(String.format("Add spot %d to the PSF?\n(The intensity profile is the sum within half the box region)", n));
if (yesNoPosition != null) {
gd.centerDialog(false);
gd.setLocation(yesNoPosition);
}
gd.showDialog();
yesNoPosition = gd.getLocation();
if (!gd.wasOKed())
return false;
}
for (int i = 0; i < spot.length; i++) {
// Normalise
final float scale = (float) (newY[i] / yValues[i]);
for (int j = 0; j < spot[i].length; j++) spot[i][j] *= scale;
// Use a Tukey window to roll-off the image edges
//spot[i] = imageWindow.applySeperable(spot[i], spotWidth, spotHeight, ImageWindow.WindowFunction.Tukey);
spot[i] = ImageWindow.applyWindow(spot[i], spotWidth, spotHeight, ImageWindow.WindowFunction.TUKEY);
}
return true;
}
use of ij.gui.Plot in project vcell by virtualcell.
the class PlotCellRegionStats method run.
@Override
public void run() {
Plot plot = new ColorPlot("Cell region mean intensity", "Time", "Mean intensity");
StringBuilder legendLabels = new StringBuilder();
for (int i = 0; i < datasets.size(); i++) {
RandomAccessibleInterval<T> data = datasets.get(i);
if (data instanceof Dataset) {
legendLabels.append(((Dataset) data).getName());
legendLabels.append(": ");
}
RandomAccessibleInterval<T> cropped = ops.transform().crop(data, mask);
displayService.createDisplay(cropped);
}
}
Aggregations