imageruler#

Imageruler for measuring minimum lengthscales in binary images.

class imageruler.IgnoreScheme(value)[source]#

Enumerates schemes for ignoring length scale violations.

Supported schemes are:

  • NONE: a strict scheme in which no violations are ignored.

  • EDGES: ignores violations on the edges of all features.

  • LARGE_FEATURE_EDGES: ignores violations at the edges of large features only. A pixel is on the edge of a large feature if it is on the edge of the feature, and adjacent to an interior pixel. Here, interior pixels are those not on any edges.

  • LARGE_FEATURE_EDGES_STRICT: similar to LARGE_FEATURE_EDGES, but uses a more strict algorithm to detect edges and does not ignore checkerboard patterns.

imageruler.kernel_for_length_scale(length_scale)[source]#

Returns an approximately circular kernel for the given length_scale.

The kernel has shape (length_scale, length_scale), and is True for pixels whose centers lie within the circle of radius length_scale / 2 centered on the kernel. This yields a pixelated circle, which for length scales less than 3 will actually be square.

Parameters:

length_scale (int) – The length scale for which the kernel is sought.

Returns:

The approximately circular kernel.

Return type:

ndarray[Any, Any]

imageruler.length_scale_violations_solid(x, length_scale, periodic=(False, False), ignore_scheme=IgnoreScheme.LARGE_FEATURE_EDGES_STRICT, feasibility_gap_allowance=10)[source]#

Computes the length scale violations, allowing for the feasibility gap.

Parameters:
  • x (ndarray[Any, Any]) – Bool-typed rank-2 array containing the features.

  • length_scale (int) – The length scale for which violations are sought.

  • periodic (Tuple[bool, bool]) – Specifies which of the two axes are to be regarded as periodic.

  • ignore_scheme (IgnoreScheme) – Specifies what pixels are ignored when detecting violations.

  • feasibility_gap_allowance (int) – In checking whether x is feasible with a brush of size n, we also check for feasibility with larger brushes, since e.g. some features realizable with a brush n + k may not be realizable with the brush of size n. The feasibility_gap_allowance is the maximum value of `k checked. For arrays with very large features, particularly when ignoring no violations, larger values may be needed.

Returns:

The array containing violations.

Return type:

ndarray[Any, Any]

imageruler.minimum_length_scale(x, periodic=(False, False), ignore_scheme=IgnoreScheme.LARGE_FEATURE_EDGES_STRICT, feasibility_gap_allowance=10)[source]#

Identifies the minimum length scale of solid and void features in x.

The minimum length scale for solid (void) features defines the largest brush which can be used to recreate the solid (void) features in x, by convolving an array of “touches” with the brush kernel. In general if an array can be created with a given brush, then its solid and void features are unchanged by binary opening operations with that brush.

In some cases, an array that can be created with a brush of size n cannot be created with the smaller brush if size n - 1. Further, small pixel-scale violations at edges of features may be unimportant. Some allowance for these is provided via optional arguments to this function.

Parameters:
  • x (ndarray[Any, Any]) – Bool-typed rank-2 array containing the features.

  • periodic (Tuple[bool, bool]) – Specifies which of the two axes are to be regarded as periodic.

  • ignore_scheme (IgnoreScheme) – Specifies what pixels are ignored when detecting violations.

  • feasibility_gap_allowance (int) – In checking whether x is feasible with a brush of size n, we also check for feasibility with larger brushes, since e.g. some features realizable with a brush n + k may not be realizable with the brush of size n. The feasibility_gap_allowance is the maximum value of `k checked. For arrays with very large features, particularly when ignoring no violations, larger values may be needed.

Returns:

The detected minimum length scales (length_scale_solid, length_scale_void).

Return type:

Tuple[int, int]

imageruler.minimum_length_scale_solid(x, periodic=(False, False), ignore_scheme=IgnoreScheme.LARGE_FEATURE_EDGES_STRICT, feasibility_gap_allowance=10)[source]#

Identifies the minimum length scale of solid features in x.

Parameters:
  • x (ndarray[Any, Any]) – Bool-typed rank-2 array containing the features.

  • periodic (Tuple[bool, bool]) – Specifies which of the two axes are to be regarded as periodic.

  • ignore_scheme (IgnoreScheme) – Specifies what pixels are ignored when detecting violations.

  • feasibility_gap_allowance (int) – In checking whether x is feasible with a brush of size n, we also check for feasibility with larger brushes, since e.g. some features realizable with a brush n + k may not be realizable with the brush of size n. The feasibility_gap_allowance is the maximum value of `k checked. For arrays with very large features, particularly when ignoring no violations, larger values may be needed.

Returns:

The detected minimum length scale of solid features.

Return type:

int