Skip to content

TrackArray

Jian Tay edited this page Jun 15, 2021 · 3 revisions

TrackArray (Generated 09-Mar-2020 14:20:54)

Class Properties

LastID

LastID - Last assigned track ID

Get Access: protected Set Access: protected

Tracks

Tracks - Struct containing data

Get Access: public Set Access: protected

FileMetadata

FileMetadata - Struct to contain file metadata

Get Access: public Set Access: protected

CreatedOn

CreatedOn - Timestamp when object was created

Get Access: public Set Access: protected

NumTracks

TrackArray/NumTracks is a property.

Get Access: public Set Access: public

Datafields

TrackArray/Datafields is a property.

Get Access: public Set Access: public

Class Methods

saveobj

SAVEOBJ Save filter for objects. B = SAVEOBJ(A) is called by SAVE when an object is saved to a .MAT file. The return value B is subsequently used by SAVE to populate the .MAT file. SAVEOBJ can be used to convert an object that maintains information outside the object array into saveable form (so that a subsequent LOADOBJ call to recreate it).

SAVEOBJ will be separately invoked for each object to be saved.

SAVEOBJ can be overloaded only for user objects.  SAVE will not call
SAVEOBJ for a built-in datatype (such as double) even if @double/saveobj
exists.

See also SAVE, LOADOBJ.

savestruct

SAVESTRUCT Save track array as struct

SAVESTRUCT(OBJ, FILENAME) will save the object data as a struct. This enables compatibility with subclasses since MATLAB does not allow direct casting of subclasses from the superclass.

export

EXPORT Export track data to various formats

EXPORT(OBJ, OUTPUTFN) will export the track data and file metadata. The output format will be determined from the extension of the output file.

Supported output formats are: CSV

treeplot

TREEPLOT Plot track lineage as a binary tree

TREEPLOT(OBJ) will plot the tree in the current axes. By default, the tree will be plotted with branches growing upwards, and the y-axis will be the height of each node.

The tree is drawn using a grid-based algorithm, producing a plot similar to tournament brackets, where the branches in each level are evenly spaced apart.

TREEPLOT(OBJ, PROPERTY) will plot the tree with each node separated by the property specified. For example, to plot the nodes positioned by the 'distance' property: PLOT(OBJ, 'distance')

TREEPLOT(OBJ, 'direction') will plot the tree growing in the direction specified. By default, the 'direction' plotted is 'up'. The following directions are allowed: 'up' - Root is at the bottom of plot, branches grow upwards. 'down' - Root is at the top of the plot, branches grow downwards. 'right' - Root is on the left of plot, branches grow right.

TREEPLOT(OBJ, ..., 'cumuldist', true) will plot the nodes separation cumulatively.

TREEPLOT(OBJ, ..., 'symmetric') will scale the non-data axis so that the tree is centered in the figure. This could make plots with missing branches look better.

Implementation notes:

  • During the first part of the code, the algorithm assigns X and Y values to each node in the tree, defined as though the tree is growing upwards. To get the tree growing in different directions, these X and Y values are rotated before plotting.

The following describe the basic principles of the algorithm:

  • The tree is traversed in a single breadth-first traverse, to assign a position to each node.

  • At the lowest levels, the nodes should be spaced evenly apart. Thus the maximum width of the tree (in pixels) will be 2 x 2^K - 1 (-1 because one of the edges is not drawn). K is the maximum height of the tree (h = 0 is the root node).

  • The root should be at the very center of the tree, so root position should be (2 * 2^K)/2 = 2^K.

  • To keep each parent centered over its children, each child node should be moved by +/- 2^(K - h) compared to the parent (e.g. in a 2 height tree, level 1 moves 2 steps away, level 2 moves 1 step away).

  • Missing branches should be treated as though they exist and no nodes should pass through the space.

  • Because each node is spaced progressively further apart, the algorithm does not produce overlapping node positions.

  • If nodes are labelled, the root and leaf nodes will appear outside the border of the image.

traverse

TRAVERSE Return track IDs in specified order

M = TRAVERSE(OBJ, ROOTTRACKID) will traverse the tree in the specified order, returning track IDs in the vector M.

Currently, only preorder traversal is supported, e.g. the order starts with the root, then down the left tree, then the right tree.

getTrack

GETTRACK Get track or specific frames from track

S = getTrack(obj, trackID) will return track data as a struct S.

S = getTrack(obj, trackID, FRAME) will return a specific frame as a struct S.

Specifically, this method moves the Data struct into the main track structure, and reformats the struct into matrices as appropriate.

Example: Say input track has the following fields IN.ID = 1; IN.MotherID = NaN; IN.DaughterID = NaN; IN.Frames = [1, 2, 4]; IN.Data.Length = {10, [], 40}; IN.Data.PxIdxList = {[10, 30, 50], [10, 20], [80, 90]}; IN.Data.Centroid = {[5, 2], [6, 7], [8, 10]};

The output track will have: OUT.ID = 1; OUT.MotherID = NaN; OUT.DaughterID = NaN; OUT.Frames = [1, 2, 4]; OUT.Length = [10; NaN; 40]; OUT.PxIdxList = {[10, 30, 50], [10, 20], [80, 90]}; OUT.Centroid = [5, 2; 6, 7; 8, 10];

splitTrack

SPLITTRACK Split an existing track at a specific frame

OBJ = SPLITTRACK(OBJ, TRACKID, FRAME) will split the track specified by TRACKID at the frame FRAME. A new track will be created containing the data from FRAME+1...END.

[OBJ, NEWTRACK] = SPLITTRACK(...) will also return the ID of the new track (the new track is created at the end of the array).

This function is used primarily during track assignment if a division event was detected to split the mother-daughter track.

Example: %Split track 5 at frame 3 OBJ = SPLITTRACK(OBJ, 5, 3);

deleteFrame

DELETEFRAME Remove a frame from a track

OBJ = DELETEFRAME(OBJ, TRACKID, FRAME) deletes data from a frame.

deleteTrack

DELETETRACK Remove a track

A.DELETETRACK(trackIndex) will remove the TrackData object at the index specified.

updateTrack

UPDATETRACK Update the specified track

OBJ = UPDATETRACK(OBJ, TRACKID, FRAME, S) will update the data stored for the track with TRACKID. The frame(s) which should be modified can be specified by FRAME. S should be a struct specifying the new data.

Multiple frames can be replaced at once by supplying a vector for FRAME. S must either be a single-element struct, in which case all specified frames will be overwritten with the same struct, or S must have the same number of elements as FRAME.

setDaughterID

Check that track exists

setMotherID

Check that track exists

addTrack

ADDTRACK Add a track to the array

ADDTRACK(OBJ, FRAME, S) will add a new track to the Data property, starting at the specified FRAME. The new track data S must be a struct. Note that fieldnames are case-sensitive.

setFileMetadata

SETFILEMETADATA Set file metadata fields

OBJ = SETFILEMETADATA(OBJ, PARAM, VALUE, ...) sets the FileMetadata property. The inputs must be parameter name/value pairs.

Example: A = TrackArray; A = setFileMetadata(A, 'Filename', 'test.nd2'); A.FileMetadata.Filename

numel

Equal to NumTracks

loadobj

LOADOBJ Load filter for objects. B = LOADOBJ(A) is called by LOAD when an object is loaded from a .MAT file. The return value B is subsequently used by LOAD to populate the workspace. LOADOBJ can be used to convert one object type into another, to update an object to match a new object definition, or to restore an object that maintains information outside of the object array.

If the input object does not match the current definition (as defined
by the constructor function), the input will be a struct-ized version
of the object in the .MAT file.  All the information in the original
object will be available for use in the conversion process.

LOADOBJ will be separately invoked for each object in the .MAT file.

LOADOBJ can be overloaded only for user objects.  LOAD will not call
LOADOBJ for a built-in datatype (such as double) even if @double/loadobj 
exists.

See also LOAD, SAVEOBJ.

exportToCSV

EXPORTTOCSV Export track and filemetadata as CSV files

EXPORTTOCSV(OBJ, FN) exports the data as a CSV file.

findtrack

FINDTRACK Returns track index

INDEX = FINDTRACK(OBJ, TRACKID, STOP_ON_ERROR) returns the track index if it exists.

If STOP_ON_ERROR is true (default: false), the method will throw an error if the track is not found. Otherwise it will return an empty matrix.

TrackArray

TRACKARRAY Data class representing an array of tracks

TRACKARRAY is a data class representing an array of tracks containing timeseries data from the LAPLinker class . Each track is modelled as a binary linked list, where each "mother" track is connected to two "daughter" tracks. The data class is built to be extensible to enable custom data structures.

TRACKARRAY holds track information in the property Tracks. Each track has the following basic structure: ID - A unique number that is given to each track in the array MotherID - ID of the mother track (if a division occured) DaughterID - ID of the daughter tracks (if a division occured) Frames - A vector contraining a list of frames containing data Data - A struct that contains the time-series data

TRACKARRAY Methods: numel - Number of tracks in array setFileMetadata - Set file metadata information (e.g. pixel size, timestamps) addTrack - Add a track setMotherID - Set mother ID of a track setDaughterID - Set daughter ID of a track deleteTrack - Delete track from array getTrack - Get a specified track updateTrack - Update specified frames of a track deleteFrame - Delete frame(s) from a track splitTrack - Split a track into two at specified frame traverse - Traverses the track structure, returning track IDs in order specified treeplot - Generates a plot of the track structure starting from a specific root node export - Export data in a specific format (e.g. CSV) savestruct - Save data as a struct

TRACKARRAY Properties: FileMetadata - Structure containing user-defined metadata CreatedOn - Time and date the object was created on NumTracks - Number of tracks in array Datafields - Cell list of fieldnames of timeseries data (excludes the common data fields listed above)

empty

Returns an empty object array of the given size