trackmate_template   A
last analyzed

Complexity

Total Complexity 0

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 0
eloc 75
dl 0
loc 157
rs 10
c 0
b 0
f 0
1
import sys
2
from ij import IJ, ImagePlus, ImageStack
3
import fiji.plugin.trackmate.Settings as Settings
4
import fiji.plugin.trackmate.Model as Model
5
import fiji.plugin.trackmate.SelectionModel as SelectionModel
6
import fiji.plugin.trackmate.TrackMate as TrackMate
7
import fiji.plugin.trackmate.Logger as Logger
8
import fiji.plugin.trackmate.detection.DetectorKeys as DetectorKeys
9
import fiji.plugin.trackmate.detection.DogDetectorFactory as DogDetectorFactory
10
import fiji.plugin.trackmate.tracking.sparselap.SparseLAPTrackerFactory as SparseLAPTrackerFactory
11
import fiji.plugin.trackmate.tracking.LAPUtils as LAPUtils
12
import fiji.plugin.trackmate.visualization.hyperstack.HyperStackDisplayer as HyperStackDisplayer
13
import fiji.plugin.trackmate.features.FeatureFilter as FeatureFilter
14
import fiji.plugin.trackmate.features.FeatureAnalyzer as FeatureAnalyzer
15
import fiji.plugin.trackmate.features.spot.SpotContrastAndSNRAnalyzerFactory as SpotContrastAndSNRAnalyzerFactory
16
import fiji.plugin.trackmate.action.ExportStatsToIJAction as ExportStatsToIJAction
17
import fiji.plugin.trackmate.io.TmXmlReader as TmXmlReader
18
import fiji.plugin.trackmate.action.ExportTracksToXML as ExportTracksToXML
19
import fiji.plugin.trackmate.io.TmXmlWriter as TmXmlWriter
20
import fiji.plugin.trackmate.features.ModelFeatureUpdater as ModelFeatureUpdater
21
import fiji.plugin.trackmate.features.SpotFeatureCalculator as SpotFeatureCalculator
22
import fiji.plugin.trackmate.features.spot.SpotContrastAndSNRAnalyzer as SpotContrastAndSNRAnalyzer
23
import fiji.plugin.trackmate.features.spot.SpotIntensityAnalyzerFactory as SpotIntensityAnalyzerFactory
24
import fiji.plugin.trackmate.features.track.TrackSpeedStatisticsAnalyzer as TrackSpeedStatisticsAnalyzer
25
import fiji.plugin.trackmate.features.track.TrackDurationAnalyzer as TrackDurationAnalyzer
26
import fiji.plugin.trackmate.util.TMUtils as TMUtils
27
28
29
# Get currently selected image
30
#imp = WindowManager.getCurrentImage()
31
imp = IJ.openImage('{target_file}')
32
IJ.run(imp, "Properties...", "channels=1 slices=1 frames=651 unit=pixel pixel_width=1.0000 pixel_height=1.0000 voxel_depth=1.0000");
33
#imp = IJ.openImage('/home/ubuntu/data/RED_nPEG_37C_pH72_S1_1_1_2.tif')
34
#imp = IJ.openImage('http://fiji.sc/samples/FakeTracks.tif')
35
#imp.show()
36
37
38
#-------------------------
39
# Instantiate model object
40
#-------------------------
41
42
model = Model()
43
44
# Set logger
45
model.setLogger(Logger.IJ_LOGGER)
46
47
#------------------------
48
# Prepare settings object
49
#------------------------
50
51
settings = Settings()
52
settings.setFrom(imp)
53
54
# Configure detector
55
settings.detectorFactory = DogDetectorFactory()
56
settings.detectorSettings = {{
57
    DetectorKeys.KEY_DO_SUBPIXEL_LOCALIZATION : True,
58
    DetectorKeys.KEY_RADIUS : {radius},
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable radius does not seem to be defined.
Loading history...
59
    DetectorKeys.KEY_TARGET_CHANNEL : 1,
60
    DetectorKeys.KEY_THRESHOLD : {threshold},
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable threshold does not seem to be defined.
Loading history...
61
    DetectorKeys.KEY_DO_MEDIAN_FILTERING : {do_median_filtering}
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable do_median_filtering does not seem to be defined.
Loading history...
62
}}
63
64
# Configure tracker
65
settings.trackerFactory = SparseLAPTrackerFactory()
66
settings.trackerSettings = LAPUtils.getDefaultLAPSettingsMap()
67
settings.trackerSettings['LINKING_MAX_DISTANCE'] = {linking_max_distance}
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable linking_max_distance does not seem to be defined.
Loading history...
68
settings.trackerSettings['GAP_CLOSING_MAX_DISTANCE']={gap_closing_max_distance}
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable gap_closing_max_distance does not seem to be defined.
Loading history...
69
settings.trackerSettings['MAX_FRAME_GAP']= {max_frame_gap}
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable max_frame_gap does not seem to be defined.
Loading history...
70
71
# Add the analyzers for some spot features.
72
# You need to configure TrackMate with analyzers that will generate
73
# the data you need.
74
# Here we just add two analyzers for spot, one that computes generic
75
# pixel intensity statistics (mean, max, etc...) and one that computes
76
# an estimate of each spot's SNR.
77
# The trick here is that the second one requires the first one to be in
78
# place. Be aware of this kind of gotchas, and read the docs.
79
settings.addSpotAnalyzerFactory(SpotIntensityAnalyzerFactory())
80
settings.addSpotAnalyzerFactory(SpotContrastAndSNRAnalyzerFactory())
81
82
filter2 = FeatureFilter('QUALITY', {quality}, True)
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable quality does not seem to be defined.
Loading history...
83
settings.addSpotFilter(filter2)
84
#filter3 = FeatureFilter('MEDIAN_INTENSITY', {median_intensity}, False)
85
#settings.addSpotFilter(filter3)
86
#filter4 = FeatureFilter('SNR', {snr}, True)
87
#settings.addSpotFilter(filter4)
88
89
90
# Add an analyzer for some track features, such as the track mean speed.
91
settings.addTrackAnalyzer(TrackSpeedStatisticsAnalyzer())
92
settings.addTrackAnalyzer(TrackDurationAnalyzer())
93
94
#filter5 = FeatureFilter('TRACK_DISPLACEMENT', {track_displacement}, True)
95
#settings.addTrackFilter(filter5)
96
97
settings.initialSpotFilterValue = 0
98
99
print(str(settings))
100
101
#----------------------
102
# Instantiate trackmate
103
#----------------------
104
105
trackmate = TrackMate(model, settings)
106
107
#------------
108
# Execute all
109
#------------
110
111
112
ok = trackmate.checkInput()
113
if not ok:
114
    sys.exit(str(trackmate.getErrorMessage()))
115
116
ok = trackmate.process()
117
if not ok:
118
    sys.exit(str(trackmate.getErrorMessage()))
119
120
121
122
#----------------
123
# Display results
124
#----------------
125
126
#model.getLogger().log('Found ' + str(model.getTrackModel().nTracks(True)) + ' tracks.')
127
128
selectionModel = SelectionModel(model)
129
#displayer =  HyperStackDisplayer(model, selectionModel, imp)
130
#displayer.render()
131
#displayer.refresh()
132
133
# The feature model, that stores edge and track features.
134
fm = model.getFeatureModel()
135
136
model.getLogger().log('Data starts here.')
137
model.getLogger().log('Track_ID' +','+ 'Spot_ID' +','+ 'Frame' +','+ 'X' +','+ 'Y' +','+ 'Quality' +','+ 'SN_Ratio' +','+ 'Mean_Intensity')
138
for id in model.getTrackModel().trackIDs(True):
139
140
    # Fetch the track feature from the feature model.
141
    #v = fm.getTrackFeature(id, 'TRACK_MEAN_SPEED')
142
    #dur = fm.getTrackFeature(id, 'TRACK_DURATION')
143
    #model.getLogger().log('')
144
    #model.getLogger().log('Track ' + str(id) + ': mean velocity = ' + str(v) + ' ' + model.getSpaceUnits() + '/' + model.getTimeUnits())
145
    #model.getLogger().log('Track ' + str(id) + ': duration = ' + str(dur) + ' ' + model.getTimeUnits())
146
    track = model.getTrackModel().trackSpots(id)
147
    for spot in track:
148
        sid = spot.ID()
149
        # Fetch spot features directly from spot.
150
        x=spot.getFeature('POSITION_X')
151
        y=spot.getFeature('POSITION_Y')
152
        t=spot.getFeature('FRAME')
153
        q=spot.getFeature('QUALITY')
154
        snr=spot.getFeature('SNR')
155
        mean=spot.getFeature('MEAN_INTENSITY')
156
        model.getLogger().log(str(id) +','+ str(sid) +','+ str(t) +','+ str(x) +','+ str(y) +','+ str(q) +','+ str(snr) +','+ str(mean))
157