axeap.utils package

axeap.utils.utils module

Utility functions.

This file contains generic utility functions for doing simple simple math or string operations.

axeap.utils.utils.getCoordsFromImage(image, area=None, subsample=None)[source]

Gets the list of non-zero pixels from an image.

Parameters
  • image (array_like) – 2D array of intensity values, indexable as image[x][y].

  • area (array_like, optional) – Rectangular area to extract coordinates of, given as bottom left corner and top right corner in form [[x1,y1],[x2,y2]].

  • subsample (float, optional) – Fraction of points to randomly sample and return, default is to return all points.

Returns

List of points in the form (x,y,z) where x and y are the pixel position and z is the pixel value.

Return type

list

axeap.utils.utils.get_trailing_number(s, default=None)[source]

Get number at the end of a string.

Used primarily for extracting number from filename. For example, a file whose stem is ‘Image021’ will have the number 21 extracted.

Parameters
  • s (str) – String to get trailing number from.

  • default (any, optional) – Default value to return if no number found.

Returns

Number extracted from end of string.

Return type

int

axeap.utils.utils.linearlen(s)[source]

Get length of a span from endpoints of span.

Note

Used to make some code look nicer, but may be removed in future due it being a very simple operation.

Parameters

s (array_like) – Span in form [x1,x2] where x1 and x2 are ends of span.

Returns

Length of span as absolute difference between x1 and x2.

Return type

number

axeap.utils.utils.linearoverlap(l1, l2)[source]

Get overlap between two ranges as fraction of length of each range.

Parameters
  • l1 (array_like) – First range, given in form [x1,x2] where x1 and x2 are ends of range.

  • l2 (array_like) – Second range, same form as l1.

Returns

Fraction of each range that overlaps with the other, in form (fraction of l1 that overlaps, fraction of l2 that overlaps).

Return type

tuple

axeap.utils.utils.separateSpans(spans, buffer)[source]

Remove overlap between spans.

Parameters
  • spans (array_like) – List of spans in form [x1,x2] where x1 and x2 are endpoints of span.

  • buffer (float) – Amount of space to separate overlapping spans by, must be a positive number.

Returns

List of spans after being separated.

Return type

list