Skip to content

Commit 593fceb

Browse files
committed
Add function to set any spot filter
1 parent f5de1fd commit 593fceb

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/imcflibs/imagej/trackmate.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,44 @@ def spot_filtering(
235235
return settings
236236

237237

238+
def set_spotfilter(settings, filter_key, filter_value):
239+
"""Sets a TrackMate spot filter with specified filter key and values.
240+
241+
Parameters
242+
----------
243+
settings : fiji.plugin.trackmate.Settings
244+
Dictionary containing all the settings to use for TrackMate.
245+
filter_name : str
246+
The name of the filter to be applied. You must use the keys of the features, not their name.
247+
Here is the table of the feature keys and names for the spot features:
248+
https://imagej.net/plugins/trackmate/scripting/trackmate-detectors-trackers-keys
249+
filter_value : list
250+
A list containing two values for the filter. The first value is
251+
applied as an above-threshold filter, and the second as a below-threshold filter.
252+
253+
Returns
254+
-------
255+
Settings
256+
The modified TrackMate settings dict with added spot filters
257+
258+
Example
259+
-------
260+
>>> # Set an above-threshold filter value for spot "QUALITY" without a below-threshold value
261+
>>> tm_settings = set_trackmate_spotfilter(tm_settings, 'QUALITY', [120, None])
262+
"""
263+
264+
settings.addAllAnalyzers()
265+
if filter_value[0] != None:
266+
filter_low = FeatureFilter(filter_key, filter_value[0], True)
267+
settings.addSpotFilter(filter_low)
268+
if filter_value[1] != None:
269+
filter_high = FeatureFilter(filter_key, filter_value[1], False)
270+
settings.addSpotFilter(filter_high)
271+
272+
return settings
273+
274+
275+
238276
def sparse_lap_tracker(settings):
239277
"""Create a sparse LAP tracker with default settings.
240278

0 commit comments

Comments
 (0)