from time import time
from .core import segmentation, tracker
from .gui import parser, load, editor, save
from .utils import contours
[docs]def main():
"""
Start DiatomTrack. First user input is parsed. Then images are segmented,
cells tracked and editor opened based on input.
Returns
-------
None.
"""
start_time = time()
# Parse segmentation
args = parser.parse_segmentation()
if args:
if args[-2] != True:
# Parse tracker
age, offset, split, gap = parser.parse_tracker()
if args[-1]:
(
source_dir, destination_dir, states, name, limit, only_seg, _
) = args
# Segment images
seg_contours, video_file_name = segmentation.run_segmentation(
states, source_dir, destination_dir, name, limit, only_seg)
else:
(
segmentation_name, video_file_name, destination_dir, name,
limit, _
) = args
# Load segmentation
seg_contours = load.read_seg(segmentation_name)
if args[-2] != True:
# Process segmented contours
filtered_contours, properties = contours.contour_filter_process(
seg_contours, limit)
# Track objects
track_summary = tracker.track(properties, age, offset, split, gap)
(tracker_output, tracks), Tracker = track_summary
track_data = tracker.tracks_to_dataframe(tracks)
else:
# Parse editor
args = parser.parse_editor()
# Load track data
if len(args) > 3:
video_file_name, track_file_name, destination_dir, name = args
track_data = load.read_track(track_file_name)
else:
track_video_file_name, destination_dir, name = args
track_data, video_file_name = load.read_tvf(track_video_file_name)
if args[-2] != True or len(args) < 5:
# Manual edit
t_edit = editor.TrackEditor(track_data.copy(), video_file_name)
# Save data and statistics
edit_counts = (
t_edit.no_frustule_flips, t_edit.no_cell_flips, t_edit.no_splits,
t_edit.no_merges, t_edit.no_moves, t_edit.no_swaps)
_ = save.SaveData(
destination_dir, name, video_file_name, t_edit.tracks, track_data,
start_time, edit_counts)
if __name__ == '__main__':
main()