Analysis › Process · version 1 · has a preview
Remove, or hide, the localizations inside or outside the ROI.
Some localizations are not wanted: a fluorescent dirt particle, a bead, a cell that was out of focus, or simply everything except the one cell out of a field of twenty that is to be analysed. This plugin takes a region and either throws away what is inside it or what is outside it.
It can do that in two ways (action):
use by default: 1 kept, 0 hidden) and the filter – also called bounds: the lowest and highest values of attributes a localization must lie between – is set on that attribute, so they disappear from the picture and from what the other plugins get, but are still in the file and come back when the filter is opened again.Hiding is the safer of the two. A removal can be undone only as long as the session lasts; once the table is saved, the removed localizations are gone from the file. A hidden localization is one slider away, now or next week.
It needs a table and, for the usual use, an ROI (region of interest: a rectangle, polygon or line with a width) drawn in the render window.
The region can also be one in time: the binding-event edges of DNA-PAINT, in which a short DNA strand carrying the dye (the imager) binds to its target for a few frames and leaves again. The imager rarely binds exactly as a frame starts or leaves exactly as one ends, so the first and the last frame of each binding event saw it for only part of the exposure: those localizations have too few photons and a worse precision. Removing them – keeping the event's core – is the selection of Steen et al. (2024), as Picasso (Schnitzbauer et al. 2017) does it, and is worth doing before anything that weighs localizations by their photons or their precision, or averages them into one position per site. It needs the localizations' frames and, for the default linking distance, the table's pixel size.
1. Which localizations are in the region. With region set to the drawn ROI, a localization is inside when it lies within the shape drawn in the render window, in the picture's own coordinates – its position (x_nm, y_nm, or the pixel attributes of a pixel table) on the ordinary picture, and whatever the axes show when the picture is of other attributes (photons against frame, say): a rectangle, a polygon, or a line with a width (a line is a rectangle of that width around the segment). The ROI is taken on its own: the layer's filter does not narrow it, so every localization of the table in the drawn shape counts, whichever file or layer it belongs to.
With region set to the selection, "inside" means everything that decides what the current layer (one picture of the localizations, with its own filter and colours) shows: its filter, the ROI if one is drawn, and the 3D slab while the 3D window is set to have plugins use it. This is the way to say "keep exactly what I see" (remove the localizations outside the selection), or to remove the localizations a filter already hides.
With region set to all included ROIs, "inside" means inside any ROI of the ROI manager whose use is ticked, each ROI in its own file, by its shape alone (the layer's filter does not narrow it, as for a measurement in the ROI). remove the localizations outside them and a field of a few hundred segmented pores shrinks to the pores, which makes a much smaller file; for clusters, a filter on cluster_id 1 does the same without the ROI manager.
With region set to binding-event edges, the localizations are first linked into binding events: a localization joins an event when it lies in the frame after the event's last one (with dark frames above 0, up to that many frames later) and within within of the event's position – by default a tenth of a camera pixel, 13 nm for a 130 nm pixel. "Inside" is then every localization in the first or the last frame of its event, and every localization of an event with fewer than min localizations (with three, such an event has no frame that is neither). Files and channels are linked apart.

The photons of simulated binding events, each localization's photons in proportion to the part of the frame the imager was bound (the truth: the whole frame, 3000 photons, dashed). All localizations (grey) have a tail of dim ones – the edges; the cores (orange) are the whole frames.
2. Which side goes. The setting remove chooses: the localizations inside empties the region, the localizations outside keeps it and nothing else.

A simulated field of view with an ROI drawn over it (blue). Removing the localizations inside the ROI cuts a hole; removing those outside keeps the ROI alone.
3a. Remove. A new table is made with only the localizations that stay, and it replaces the old one. The old one goes on the undo stack, under the plugin's name, so File > Undo brings it back.
3b. Hide. The flag attribute is written: 1 for a localization that stays, 0 for one that is hidden. If the attribute is already there, the two are combined – a localization already hidden stays hidden – so hiding one dirt particle and then another hides both. Then the filter of every localization layer is set to keep use 0.5. No row is deleted, and moving that bound back (or removing it) shows everything again.
Before anything is written the plugin counts what would go, and refuses a run that would take nothing (nothing is on that side of the region) or everything (it would leave an empty table). Preview says the same count without changing the table.
Inside a shape. A rectangle is a test of and
against its edges, the edges included. A polygon, and a line (stored as the four corners of its rectangle), is tested with the even-odd rule: a point is inside when a ray from it crosses the outline an odd number of times. Only the points in the polygon's bounding box are tested, so a small ROI on a large table is quick.
The whole table. Both actions work on the whole table of single localizations, not on the selection of one layer: a localization inside the drawn ROI goes (or is hidden) whatever layer or file it is in. To act on one file only, set region to the selection with the layer showing that file. The selection is then the layer's bounds applied to each localization, also when the layer shows blinks.
A hidden flag and merged blinks. Once the localizations of a blink are merged – merge blinks, also called grouping or linking – a blink is kept only if all of its localizations are. The flag is stored with a rule for merging (a recipe with the rule all and no expression, in the table's metadata["derived"]), so it is not averaged like a measured attribute: a blink that straddles the edge of the hidden region is hidden as a whole rather than coming back as a blink with half a flag. See Math Parser for how recipes work.
Binding-event edges. The events are linked by the same walk as merge blinks uses, given no precision, so that its test is a circle: a localization joins when its distance from the event's running position is less than within. The running position is the mean of the last position and the new one, each time a localization joins; Picasso tests the distance to the last localization alone. Two consecutive localizations of one event are apart along each axis (with
the precision), and one from the running position about
, so at the same radius an event breaks in two a little less often here. Either way the radius must be several times the precision: at 13 nm, localizations precise to 5 nm break an event between two frames about one time in eight (one in five with Picasso's test), and each break makes two more edges; precise to 3 nm, about one time in 800. In both programs the first localization in range in the next frame joins, not the nearest. Picasso's constants are the defaults: a tenth of a pixel, no dark frame, three localizations.
Hidden rather than removed, the edges are flagged with the rule any for merging, not all: every merged blink has edges, so with all every one would be hidden. A merged blink is then shown when it has a core, but its position and photons are still merged from all its localizations, the edges included. To merge blinks from their cores alone, remove the edges.
The flag's name. flag must be a word of letters, digits and underscores that does not start with a digit, so that it can be used in a filter and in an expression. group_id and n_in_group are refused, because merging blinks writes them itself and would overwrite the flag. So is a attribute the table already has, unless it is a flag itself: hiding writes 0 and 1 over it, and a flag named photons would have replaced the photons.
| setting | default | what it does |
|---|---|---|
removewhich | the localizations inside | Which side of the region goes. the localizations outside together with the selection keeps what is on screen and nothing else. Choices: the localizations inside; the localizations outside |
regionregion | the drawn ROI | The drawn ROI on its own, everything that decides what is on screen, the ROI manager's used ROIs, or the first and last frame of each binding event. the drawn ROI needs an ROI in the render window, all included ROIs at least one used ROI in the ROI manager; the plugin refuses to run without them. Choices: the drawn ROI; the selection (filter, ROI, slab); all included ROIs; binding-event edges |
actionaction | remove them from the table | Hiding writes an attribute and sets the filter on it, so the decision is reversible and is saved with the file. Prefer hide while deciding; remove makes a smaller table and file, which is worth it only once the decision is final. Choices: remove them from the table; keep them, flagged and filtered out |
flag (more)field | use | The attribute hiding writes: 1 visible, 0 hidden. Only used when hiding. Keep the default unless two different kinds of hiding should be kept apart – |
| binding events | ||
withinedges.within_nm | auto | How far a localization may be from the event's position in the frame before; auto: a tenth of a pixel. The default, a tenth of a camera pixel, is Picasso's and suits DNA-PAINT, whose bright events are localized to a few nanometres. For dimmer data raise it to about three times the precision; too small and events break into pieces, each with edges of its own, too large and two sites close together are linked into one event. |
dark framesedges.dark_frames | 0 frames | Frames an event may miss and continue. 0, as in Picasso: one frame without a localization ends the event. With 1, an event missed in one frame (a localization lost to the filter) stays one event, but two bindings of one site a frame apart are joined. |
min localizationsedges.min_locs | 3 | An event with fewer is all edges. Three is the least that leaves a core. Raise it to keep only long events, whose cores are many frames. at least 1 |
The run is recorded in the file's history, with its settings, and can be undone. The flag attribute and its merging rule are saved with the file, so the decision survives a reload. So does the filter on it: the bound is kept with the table, and a reopened file hides the same localizations again.
Based on SMAP's Process/Modify/RemoveLocs (Ries 2020). Here:
active field and regroups the table after every run. Here the attribute is named by flag, the filter is set on it so the hidden localizations actually disappear, and it carries the rule all for merging blinks, so nothing is merged again unless a layer merges blinks.select_binding_event_cores this follows.