Module ukat.utils.tools
This module contains multiple auxiliary functions that might be used by multiple algorithms
Functions
def convert_to_pi_range(pixel_array)
-
Rescale the image values to the interval [-pi, pi].
Parameters
pixel_array
:np.ndarray
Returns
radians_array
:np.ndarray
- An array containing with the same shape as pixel_array scaled to the range [-pi, pi].
def mask_slices(shape, slices, mask=None)
-
Get mask to limit processing to specific slices.
This function allows to quickly get a mask of Trues of the right shape to limit processing to specific slices. If
mask
is provided it outputs a new mask corresponding to the input mask but only on the specified slices.Parameters
shape
:tuple
- shape of mask to be created
slices
:int
orlist (of ints)
- slice indices where mask is to be True
mask
:np.ndarray (of booleans)
- original mask, if provided this function will return a mask of Falses
in all elements except at the locations of the True elements of this
mask
in the slices given byslices
Returns
np.ndarray (of booleans)
def rescale_b1_map(b1_map)
-
Some method of estimating B1 cannot distinguish B1 values x degrees over the nominal flip angle from x degrees under the nominal flip angle. It can therefore be useful to reflect all values over 100% of the nominal flip angle. To avoid confusion between reflected and un-reflected B1 maps, this function is designed to take B1 maps as a percentage of the nominal flip angle and output them as a ratio between 0 and 1.
Parameters
b1_map
:np.ndarray
- B1 map in percentage of nominal flip angle.
Returns
b1_scaled
:np.ndarray
- B1 map scaled to the range [0, 1] where flip angles over 100% are reflected back.
def resize_array(pixel_array, factor=1, target_size=None)
-
Resizes the given pixel_array, using target_size as the reference of the resizing operation (if None, then there's no resizing). This method applies a resize_factor to the first 2 axes of the input array. The remaining axes are left unchanged. Example 1: (10, 10, 2) => (5, 5, 2) with resize_factor = 0.5 Example 2: (10, 10, 10, 2) => (20, 20, 10, 2) with resize_factor = 2
Parameters
pixel_array
:np.ndarray
factor
:boolean
- Optional input argument. This is the resize factor defined by the user and it is applied in the scipy.ndimage.zoom
target_size
:boolean
- Optional input argument. By default, this script does not apply the scipy wrap_around in the input image.
Returns
resized_array
:np.ndarray where the size
ofthe first 2 dimensions
- is np.shape(pixel_array) * factor. The remaining dimensions (or axes) will have a the same size as in pixel_array.