topostats.tracing.tracingfuncs#

Miscellaneous tracing functions.

Classes#

getSkeleton

Skeltonisation : "A Fast Parallel Algorithm for Thinning Digital Patterns" by Zhang et al., 1984.

reorderTrace

genTracingFuncs

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#
getDNAmolHeightStats()[source]#

Get molecule heights.

doSkeletonising()[source]#

Check if the skeletonising is finished.

_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

_checkWhichHeightPoints()[source]#

Check which height points.

_initialiseHeightFindingDict()[source]#
_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

_identifyHighestPoint(x, y, index_direction, indexed_heights)[source]#
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

_binaryFinalThinCheck_a()[source]#

Binary final thin check A.

_binaryFinalThinCheck_b()[source]#

Binary final thin check B.

_binaryThinCheck_b_returncount()[source]#

Binary final thin check B return count.

pruneSkeleton()[source]#

Function to remove the hanging branches from the skeletons.

These are a persistent problem in the overall tracing process.

_findBranchEnds(coordinates)[source]#
_deleteSquareEnds(coordinates)[source]#
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

loopedCircularTrace()[source]#
loopedLinearTrace()[source]#
class topostats.tracing.tracingfuncs.genTracingFuncs[source]#
static getLocalPixelsBinary(binary_map, x, y)[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

static countandGetNeighbours(x, y, trace_coordinates)[source]#

Returns the number of neighbouring points for a coordinate and an array containing the those points

static returnPointsInArray(points_array, trace_coordinates)[source]#
static makeGrid(x, y, size)[source]#
static findBestNextPoint(x, y, ordered_points, candidate_points)[source]#
static checkVectorsCandidatePoints(x, y, ordered_points, candidate_points)[source]#

Finds which neighbouring pixel incurs the smallest angular change with reference to a previous pixel in the ordered trace, and chooses that as the next point