use of uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi in project GDSC-SMLM by aherbert.
the class PeakResultTableModelFrame method doSourceOverlay.
private void doSourceOverlay() {
final PeakResultTableModel model = getModel();
if (model == null) {
return;
}
final PeakResult[] list = table.getSelectedData();
if (list.length == 0) {
return;
}
final ImageSource source = model.getSource();
if (source == null) {
return;
}
final String title = source.getOriginal().getName();
final ImagePlus imp = WindowManager.getImage(title);
if (imp == null) {
return;
}
// Assumes 3D stack (no channel/time)
if (imp.getNDimensions() > 3) {
return;
}
try {
final TypeConverter<DistanceUnit> converter = CalibrationHelper.getDistanceConverter(model.getCalibration(), DistanceUnit.PIXEL);
final Overlay o = new Overlay();
if (list.length == 1) {
final PeakResult p = list[0];
final PointRoi roi = new OffsetPointRoi(converter.convert(p.getXPosition()), converter.convert(p.getYPosition()));
roi.setPointType(3);
roi.setPosition(p.getFrame());
o.add(roi);
} else {
Arrays.sort(list, FramePeakResultComparator.INSTANCE);
final TFloatArrayList ox = new TFloatArrayList(list.length);
final TFloatArrayList oy = new TFloatArrayList(list.length);
int frame = list[0].getFrame() - 1;
for (int i = 0; i < list.length; i++) {
if (frame != list[i].getFrame()) {
if (ox.size() > 0) {
final PointRoi roi = new OffsetPointRoi(ox.toArray(), oy.toArray());
roi.setPointType(3);
roi.setPosition(frame);
ox.resetQuick();
oy.resetQuick();
o.add(roi);
}
frame = list[i].getFrame();
}
ox.add(converter.convert(list[i].getXPosition()));
oy.add(converter.convert(list[i].getYPosition()));
}
if (ox.size() > 0) {
final PointRoi roi = new OffsetPointRoi(ox.toArray(), oy.toArray());
roi.setPointType(3);
roi.setPosition(frame);
o.add(roi);
}
}
imp.setOverlay(o);
final PeakResult p = list[0];
imp.setSlice(p.getFrame());
ImageJUtils.adjustSourceRect(imp, 0, (int) converter.convert(p.getXPosition()), (int) converter.convert(p.getYPosition()));
imp.getWindow().toFront();
} catch (final ConversionException ex) {
// Ignore
}
}
use of uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi in project GDSC-SMLM by aherbert.
the class PeakFit method addSingleFrameOverlay.
private void addSingleFrameOverlay() {
// If a single frame was processed add the peaks as an overlay if they are in memory
ImagePlus localImp = this.imp;
if (fitMaxima && singleFrame > 0 && source instanceof IJImageSource) {
final String title = source.getName();
localImp = WindowManager.getImage(title);
}
if (singleFrame > 0 && localImp != null) {
MemoryPeakResults memoryResults = null;
for (final PeakResults r : this.results.toArray()) {
if (r instanceof MemoryPeakResults) {
memoryResults = (MemoryPeakResults) r;
break;
}
}
if (memoryResults == null || memoryResults.size() == 0) {
return;
}
final ExtendedGenericDialog gd = new ExtendedGenericDialog(TITLE);
gd.enableYesNoCancel();
gd.hideCancelButton();
gd.addMessage("Add the fitted localisations as an overlay?");
gd.showDialog();
if (!gd.wasOKed()) {
return;
}
final LUT lut = LutHelper.createLut(LutColour.ICE);
final Overlay o = new Overlay();
final int size = memoryResults.size();
final Counter j = new Counter(size);
final ImagePlus finalImp = localImp;
memoryResults.forEach(DistanceUnit.PIXEL, (XyResultProcedure) (x, y) -> {
final PointRoi roi = new OffsetPointRoi(x, y);
final Color c = LutHelper.getColour(lut, j.decrementAndGet(), size);
roi.setStrokeColor(c);
roi.setFillColor(c);
if (finalImp.getStackSize() > 1) {
roi.setPosition(singleFrame);
}
o.add(roi);
});
localImp.setOverlay(o);
localImp.getWindow().toFront();
}
}
use of uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi in project GDSC-SMLM by aherbert.
the class TcPalmAnalysis method runBurstOverlay.
/**
* Overlay the clusters on the image.
*
* @param bursts the bursts
* @param image the image
* @param colourMap the colour map
*/
private static void runBurstOverlay(LocalList<LocalList<PeakResult>> bursts, ImageJImagePeakResults image, ColourMap colourMap) {
if (bursts.isEmpty()) {
image.getImagePlus().setOverlay(null);
return;
}
final Overlay overlay = new Overlay();
for (int i = 0; i < bursts.size(); i++) {
final LocalList<PeakResult> results = bursts.unsafeGet(i);
final int np = results.size();
final float[] xp = new float[np];
final float[] yp = new float[np];
for (int j = 0; j < np; j++) {
final PeakResult r = results.unsafeGet(j);
xp[j] = image.mapX(r.getXPosition());
yp[j] = image.mapY(r.getYPosition());
}
final PointRoi roi = new OffsetPointRoi(xp, yp, np);
roi.setShowLabels(false);
roi.setPointType(3);
final Color c = colourMap.getColour(i);
roi.setFillColor(c);
roi.setStrokeColor(c);
overlay.add(roi);
}
image.getImagePlus().setOverlay(overlay);
}
use of uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi in project GDSC-SMLM by aherbert.
the class SpotInspector method mouseClicked.
private void mouseClicked(MouseEvent event) {
if (id != currentId.get()) {
return;
}
// Show the result that was double clicked in the result table
if (event.getClickCount() > 1) {
final int rank = textPanel.getSelectionStart() + 1;
// Show the spot that was double clicked
final ImagePlus imp = WindowManager.getImage(TITLE);
if (imp != null && rank > 0 && rank <= imp.getStackSize()) {
imp.setSlice(rank);
if (imp.getWindow() != null) {
imp.getWindow().toFront();
}
final PeakResult r = rankedResults.get(rank - 1).peakResult;
final TypeConverter<DistanceUnit> dc = results.getDistanceConverter(DistanceUnit.PIXEL);
final float rx = dc.convert(r.getXPosition());
final float ry = dc.convert(r.getYPosition());
final int x = (int) rx;
final int y = (int) ry;
// Find bounds
final int minX = x - settings.radius;
final int minY = y - settings.radius;
// Require the Shift key to add all spots
if (!event.isShiftDown()) {
// Add the single clicked spot
imp.setRoi(new OffsetPointRoi(rx - minX, ry - minY));
return;
}
// Add all the spots
final int maxX = x + settings.radius + 1;
final int maxY = y + settings.radius + 1;
// Create ROIs
final HashSet<Point2D.Float> spots = new HashSet<>();
results.forEach(DistanceUnit.PIXEL, (XyResultProcedure) (xp, yp) -> {
if (xp > minX && xp < maxX && yp > minY && yp < maxY) {
// Use only unique points
spots.add(new Point2D.Float(xp - minX, yp - minY));
}
});
final int points = spots.size();
final float[] ox = new float[points];
final float[] oy = new float[points];
final Counter c = new Counter();
spots.forEach(p -> {
ox[c.getCount()] = p.x;
oy[c.getAndIncrement()] = p.y;
});
imp.setRoi(new OffsetPointRoi(ox, oy, points));
}
}
}
use of uk.ac.sussex.gdsc.core.ij.gui.OffsetPointRoi in project GDSC-SMLM by aherbert.
the class PsfCreator method createRoi.
private static Roi createRoi(float x, float y, Color color) {
final Roi roi = new OffsetPointRoi(x, y);
roi.setStrokeColor(color);
roi.setFillColor(color);
return roi;
}
Aggregations