use of ij.gui.Roi in project GDSC-SMLM by aherbert.
the class EMGainAnalysis method run.
public void run(ImageProcessor ip) {
// Calculate the histogram
final int[] h = (simulate) ? simulateHistogram(usePDF ? 0 : 1) : buildHistogram(imp);
// We need > 10^7 pixels from flat white-light images under constant exposure ...
final int size = getSize(h);
if (imp != null) {
Roi roi = imp.getRoi();
Rectangle bounds;
if (roi == null)
bounds = new Rectangle(0, 0, imp.getWidth(), imp.getHeight());
else
bounds = roi.getBounds();
Utils.log("Analysing %s [x=%d,y=%d,width=%d,height=%d]", imp.getTitle(), bounds.x, bounds.y, bounds.width, bounds.height);
}
Utils.log("Histogram contains %d pixels", size);
if (size < MINIMUM_PIXELS)
Utils.log("WARNING : Recommend at least %d pixels (%sx more)", MINIMUM_PIXELS, Utils.rounded((double) MINIMUM_PIXELS / size));
fit(h);
}
use of ij.gui.Roi in project GDSC-SMLM by aherbert.
the class DriftCalculator method run.
/*
* (non-Javadoc)
*
* @see ij.plugin.PlugIn#run(java.lang.String)
*/
public void run(String arg) {
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
// Require some fit results and selected regions
if (MemoryPeakResults.isMemoryEmpty()) {
IJ.error(TITLE, "There are no fitting results in memory");
return;
}
Roi[] rois = getRois();
String[] stackTitles = createStackImageList();
if (!showDialog(rois, stackTitles))
return;
MemoryPeakResults results = ResultsManager.loadInputResults(inputOption, false);
if (results == null || results.size() < 2) {
IJ.error(TITLE, "There are not enough fitting results for drift correction");
return;
}
double[][] drift = null;
int[] limits = findTimeLimits(results);
if (method.equals(MARKED_ROIS)) {
drift = calculateUsingMarkers(results, limits, rois);
} else if (method.equals(STACK_ALIGNMENT)) {
ImageStack stack = showStackDialog(stackTitles);
if (stack == null)
return;
drift = calculateUsingImageStack(stack, limits);
} else if (method.equals(DRIFT_FILE)) {
drift = calculateUsingDriftFile(limits);
} else {
if (!showSubImageDialog())
return;
drift = calculateUsingFrames(results, limits, Integer.parseInt(reconstructionSize));
}
if (drift == null)
return;
Utils.log("Drift correction interpolated for frames [%d - %d] of [%d - %d] (%s%%)", interpolationStart, interpolationEnd, limits[0], limits[1], Utils.rounded((100.0 * (interpolationEnd - interpolationStart + 1)) / (limits[1] - limits[0] + 1)));
applyDriftCorrection(results, drift);
}
use of ij.gui.Roi in project GDSC-SMLM by aherbert.
the class SmoothImage method setup.
/*
* (non-Javadoc)
*
* @see ij.plugin.filter.PlugInFilter#setup(java.lang.String, ij.ImagePlus)
*/
public int setup(String arg, ImagePlus imp) {
if (arg.equals("final")) {
//imp.resetDisplayRange();
imp.updateAndDraw();
return DONE;
}
SMLMUsageTracker.recordPlugin(this.getClass(), arg);
if (imp == null) {
IJ.noImage();
return DONE;
}
Roi roi = imp.getRoi();
if (roi != null && roi.getType() != Roi.RECTANGLE) {
IJ.error("Rectangular ROI required");
return DONE;
}
return flags;
}
use of ij.gui.Roi in project GDSC-SMLM by aherbert.
the class PCPALMAnalysis method cropToRoi.
/**
* Extract all the PC-PALM molecules that are within the image ROI region. The coordinates bounds are
* converted using relative scaling to the limits of the PC-PALM molecules. If a non-rectangular ROI is used then a
* mask is extracted and used for the crop. If no image is provided then the full set of molecules is returned.
* <p>
* Set the area property to the region covered by the molecules.
*
* @param imp
* @return
*/
ArrayList<Molecule> cropToRoi(ImagePlus imp) {
croppedArea = PCPALMMolecules.area;
if (PCPALMMolecules.molecules == null || PCPALMMolecules.molecules.isEmpty()) {
return PCPALMMolecules.molecules;
}
double pcw = PCPALMMolecules.maxx - PCPALMMolecules.minx;
double pch = PCPALMMolecules.maxy - PCPALMMolecules.miny;
Roi roi = (imp == null) ? null : imp.getRoi();
if (roi == null || !roi.isArea()) {
log("Roi = %s nm x %s nm = %s um^2", Utils.rounded(pcw, 3), Utils.rounded(pch, 3), Utils.rounded(croppedArea, 3));
minx = PCPALMMolecules.minx;
maxx = PCPALMMolecules.maxx;
miny = PCPALMMolecules.miny;
maxy = PCPALMMolecules.maxy;
return PCPALMMolecules.molecules;
}
int w = imp.getWidth();
int h = imp.getHeight();
Rectangle bounds = roi.getBounds();
// Construct relative coordinates
minx = PCPALMMolecules.minx + pcw * ((double) bounds.x / w);
miny = PCPALMMolecules.miny + pch * ((double) bounds.y / h);
maxx = PCPALMMolecules.minx + pcw * ((double) (bounds.x + bounds.width) / w);
maxy = PCPALMMolecules.miny + pch * ((double) (bounds.y + bounds.height) / h);
final double roix = maxx - minx;
final double roiy = maxy - miny;
ArrayList<Molecule> newMolecules = new ArrayList<Molecule>(PCPALMMolecules.molecules.size() / 2);
// Support non-rectangular ROIs
if (roi.getMask() != null) {
MaskDistribution dist = createMaskDistribution(roi.getMask(), roix, roiy);
double fraction = (double) dist.getSize() / (roi.getMask().getWidth() * roi.getMask().getHeight());
log("Roi is a mask of %d pixels", dist.getSize());
croppedArea = fraction * roix * roiy / 1e6;
log("Roi area %s x %s nm x %s nm = %s um^2", Utils.rounded(fraction), Utils.rounded(roix, 3), Utils.rounded(roiy, 3), Utils.rounded(croppedArea, 3));
double[] xyz = new double[3];
// The mask is 0,0 in the centre so offset by this as well
double xoffset = minx + roix / 2;
double yoffset = miny + roiy / 2;
for (Molecule m : PCPALMMolecules.molecules) {
xyz[0] = m.x - xoffset;
xyz[1] = m.y - yoffset;
if (dist.isWithinXY(xyz))
newMolecules.add(m);
}
} else {
croppedArea = roix * roiy / 1e6;
log("Roi = %s nm x %s nm = %s um^2", Utils.rounded(roix, 3), Utils.rounded(roiy, 3), Utils.rounded(croppedArea, 3));
for (Molecule m : PCPALMMolecules.molecules) {
if (m.x < minx || m.x >= maxx || m.y < miny || m.y >= maxy)
continue;
newMolecules.add(m);
}
}
return newMolecules;
}
Aggregations