SCTrack.tracker module¶
- class SCTrack.tracker.CellNode(*args, **kwargs)[source]¶
Bases:
Node
Tracking node, including the track_ID, cell_id, branch_id of the cell, and the detailed information of the cell, the parent-child node relationship
- STATUS = ['ACCURATE', 'ACCURATE-FL', 'INACCURATE', 'INACCURATE-MATCH', 'PREDICTED']¶
- property identifier¶
The unique ID of a node within the scope of a TrackingTree
- property nid¶
same as identifier, override treelib related methods
- set_tree_status(status: TreeStatus)[source]¶
- class SCTrack.tracker.Checker(protocol=None)[source]¶
Bases:
object
A checker that checks whether the cells participating in the match can calculate.
- class SCTrack.tracker.Match(*args, **kwargs)[source]¶
Bases:
object
Matcher, matches targets based on previous and next frames and assigns IDs in the current frame. Mainly used for feature matching and calculating similarity. The unit of operation is frames.
- calcAreaSimilar(cell_1: Cell, cell_2: Cell)[source]¶
Calculate the area similarity of two cells Return value range: float[0, 1]
- calcCosDistance(cell_1: Cell, cell_2: Cell)[source]¶
Calculate the cosine distance of two cells Return value range: float[0, 2] The smaller the distance, the more similar it is, scaled to [0, 1) by the arctangent function The return value is the cosine value after normalization [0, π/2]. The smaller the return value, the lower the similarity
- calcCosSimilar(cell_1: Cell, cell_2: Cell)[source]¶
Calculate the cosine similarity of the center points of two cells Return value range: float[0, 1] The larger the value, the more similar The return value is the sine value after normalization [0, π/2]
- calcEuclideanDistance(cell_1: Cell, cell_2: Cell)[source]¶
Calculate the Euclidean distance between two cell center points Return value range: float(0,∞) The smaller the distance, the more similar it is, scaled to [0, 1) by the arctangent function The return value is the cosine value after normalization [0, π/2]. The smaller the return value, the lower the similarity
- calcIoU(cell_1: Cell, cell_2: Cell)[source]¶
Calculate IoU of two cells. First, try to calculate the IoU of the contour. If it is not possible to calculate, then change to calculating the IoU of the bounding box. return value range: float(0-1)
- calcIoU_roughly(cell_1: Cell, cell_2: Cell)[source]¶
Calculate IoU of two cell bounding boxes. return value range: float(0-1)
- compareDicSimilar(cell_1: Cell, cell_2: Cell)[source]¶
Compare dic similarity Return value range: float(0, 1)
- compareMcySimilar(cell_1: Cell, cell_2: Cell)[source]¶
Compare mcy similarity Return value range: float(0, 1)
- compareShapeSimilar(cell_1: Cell, cell_2: Cell)[source]¶
Calculate the contour similarity of two cells Return value range: float(0, 1) The smaller the score value, the greater the similarity, and the inversion operation can be performed. (The return value is the cosine value after normalization [0, π/2], no longer do this change, directly return the score.)
- class SCTrack.tracker.Matcher[source]¶
Bases:
object
A matcher that realizes the association of front and back frame objects.
- calc_sorted_value(parent: Cell, matched_cell)[source]¶
Calculate the sorting value of a Cell object.
- check_iou(similar_dict)[source]¶
Check the IoU to provide a basis for determining cell division. If there are less than 2 matching options with IoU > 0, return False. Otherwise, return these two cells.
- get_similar_sister(parent: Cell, matched_cells_dict: dict, area_t=0.7, shape_t=0.03, area_size_t=1.3, iou_t=0.1)[source]¶
Find the two most similar cells among multiple candidates as the daughter cells.
- is_mitosis_start(pre_parent: Cell, last_leaves: List[Cell], area_size_t=1.5, iou_t=0.3)[source]¶
Determine whether a cell enters the M cell_type. The basic criterion is that when a cell enters mitosis, its volume increases and the number of candidate regions increases. If the cell successfully enters the M cell_type, return a dict containing information about the last frame of G2 and the first frame of M. Otherwise, return False.
- match_duplicate_child(parent, unmatched_child_list)[source]¶
Match multiple candidates. Calling this function means that there is more than one candidate, and this method calculates the matching degree of each candidate The return value is a dictionary in the form of {Cell: similar_dict}
- match_similar(cell_1: Cell, cell_2: Cell)[source]¶
Calculate the similarity of two cells, do not include the image information.
- match_single_cell(tree: TrackingTree, current_frame: FeatureExtractor)[source]¶
The implementation logic for tracking a single cell.
- predict_next_position(parent: Cell)[source]¶
According to the speed, the possible position of the daughter cell is predicted, and the predicted daughter cell is used to participate in the matching. speed=0 is equivalent to not enabling prediction.
- select_mitosis_cells(parent: Cell, candidates_child_list: List[Cell], area_t=0.5, shape_t=0.05, area_size_t=1.3)[source]¶
If cell division occurs, select two daughter cells. When calling this method, make sure that cell division is highly likely to occur. If the return value is cell division, then it is necessary to check whether the areas of the two daughter cells are normal. If the area of one daughter cell is too large, it is considered a FP.
:return ([cell_1, cell2], ‘match status’)
- select_single_child(score_dict)[source]¶
For multiple IOU matching options, choose the one with a higher similarity. This is to distinguish overlapping cells rather than cell division. Note: the results of this method are not necessarily accurate and may result in mismatches due to cell crossing, which needs to be resolved in subsequent steps. In addition, if one cell is accurately matched, and the other cell has no match (i.e., not detected in the next frame during recognition), it should be filled as a predicted cell.
- class SCTrack.tracker.Tracker(annotation, mcy=None, dic=None)[source]¶
Bases:
object
Tracker object, which is the controller of the tracking process. It reads images frame by frame, initializes and updates the TrackingTree, performs matching and assigns various IDs.
- check_track(fe1: FeatureExtractor, fe2: FeatureExtractor, fe3: FeatureExtractor)[source]¶
Check the track results to see if there are any wrong matches and omissions, and update the matching status at the same time
- get_current_tree(parent_cell: Cell)[source]¶
Get the TrackingTree where the current parent cell is located
- handle_duplicate_match(duplicate_match_cell)[source]¶
Solve a cell is repeatedly matched by multiple cells
- init_tracking_tree(fe: FeatureExtractor)[source]¶
Initialize TrackingTree
- rematch(fe1: FeatureExtractor, fe2: FeatureExtractor)[source]¶
For the loss detection cells, re-match the upper and lower frames with the cache frame
- track_near_frame(fe1: FeatureExtractor, fe2: FeatureExtractor)[source]¶
match adjacent frames
- track_near_frame_mult_thread(fe1: FeatureExtractor, fe2: FeatureExtractor)[source]¶
Match Adjacent Frames, Multithreaded Beta
- static update_speed(parent: Cell, child: Cell, default: Vector | None = None)[source]¶
Update cell movement speed
- visualize_to_tif(background_mcy_image: str, output_tif_path, tree_list, xrange=None, single=False)[source]¶
Visualize the tracking results, you can choose to save as a single tif file or multiple tif sequences :param background_mcy_image: background image for visualization :param output_tif_path: output file path :param tree_list: TrackingTree list to visualize :param xrange: visualization range :param single: Whether to choose to save as a single file
- class SCTrack.tracker.TrackingTree(root: CellNode | None = None, track_id=None)[source]¶
Bases:
Tree
The core structure of tracking implement. All tracking results are stored in the instance of this class. Each TrackingTree instance represents the cell line of a cell, and the TrackingTree branch represents cell division.
- add_node(node: CellNode, parent: CellNode | None = None)[source]¶
Add a new CellNode object to the TrackingTree
- branch_id_distributor()[source]¶
Used to assign a branch_id to each branch in a TrackingTree object. The branch_id is incremented in a non-reversible and non-reusable manner.
- change_mitosis_flag(flag: bool)[source]¶
When the cell enters mitosis for the first time, self.mitosis_start_flag is set to True, and when the cell completes division, it is reset to false
- property last_layer¶
Return all CellNodes in the last layer of TrackingTree
- property last_layer_cell¶
cells contained in the node}.
- Type:
Return a dict of {leaf node
- SCTrack.tracker.get_cell_line_from_tree(tree: TrackingTree, dic_path: str, mcy_path: str, savepath)[source]¶
Obtain a complete cell sequence from the track tree, including cell images, dic and mcy dual channels, and cycles, and the generated file name is named track_id-branch_id-frame-cell_type.tif