use of ij.plugin.frame.RoiManager in project imagej1 by imagej.
the class OverlayCommands method hide.
void hide() {
ImagePlus imp = IJ.getImage();
imp.setHideOverlay(true);
RoiManager rm = RoiManager.getInstance();
if (rm != null)
rm.runCommand("show none");
}
use of ij.plugin.frame.RoiManager in project imagej1 by imagej.
the class OverlayCommands method toRoiManager.
void toRoiManager() {
ImagePlus imp = IJ.getImage();
Overlay overlay = imp.getOverlay();
if (overlay == null) {
IJ.error("Overlay required");
return;
}
RoiManager rm = RoiManager.getInstance2();
if (rm == null)
rm = new RoiManager();
if (overlay.size() >= 4 && overlay.get(3).getPosition() != 0)
Prefs.showAllSliceOnly = true;
rm.runCommand("reset");
rm.setEditMode(imp, false);
for (int i = 0; i < overlay.size(); i++) rm.add(imp, overlay.get(i), i + 1);
rm.setEditMode(imp, true);
rm.runCommand("show all");
imp.setOverlay(null);
}
use of ij.plugin.frame.RoiManager in project imagej1 by imagej.
the class RoiInterpolator method run.
public void run(String arg) {
RoiManager roiman = RoiManager.getInstance();
if (roiman == null || roiman.getCount() < 2) {
IJ.error("RoiInterpolator", "Please populate the ROI Manager with at least two ROIs");
return;
}
Roi[] rois = roiman.getRoisAsArray();
int xmax = 0;
int xmin = Integer.MAX_VALUE;
int ymax = 0;
int ymin = Integer.MAX_VALUE;
int zmax = 1;
int zmin = Integer.MAX_VALUE;
ArrayList<Integer> templateSlices = new ArrayList<Integer>();
for (Roi roi : rois) {
int slice = roiman.getSliceNumber(roi.getName());
if (!templateSlices.contains(new Integer(slice)))
templateSlices.add(new Integer(slice));
if (// ignore non-slice associated ROIs
slice == 0)
continue;
zmin = Math.min(slice, zmin);
zmax = Math.max(slice, zmax);
Rectangle bounds = roi.getBounds();
xmin = Math.min(xmin, bounds.x);
ymin = Math.min(ymin, bounds.y);
xmax = Math.max(xmax, bounds.x + bounds.width);
ymax = Math.max(ymax, bounds.y + bounds.height);
}
if (templateSlices.size() < 2) {
IJ.error("RoiInterpolator", "ROIs are all on the same slice, nothing to interpolate");
return;
}
// create the binary stack
final int stackW = xmax - xmin + 1;
final int stackH = ymax - ymin + 1;
final int nSlices = zmax - zmin + 1;
ImageStack stack = new ImageStack(stackW, stackH);
for (int s = 0; s < nSlices; s++) {
ByteProcessor bp = new ByteProcessor(stackW, stackH);
bp.setColor(255);
for (Roi roi : rois) {
int slice = roiman.getSliceNumber(roi.getName());
if (slice == zmin + s) {
Rectangle bounds = roi.getBounds();
roi.setLocation(bounds.x - xmin, bounds.y - ymin);
bp.setRoi(roi);
if (roi.getType() == Roi.RECTANGLE)
bp.fill();
else
bp.fill(roi);
}
}
stack.addSlice("" + s, bp);
}
// do the binary interpolation
BinaryInterpolator bi = new BinaryInterpolator();
bi.run(stack);
ImagePlus binary = new ImagePlus("interpolated", stack);
// get the ROIs
ThresholdToSelection ts = new ThresholdToSelection();
ts.setup("", binary);
for (int s = 0; s < nSlices; s++) {
if (templateSlices.contains(new Integer(s + zmin)))
continue;
ImageProcessor bp = stack.getProcessor(s + 1);
int threshold = 255;
bp.setThreshold(threshold, threshold, ImageProcessor.NO_LUT_UPDATE);
Roi roi = ts.convert(bp);
roi.setPosition(s + zmin);
Rectangle bounds = roi.getBounds();
roi.setLocation(bounds.x + xmin, bounds.y + ymin);
roiman.addRoi(roi);
}
for (Roi roi : rois) {
Rectangle bounds = roi.getBounds();
roi.setLocation(bounds.x + xmin, bounds.y + ymin);
}
roiman.runCommand("sort");
IJ.showStatus("ROIs interpolated");
}
use of ij.plugin.frame.RoiManager in project GDSC-SMLM by aherbert.
the class TcPalmAnalysis method analyseRois.
/**
* Analyses all the ROIs in the ROI manager.
*
* @param event the event
*/
private void analyseRois(ActionEvent event) {
final RoiManager manager = RoiManager.getInstance();
if (manager == null) {
IJ.error(TITLE, "ROI manager is not open");
return;
}
final LocalList<Roi> rois = Arrays.stream(manager.getRoisAsArray()).filter(Roi::isArea).collect(LocalCollectors.toLocalList());
if (rois.isEmpty()) {
IJ.error(TITLE, "No area ROIs");
return;
}
// Check for overlaps.
if (!settings.getDisableOverlapCheck() && anyOverlap(rois)) {
final GenericDialog gd = new GenericDialog(TITLE);
gd.addMessage(TextUtils.wrap("WARNING - Bounding rectangles of ROIs overlap. You can verify " + "the ROIs on the image using the ROI manager 'Show all' function.", 80));
gd.setOKLabel("Continue");
gd.showDialog();
if (gd.wasCanceled()) {
return;
}
}
// For each ROI:
// - Extract the current groups
// - Build the cumulative count plot
// - Identify the bursts
// - Extract ClusterData for each burst
final TcPalmAnalysisSettings settings = this.settings.build();
final LocalList<ClusterData> allClusters = rois.parallelStream().map(roi -> {
final Rectangle2D scaledBounds = createScaledBounds(roi);
final BiPredicate<ClusterData, Rectangle2D> filter = createSelectionFilter(roi, settings);
// Filter all cluster groups
final LocalList<ClusterData> clusters = new LocalList<>();
clusterData.forEach(c -> {
if (filter.test(c, scaledBounds)) {
clusters.add(c);
}
});
// Extract activation bursts
final CumulativeCountData countData = createCumulativeCountData(clusters, false);
final LocalList<int[]> bursts = runBurstAnalysis(settings, countData);
final LocalList<LocalList<PeakResult>> burstLocalisations = createBurstLocalisations(clusters, bursts);
clusters.clear();
burstLocalisations.forEach(list -> {
final ClusterData d = new ClusterData(clusters.size() + 1, list);
// Save this for analysis
d.sourceRoi = roi;
d.getArea();
clusters.add(d);
});
return clusters;
}).collect(LocalList::new, LocalList::addAll, LocalList::addAll);
// Reorder
final Counter count = new Counter();
allClusters.forEach(c -> c.id = count.incrementAndGet());
// Display in a table
final ClusterDataTableModelFrame frame = createAllClustersTable();
frame.getModel().setData(allClusters, dataCalibration);
// Allow the results to be repeated
frame.selectedAction = clusters -> {
// Expecting a single cluster. No clusters occurs when the table (and selection) is cleared.
if (clusters.size() == 1) {
final ClusterData c = clusters.get(0);
// Push the correct ROI and settings to the analysis action.
// We do not directly update the ROI or dialog settings as
// these trigger events that are processed to add work with a delay.
// Updating them at the end should generate events that are
// ignored when finally executed as the ROI/settings should be the same.
addWork(0, c.sourceRoi, settings, () -> {
// When analysis has finished update the settings and image ROI.
image.getImagePlus().setRoi(c.sourceRoi);
darkTimeToleranceTextField.setText(Integer.toString(settings.getDarkTimeTolerance()));
minClusterSizeTextField.setText(Integer.toString(settings.getMinClusterSize()));
// When analysis has finished the cluster should be selected in the
// current clusters table.
final ClusterDataTableModelFrame currentClusters = currentClustersTable.get();
if (currentClusters != null) {
currentClusters.select(c);
}
});
}
};
// Show histogram of cluster size/duration
reportAnalysis(settings, allClusters, dataCalibration);
// Save clusters to memory
final Trace[] traces = allClusters.stream().map(c -> {
final Trace t = new Trace();
t.setId(c.id);
c.results.forEach(t::add);
return t;
}).toArray(Trace[]::new);
TraceMolecules.saveResults(results, traces, "TC PALM");
IJ.showStatus(TITLE + ": " + TextUtils.pleural(allClusters.size(), "cluster"));
}
use of ij.plugin.frame.RoiManager in project imagej1 by imagej.
the class ImageCanvas method roiManagerSelect.
public boolean roiManagerSelect(Roi roi, boolean delete) {
RoiManager rm = RoiManager.getInstance();
if (rm == null)
return false;
int index = rm.getRoiIndex(roi);
if (index < 0)
return false;
if (delete) {
rm.select(imp, index);
rm.runCommand("delete");
} else
rm.selectAndMakeVisible(imp, index);
return true;
}
Aggregations