DiatomTrack.core package
Submodules
DiatomTrack.core.assignment module
- DiatomTrack.core.assignment.associate(detections, trackers, distance=None)[source]
Assign detections to trackers.
- Parameters:
detections (array) – The detection data.
trackers (array) – The tracker data.
distance (int, optional) – The cutoff Euclidean distance. The default is None.
- Returns:
matched (array) – Indices of matched detections and trackers.
unmatched_dets (array) – Indices of unmatched detections.
unmatched_trks (array) – Indices of unmatched trackers.
- DiatomTrack.core.assignment.associate_secondary(matched, dets, unmatched_dets, tracks, unmatched_trks, distance=None)[source]
Assign detections to trackers after filtering for already matched data.
- Parameters:
matched (array) – Indices of matched detections and trackers.
dets (array) – The detection data.
unmatched_dets (array) – Indices of unmatched detections.
tracks (array) – The tracker data.
unmatched_trks (array) – Indices of unmatched trackers.
distance (int, optional) – The cutoff Euclidean distance. The default is None.
- Returns:
matched (array) – Updated indices of matched detections and trackers.
unmatched_dets (array) – Updated indices of unmatched detections.
unmatched_trks (array) – Updated indices of unmatched trackers.
- DiatomTrack.core.assignment.calculate_iou(array)[source]
Caculate IoU between two rotated rectangles in OpenCV’s format.
- Parameters:
array (array) – The two rotated rectangles concatenated.
- Returns:
The IoU of the rectangles.
- Return type:
float
- DiatomTrack.core.assignment.euclid_batch(trackers, detections, distance)[source]
Calculate the Euclidean cost matrix for trackers and detections.
- Parameters:
trackers (array) – Tracker data.
detections (array) – Detection data.
distance (int) – Cutoff distance.
- Returns:
Euclidean cost matrix for all tracker and detection combinations.
- Return type:
array
DiatomTrack.core.segmentation module
- DiatomTrack.core.segmentation.run_segmentation(state_path, source_dir, destination_dir, name, limit, only_seg)[source]
Run the segmentation and extract all recognized object contours. Save contours and write all images to a video file.
- Parameters:
state_path (str) – Path to model states.
source_dir (str) – Path to images.
destination_dir (str) – Path to saving directory.
name (str) – Name of the experiment.
limit (int) – Number of images to segment.
only_seg (bool) – Determines program exit after segmentation.
- Returns:
contours (dict) – The dictionary containing all found object contours of all segmented images.
video_name (str) – Name of the created video from images.
Notes
The limit value is divided by the batch size thus rounding to the next larger multiple for the actual number of images.
- DiatomTrack.core.segmentation.segmentation(device, model, batch)[source]
Process a batch of images on the defined device and with the given model. Return two dictionaries with contour lists for singles and aggregates and the RGB images. The keys of the dictionaries are the image file names.
- Parameters:
device (torch.device) – The initialized torch.device with cude if available.
model (torch.model) – The model loaded to GPU to perform the segmentation.
batch (torch.dataloader batch) – The batch of images to be segmented containing the tensors, images and file names.
- Returns:
single (dict) – This dictionary contains the contours that were segmented as single cells. The keys are the image file names.
aggregate (dict) – This dictionary contains the contours that were segmented as aggregated cells. The keys are the image file names.
image_rgb (array) – The loaded image file as array.
- DiatomTrack.core.segmentation.segmentation_setup(state_path, image_dir)[source]
Take the path for the states of the model and the directory of the images to be segmented. Initialize the segmentation device, model and data.
- Parameters:
state_path (str) – The path to the states of weighted UNet.
image_dir (str) – The directory the to the images that shall be segmented.
- Returns:
device (torch.device) – The initialized torch.device with cude if available.
model (torch.model) – The model loaded to GPU to perform the segmentation.
data_loader (torch.dataloader) – The initialized dataloader for the images.
DiatomTrack.core.tracker module
- class DiatomTrack.core.tracker.DiatomTrack(max_age=200, division_age=1000, gap_distance=200, split_distance=50, offset=80)[source]
Bases:
objectThis class performs the spatial tracking of diatom objects using Kalman filter objects and also tracks the long sides / thecae of the objects.
- get_state()[source]
Return current states of all active trackers.
- Returns:
state – States of all active trackers.
- Return type:
list
- summarize()[source]
Compile the tracking results and match the long sides / theca over generations.
- Returns:
Summary of all tracking results.
- Return type:
list
- update(dets=array([], shape=(0, 5), dtype=float64), areas=[])[source]
Perform the tracking on the data from the next frame and archive expired trackers.
- Parameters:
dets (array, optional) – The data of detected bounding boxes. The default is np.empty((0, 5)).
areas (lilst, optional) – The areas of the detections. The default is [].
- Return type:
None.
- class DiatomTrack.core.tracker.KalmanTracker(rect, start, area, dist=200, boundary=(2048, 1536))[source]
Bases:
objectThis class contains the Kalman filter of individual tracked objects observed as a rotated bounding box and the history of that object and its ancestors.
- count = 0
- predict()[source]
Predict next state from filter while keeping boundary conditions of image, maximum distance, rotation angle < pi, and area > 0.
- summarize()[source]
Compiles summary of the tracker object with all relevant information to transform into a dataframe. Perform the side tracking based on minimum difference of adjacent rotation angles.
- Returns:
Summary of the tracker.
- Return type:
array
- tree = 0
- DiatomTrack.core.tracker.track(data, age, offset, split, gap)[source]
Track diatoms and theca over multiple generations using DiatomTrack.
- Parameters:
data (list) – The rotated rectangle data for each frame.
age (int) – Maximum frames an object may be undetected.
offset (int) – The maximum distance in Euclidean tracking.
split (int) – The maximum distance to consider splitting.
gap (int) – The maximum distance for matching after detection gap.
- Returns:
output (tuple) – Track data and trackers summarys.
Tracker (DiatomTrack object) – The DiatomTrack object used to track the objects.