topostats.tracing.tracingfuncs#
Miscellaneous tracing functions.
Classes#
Skeltonisation : "A Fast Parallel Algorithm for Thinning Digital Patterns" by Zhang et al., 1984. |
|
Module Contents#
- class topostats.tracing.tracingfuncs.getSkeleton(image_data: numpy.typing.NDArray, binary_map: numpy.typing.NDArray, number_of_columns: int, number_of_rows: int, pixel_size: float)[source]#
Skeltonisation : “A Fast Parallel Algorithm for Thinning Digital Patterns” by Zhang et al., 1984.
- Parameters:
image_data (npt.NDArray) – Image to be traced.
binary_map (npt.NDArray) – Image mask.
number_of_columns (int) – Number of columns.
number_of_rows (int) – Number of rows.
pixel_size (float) – Pixel to nm scaling.
- image_data#
- binary_map#
- number_of_columns#
- number_of_rows#
- pixel_size#
- p2 = 0#
- p3 = 0#
- p4 = 0#
- p5 = 0#
- p6 = 0#
- p7 = 0#
- p8 = 0#
- mask_being_skeletonised = []#
- output_skeleton = []#
- skeleton_converged = False#
- pruning = True#
- average_height = 0#
- highest_points#
- search_window#
- dir_search#
- _doSkeletonisingIteration()[source]#
Do an iteration of skeletonisation.
Check for the local binary pixel environment and assess the local height values to decide whether to delete a point.
- _deletePixelSubit1(point: numpy.typing.NDArray) bool [source]#
Check whether a point should be deleted based on local binary environment and local height values.
- Parameters:
point (npt.NDArray) – Point to be checked.
- Returns:
Whether the point should be deleted.
- Return type:
bool
- _deletePixelSubit2(point: numpy.typing.NDArray) bool [source]#
Check whether a point should be deleted based on local binary environment and local height values.
- Parameters:
point (npt.NDArray) – Point to be checked.
- Returns:
Whether the point should be deleted.
- Return type:
bool
- _binaryThinCheck_a() bool [source]#
Binary thin check A.
- Returns:
Whether the condition is met.
- Return type:
bool
- _binaryThinCheck_b() bool [source]#
Binary thin check B.
- Returns:
Whether the condition is met.
- Return type:
bool
- _binaryThinCheck_c() bool [source]#
Binary thin check C.
- Returns:
Whether the condition is met.
- Return type:
bool
- _binaryThinCheck_d() bool [source]#
Binary thin check D.
- Returns:
Whether the condition is met.
- Return type:
bool
- _binaryThinCheck_csharp() bool [source]#
Binary thin check C#.
- Returns:
Whether the condition is met.
- Return type:
bool
- _binaryThinCheck_dsharp() bool [source]#
Binary thin check D#
- Returns:
Whether the condition is met.
- Return type:
bool
- _checkHeights(candidate_points: numpy.typing.NDArray) numpy.typing.NDArray [source]#
Check heights.
- Parameters:
candidate_points (npt.NDArray) - > npt.NDArra) – Candidate points to be checked.
- Returns:
Candidate points.
- Return type:
npt.NDArray
- _getHorizontalLeftHeights(x: int, y: int) float [source]#
Calculate heights left (west).
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height left (west).
- Return type:
float
- _getHorizontalRightHeights(x, y)[source]#
Calculate heights right (east).
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height right (east).
- Return type:
float
- _getVerticalUpwardHeights(x, y)[source]#
Calculate heights upwards (north).
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height upwards (north).
- Return type:
float
- _getVerticalDonwardHeights(x, y)[source]#
Calculate heights downwards (south).
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height downwards (south).
- Return type:
float
- _getDiaganolLeftUpwardHeights(x, y)[source]#
Calculate heights diagonal left upwards (north east).
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height to diagonal left upwards (north east).
- Return type:
float
- _getDiaganolLeftDownwardHeights(x, y)[source]#
Calculate heights diagonal left downwards (south west).
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height diagonal left downwards (south west).
- Return type:
float
- _getDiaganolRightUpwardHeights(x: int, y: int) float [source]#
Calculate heights diagonal right upwards (north east).
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height diagonal right upwards (north east).
- Return type:
float
- _getDiaganolRightDownwardHeights(x, y)[source]#
Calculate heights diagonal right downwards (south east).
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height heights diagonal right downwards (south east).
- Return type:
float
- _condemnPoint(x: int, y: int) float [source]#
Condemn a point.
- Parameters:
x (int) – X coordinate.
y (int) – Y coordinate.
- Returns:
Height to be condemned.
- Return type:
float
- finalSkeletonisationIteration()[source]#
A final skeletonisation iteration that removes “hanging” pixels.
Examples of such pixels are:
[0, 0, 0] [0, 1, 0] [0, 0, 0] [0, 1, 1] [0, 1, 1] [0, 1, 1]
case 1: [0, 1, 0] or case 2: [0, 1, 0] or case 3: [1, 1, 0]
This is useful for the future functions that rely on local pixel environment to make assessments about the overall shape/structure of traces
- class topostats.tracing.tracingfuncs.reorderTrace[source]#
- static linearTrace(trace_coordinates)[source]#
My own function to order the points from a linear trace.
This works by checking the local neighbours for a given pixel (starting at one of the ends). If this pixel has only one neighbour in the array of unordered points, this must be the next pixel in the trace – and it is added to the ordered points trace and removed from the remaining_unordered_coords array.
If there is more than one neighbouring pixel, a fairly simple function (checkVectorsCandidatePoints) finds which pixel incurs the smallest change in angle compared with the rest of the trace and chooses that as the next point.
This process is repeated until all the points are placed in the ordered trace array or the other end point is reached.
- static circularTrace(trace_coordinates)[source]#
An alternative implementation of the linear tracing algorithm but with some adaptations to work with circular dna molecules
- static circularTrace_old(trace_coordinates)[source]#
Reorders the coordinates of a trace from a circular DNA molecule (with no loops) using a polar coordinate system with reference to the center of mass
I think every step of this can be vectorised for speed up
This is vulnerable to bugs if the dna molecule folds in on itself slightly
- class topostats.tracing.tracingfuncs.genTracingFuncs[source]#
-
- static countNeighbours(x, y, trace_coordinates)[source]#
Counts the number of neighbouring points for a given coordinate in a list of points
- static getNeighbours(x, y, trace_coordinates)[source]#
Returns an array containing the neighbouring points for a given coordinate in a list of points