idtrackerai

Post-processing

Impossible velocity jumps correction

correct_impossible_velocity_jumps.compute_neighbour_fragments_and_velocities(video, list_of_fragments, fragment)[source]

Computes the fragments with the same identities to the past and to the future of a given fragment and gives the velocities at the extremes of the current fragment

Parameters:

video : <Video object>

Object collecting all the parameters of the video and paths for saving and loading

list_of_fragments : <ListOfFragments object>

Object collecting the list of fragments and all the statistics and methods related to them

fragment : <Fragment object>

Object collecting all the information for a consecutive set of overlapping blobs that are considered to be the same animal

Returns:

neighbour_fragment_past : <Fragment object>

Fragment object with the same identity as the current fragment in the past

neighbour_fragment_future : <Fragment object>

Fragment object with the same identity as the current fragment in the future

velocities_between_fragments : nd.array

Velocities needed to connect the current fragment to its consecutive fragments in the past and in the future.

correct_impossible_velocity_jumps.compute_velocities_consecutive_fragments(neighbour_fragment_past, fragment, neighbour_fragment_future)[source]

Compute velocities in the extremes of a fragment with respecto to its neighbour_fragment_past and neighbour_fragment_future

Parameters:

neighbour_fragment_past : <Fragment object>

Fragment object with the same identity as the current fragment in the past

fragment : <Fragment object>

Object collecting all the information for a consecutive set of overlapping blobs that are considered to be the same animal

neighbour_fragment_future : <Fragment object>

Fragment object with the same identity as the current fragment in the future

Returns:

velocities : list

List with the velocity needed to link the fragment with its fragment in the past and in the future

See also

Fragment

correct_impossible_velocity_jumps.correct_impossible_velocity_jumps(video, list_of_fragments)[source]

Corrects the parts of the video where the velocity of any individual is higher than a particular velocty threshold given by video.velocity_threshold. This check is done from the video.first_frame_first_global_fragment to the past and to the future

Parameters:

video : <Video object>

Object collecting all the parameters of the video and paths for saving and loading

list_of_fragments : <ListOfFragments object>

Object collecting the list of fragments and all the statistics and methods related to them

correct_impossible_velocity_jumps.correct_impossible_velocity_jumps_loop(video, list_of_fragments, scope=None)[source]

Checks whether the velocity needed to join two consecutive fragments with the same identity is consistent with the typical velocity of the animals in the video (video.velocity_threshold). If the velocity is not consistent the identity of one of the fragments is reassigned. The check is performed from the video.first_frame_first_global_fragment to the past or to the future according to the scope

Parameters:

video : <Video object>

Object collecting all the parameters of the video and paths for saving and loading

list_of_fragments : <ListOfFragments object>

Object collecting the list of fragments and all the statistics and methods related to them

scope : string

If scope = to_the_past the check is performed to the past and if scope = to_the_future the check is performed to the future.

correct_impossible_velocity_jumps.get_fragment_with_same_identity(video, list_of_fragments, fragment, direction)[source]

Get the neighbour_fragment with the same identity in a given direction

Parameters:

video : <Video object>

Object collecting all the parameters of the video and paths for saving and loading

list_of_fragments : <ListOfFragments object>

Object collecting the list of fragments and all the statistics and methods related to them

fragment : <Fragment object>

Object collecting all the information for a consecutive set of overlapping blobs that are considered to be the same animal

direction : string

If direction = to_the_past gets the neighbour_fragment in the past direction = to_the_future gets the neighbour_fragment in the future

Returns:

neighbour_fragment : <Fragment object>

Fragment object with the same identity in a given direction

number_of_frames_in_direction : int

Number of frames to find the neighbour_fragment from a given extreme of the fragment

See also

Fragment

correct_impossible_velocity_jumps.reassign(fragment, fragments, impossible_velocity_threshold)[source]

Reassigns the identity of a given fragment considering the identity of the fragments coexisting with it and the impossible_velocity_threshold

Parameters:

fragment : <Fragment object>

Object collecting all the information for a consecutive set of overlapping blobs that are considered to be the same animal

fragments : list

List with all the Fragment objects of the video

impossible_velocity_threshold : float

If the velocity needed to link two fragments is higher than this threshold the identiy of one of the fragments is considerd to be wrong as it would be physically impossible for an animal to move so much. See video.velocity_threshold for each definition

See also

fragment.Fragment, get_available_and_non_available_identities(), get_candidate_identities_by_minimum_speed(), get_candidate_identities_above_random_P2()

Assign crossings

assign_them_all.clean_individual_blob_before_saving(blobs_in_video)[source]

Clean inidividual blobs whose identity is a list (it cannot be, hence an occluded identity has been assigned to an individual blob).

assign_them_all.close_trajectories_gaps(video, list_of_blobs, list_of_fragments)[source]

This is the main function to close the gaps where animals have not been identified (labelled with identity 0), are crossing with another animals or are occluded or not segmented.

Parameters:

video : <Video object>

Object containing all the parameters of the video.

list_of_blobs : <ListOfBlobs object>

Object with the collection of blobs found during segmentation with associated methods. See list_of_blobs.ListOfBlobs

list_of_fragments : <ListOfFragments object>

Collection of individual and crossing fragments with associated methods. See list_of_fragments.ListOfFragments

Returns:

list_of_blobs : <ListOfBlobs object>

ListOfBlobs object with the updated blobs and identities that close gaps

See also

set_individual_with_identity_0_as_crossings(), compute_erosion_disk(), compute_model_velocity(), reset_blobs_in_video_before_erosion_iteration(), interpolate_trajectories_during_gaps(), closing_gap_stopping_criteria(), clean_individual_blob_before_saving()

assign_them_all.get_forward_backward_list_of_frames(gap_interval)[source]

input: gap_interval: array of tuple [start_frame_number, end_frame_number] output: [f1, fn, f2, fn-1, …] for f1 = start_frame_number and

fn = end_frame_number
assign_them_all.reset_blobs_in_video_before_erosion_iteration(blobs_in_video)[source]

Resets the identity of crossings and individual with multiple identities before starting a loop of intepro()

Parameters:

blobs_in_video : type

Description of parameter blobs_in_video.

Returns:

type

Description of returned object.

Get trajectories

Produces the dictionary of outputs containing the individual trajectories (centroids), the git output, the path to the video whose tracking poroduced the individual trajectories and frames_per_second.

get_trajectories.assign_P2_to_identity(P2_vector, identity, frame_number, id_probabilities)[source]

Populate the matrix of P2 trajectories with the argmax of the P2_vector of a selected Blob object (see Blob)

Parameters:

P2_vector : array

Array with P2 values for a Blob

identity : int

Identity to be associated with the centroid

frame_number : int

Frame number in the tracked video

centroid_trajectories : ndarray

array of shape [number of frame in video x number of animals x 2]

Returns:

ndarray

centroid_trajectories

get_trajectories.assign_point_to_identity(centroid, identity, frame_number, centroid_trajectories)[source]

Populate the matrix of individual trajectories with the centroid of a selected Blob object (see Blob)

Parameters:

centroid : tuple

(x, y)

identity : int

Identity to be associated with the centroid

frame_number : int

Frame number in the tracked video

centroid_trajectories : ndarray

array of shape [number of frame in video x number of animals x 2]

Returns:

ndarray

centroid_trajectories

get_trajectories.produce_output_dict(blobs_in_video, video)[source]

Outputs the dictionary with keys: trajectories, git_commit, video_path, frames_per_second

Parameters:

blobs_in_video : list

List of all blob objects (see Blobs) generated by considering all the blobs segmented from the video

video : <Video object>

See Video

Returns:

dict

Output dictionary containing trajectories as values

get_trajectories.produce_trajectories(blobs_in_video, number_of_frames, number_of_animals)[source]

Produce trajectories array from ListOfBlobs

Parameters:

blobs_in_video : <ListOfBlobs object>

number_of_frames : int

Total number of frames in video

number_of_animals : int

Number of animals to be tracked

Returns:

dict

Dictionary with np.array as values (trajectories organised by identity)