Slice
A class that abstracts a 2D slice of a Core.
- class core_ct.slice.Slice(data: ndarray, pixel_dimensions: tuple[float, float], thickness: float = 0.0)[source]
Abstracts properties of a core slice and contains methods for manipulating it.
- __getitem__(index: slice | int | Tuple[slice | int, ...]) Slice[source]
Overloads the bracket operator ([]) to support numpy-like indexing behavior.
- Parameters:
index (slice, int, or tuple of slice and/or int) – Index to use for the slicing operation. Can be a single slice, integer, or a tuple containing a combination of slices and integers (up to 2 items total).
- Returns:
a new Slice containing the data specified via the index
- Return type:
- Raises:
IndexError – If any provided indices are out of range or the end index comes before the start index on an axis.
ValueError – If the provided index would result in a data shape other than 2D. If the provided index specifies more than 2 axes. If a step other than 1 is defined on any axis.
Examples
Trim 25 pixels off both ends of the x-axis:
trimmed = slice[25:-25]Get a Slice containing only 100th-500th pixels along the x-axis:
trimmed = slice[100:500]Trim 50 pixels off the start of the y-axis:
trimmed = slice[:, 50:]Trim 50 pixels off the end of the y-axis:
trimmed = slice[:, :-50]Trim 30 pixels from all sides:
trimmed = slice[30:-30, 30:-30]
- filter(brightness_filter: Callable[[float], bool]) Slice[source]
Get section of the slice that only contains the specified brightness values.
- Parameters:
brightness_filter (Callable[[float], bool]) – Lambda function that defines what will be filtered out. Function must either return false if the value should not be included or true if the value should be included.
- Returns:
New Slice object with only the specified brightness values left, everything else is set to nan.
- Return type: