FastSurferCNN.data_loader.conform¶
- FastSurferCNN.data_loader.conform.check_affine_in_nifti(img, logger=None)[source]¶
Check the affine in nifti Image.
Sets affine with qform, if it exists and differs from sform. If qform does not exist, voxel sizes between header information and information in affine are compared. In case these do not match, the function returns False (otherwise True).
- Parameters:
- img
Union
[nib.Nifti1Image
,nib.Nifti2Image
] Loaded nifti-image.
- logger
Optional
[logging.Logger
] Logger object or None (default) to log or print an info message to stdout (for None).
- img
- Returns:
bool
False, if voxel sizes in affine and header differ.
- FastSurferCNN.data_loader.conform.find_img_size_by_fov(img, vox_size, min_dim=256)[source]¶
Find the cube dimension (>= 256) to cover the field of view of img.
If vox_size is one, the img_size MUST always be min_dim (the FreeSurfer standard).
- Parameters:
- Returns:
int
The number of voxels needed to cover field of view.
Notes
This function only needs the header (not the data).
- FastSurferCNN.data_loader.conform.find_min_size(img, max_size=1)[source]¶
Find minimal voxel size <= 1mm.
- Parameters:
- img
nib.analyze.SpatialImage
Loaded source image.
- max_size
float
Maximal voxel size in mm (default: 1.0).
- img
- Returns:
float
Rounded minimal voxel size.
Notes
This function only needs the header (not the data).
- FastSurferCNN.data_loader.conform.get_conformed_vox_img_size(img, conform_vox_size, conform_to_1mm_threshold=None)[source]¶
Extract the voxel size and the image size.
This function only needs the header (not the data).
- Parameters:
- img
nib.analyze.SpatialImage
Loaded source image.
- conform_vox_size
float
, “min” The voxel size parameter to use: either a voxel size as float, or the string “min” to automatically find a suitable voxel size (smallest per-dimension voxel size).
- conform_to_1mm_threshold
float
,optional
The threshold for which image voxel size should be conformed to 1mm instead of conformed to the smallest voxel size (default: None, never apply).
- img
- Returns:
- FastSurferCNN.data_loader.conform.getscale(data, dst_min, dst_max, f_low=0.0, f_high=0.999)[source]¶
Get offset and scale of image intensities to robustly rescale to dst_min..dst_max.
Equivalent to how mri_convert conforms images.
- Parameters:
- data
np.ndarray
Image data (intensity values).
- dst_min
float
Future minimal intensity value.
- dst_max
float
Future maximal intensity value.
- f_low
float
, default=0.0 Robust cropping at low end (0.0=no cropping).
- f_high
float
, default=0.999 Robust cropping at higher end (0.999=crop one thousandth of highest intensity).
- data
- Returns:
- FastSurferCNN.data_loader.conform.is_lia(affine, strict=True, eps=1e-06)[source]¶
Checks whether the affine is LIA-oriented.
- Parameters:
- affine
np.ndarray
The affine to check.
- strict
bool
, default=True Whether the orientation should be “exactly” LIA or just similar to LIA (i.e. it is more LIA than other directions).
- eps
float
, default=1e-6 The threshold in strict mode.
- affine
- Returns:
bool
Whether the affine is LIA-oriented.
- FastSurferCNN.data_loader.conform.is_resampling_vox2vox(vox2vox, eps=1e-06)[source]¶
Check whether the affine is resampling or just reordering.
- Parameters:
- vox2vox
np.ndarray
The affine matrix.
- eps
float
, default=1e-6 The epsilon for the affine check.
- vox2vox
- Returns:
bool
The result.
- FastSurferCNN.data_loader.conform.map_image(img, out_affine, out_shape, ras2ras=None, order=1, dtype=None)[source]¶
Map image to new voxel space (RAS orientation).
- Parameters:
- img
nib.analyze.SpatialImage
The src 3D image with data and affine set.
- out_affine
np.ndarray
Trg image affine.
- out_shape
tuple
[int
, …],np.ndarray
The trg shape information.
- ras2ras
np.ndarray
,optional
An additional mapping that should be applied (default=id to just reslice).
- order
int
, default=1 Order of interpolation (0=nearest,1=linear,2=quadratic,3=cubic).
- dtype
Type
,optional
Target dtype of the resulting image (relevant for reorientation, default=keep dtype of img).
- img
- Returns:
np.ndarray
Mapped image data array.
- FastSurferCNN.data_loader.conform.options_parse()[source]¶
Command line option parser.
- Returns:
options
Object holding options.
- FastSurferCNN.data_loader.conform.rescale(data, dst_min, dst_max, f_low=0.0, f_high=0.999)[source]¶
Rescale image intensity values (0-255).
- Parameters:
- data
np.ndarray
Image data (intensity values).
- dst_min
float
Future minimal intensity value.
- dst_max
float
Future maximal intensity value.
- f_low
float
, default=0.0 Robust cropping at low end (0.0=no cropping).
- f_high
float
, default=0.999 Robust cropping at higher end (0.999=crop one thousandth of highest intensity).
- data
- Returns:
np.ndarray
Scaled image data.
- FastSurferCNN.data_loader.conform.scalecrop(data, dst_min, dst_max, src_min, scale)[source]¶
Crop the intensity ranges to specific min and max values.
- Parameters:
- data
np.ndarray
Image data (intensity values).
- dst_min
float
Future minimal intensity value.
- dst_max
float
Future maximal intensity value.
- src_min
float
Minimal value to consider from source (crops below).
- scale
float
Scale value by which source will be shifted.
- data
- Returns:
np.ndarray
Scaled image data.