StrokeSegLab
Loading...
Searching...
No Matches
StrokeSegLab.preprocessing.resampling.Resampler Class Reference

Public Member Functions

None __init__ (self)
 
np.ndarray run (self, np.ndarray data, tuple[float, float, float] current_spacing, tuple[float, float, float] new_spacing)
 

Public Attributes

float separate_z_anisotropy_threshold = 3.0
 
 force_separate_z = None
 
bool is_seg = False
 
int order = 1
 
int order_z = 0
 
np.ndarray force_separate_z = self._get_lowres_axis(current_spacing)
 

Protected Member Functions

tuple[bool, int] _determine_do_sep_z_and_axis (self, tuple[float, float, float] current_spacing, tuple[float, float, float] new_spacing)
 
np.ndarray _get_lowres_axis (self, tuple[float, float, float] new_spacing)
 
bool _get_do_separate_z (self, tuple[float, float, float] spacing)
 
np.ndarray _compute_new_shape (self, np.ndarray old_shape, tuple[float, float, float] old_spacing, tuple[float, float, float] new_spacing)
 
np.ndarray _resample_data_or_seg (self, np.ndarray data, np.ndarray new_shape, int axis, bool do_separate_z, np.dtype dtype_out=None)
 

Detailed Description

This class handle the resampling during the preprocessing and postprocessing

Constructor & Destructor Documentation

◆ __init__()

None StrokeSegLab.preprocessing.resampling.Resampler.__init__ ( self)
Initialize the resampler class

Member Function Documentation

◆ _compute_new_shape()

np.ndarray StrokeSegLab.preprocessing.resampling.Resampler._compute_new_shape ( self,
np.ndarray old_shape,
tuple[float,float,float] old_spacing,
tuple[float,float,float] new_spacing )
protected
@public
Computes the new shape of data after resampling to a new spacing
Scales each dimension according to the ratio of old and new spacing values

Args:
    old_shape (np.ndarray): Current shape of the data
    old_spacing (tuple[float,float,float]): Current spacing in mm (sx, sy, sz) 
    new_spacing (tuple[float,float,float]): Desired spacing in mm (sx, sy, sz)

Returns:
    np.ndarray: Future shape of the resempled data

◆ _determine_do_sep_z_and_axis()

tuple[bool,int] StrokeSegLab.preprocessing.resampling.Resampler._determine_do_sep_z_and_axis ( self,
tuple[float,float,float] current_spacing,
tuple[float,float,float] new_spacing )
protected
@public
Decides if resampling should be done separately along the z-axis and finds the right axis
The choice is based on the force_separate_z attribute and the spacing values. If force_separate_z is set, it is used first. If not, the method checks if the current or new spacing needs separate resampling in the z direction

Args:
    current_spacing (tuple[float,float,float]): Current spacing in mm (sx, sy, sz)
    new_spacing (tuple[float,float,float]): Desired spacing in mm (sx, sy, sz)

Returns:
    tuple[bool,int]:
    - True if separate resampling along the z-axis should be done
    - The axis to resample separately, or None if not needed

◆ _get_do_separate_z()

bool StrokeSegLab.preprocessing.resampling.Resampler._get_do_separate_z ( self,
tuple[float,float,float] spacing )
protected
@public
 It compares the ratio between the max and min spacing values to a threshold (separate_z_anisotropy_threshold)

Args:
    spacing (tuple[float,float,float]): Spacing in mm (sx, sy, sz)

Returns:
    bool: True if the ratio is higher than the threshold

◆ _get_lowres_axis()

np.ndarray StrokeSegLab.preprocessing.resampling.Resampler._get_lowres_axis ( self,
tuple[float,float,float] new_spacing )
protected
@public
Finds which axis has the biggest spacing (=the lowest resolution)

Args:
    new_spacing (tuple[float,float,float]): Spacing in mm (sx, sy, sz)

Returns:
    np.ndarray: The indices of the axis with the biggest spacing

◆ _resample_data_or_seg()

np.ndarray StrokeSegLab.preprocessing.resampling.Resampler._resample_data_or_seg ( self,
np.ndarray data,
np.ndarray new_shape,
int axis,
bool do_separate_z,
np.dtype dtype_out = None )
protected
@public
Resample image or segmentation data to a new shape, optionally resampling separately along an anisotropic axis

Args:
    data (np.ndarray): Input array of shape (c, x, y, z)
    new_shape (np.ndarray): Future shape of the resempled data
    axis (int): The axis to resample separately, or None if not needed
    do_separate_z (bool): True if separate resampling along the z-axis should be done
    dtype_out (np.dtype, optional): Output data type. Defaults to None.

Returns:
    np.ndarray: Output data array of shape (c, x, y, z)

◆ run()

np.ndarray StrokeSegLab.preprocessing.resampling.Resampler.run ( self,
np.ndarray data,
tuple[float,float,float] current_spacing,
tuple[float,float,float] new_spacing )
Resamples the input data to a new spacing

Args:
    data (np.ndarray): Input array of shape (c, x, y, z)
    current_spacing (tuple[float,float,float]): Current spacing in mm (sx, sy, sz)
    new_spacing (tuple[float,float,float]): Desired spacing in mm (sx, sy, sz)

Returns:
    np.ndarray: The resampled data 

The documentation for this class was generated from the following file: