kwneuro.csd module

kwneuro.csd.combine_csd_peaks_to_vector_volume(csd_peaks_dirs, csd_peaks_values)

Convert CSD peaks from separate direction and value VolumeResources (e.g. Dipy format) into a single volume containing a 4D array, where the last dimension is a n_peaks*3-length vector containing the x,y,z components of each peak (e.g. MRtrix3 format). The magnitude of each vector (peak value) is stored as its length (norm). :type csd_peaks_dirs: VolumeResource :param csd_peaks_dirs: VolumeResource containing peak directions (unit vectors). :type csd_peaks_values: VolumeResource :param csd_peaks_values: VolumeResource containing peak values (amplitudes).

Returns: VolumeResource with 4D array of shape [x,y,z,n_peaks*3].

Return type:

VolumeResource

kwneuro.csd.combine_response_functions(responses)

Combines multiple response functions into a single group average using the MRtrix3 approach.

This function harmonizes subjects by scaling their SH coefficients so that the isotropic component (L=0) of each subject matches the group’s mean L=0 intensity. This ensures that differences in scanner gain or global signal intensity do not bias the shape of the resulting group-average response.

Parameters:

responses (list[ResponseFunctionResource]) – List of ResponseFunctionResource objects to be combined.

Return type:

InMemoryResponseFunctionResource

Returns: An InMemoryResponseFunctionResource containing the combined group-average response function.

kwneuro.csd.compute_csd_fods(dwi, mask, response=None, flip_bvecs_x=True, mrtrix_format=False, sh_order_max=8)

Computes Fiber Orientation Distributions (FODs) from a DWI dataset using Constrained Spherical Deconvolution (CSD).

Parameters:
  • dwi (Dwi) – The Diffusion Weighted Imaging (DWI) dataset.

  • mask (VolumeResource) – A binary brain mask volume. FODs are computed only within this mask.

  • response (Optional) – The single-fiber response function. If None, the response function is estimated using an ROI in the center of the brain mask.

  • flip_bvecs_x (bool) – Whether to flip the x-component of the b-vectors to match MRtrix3 convention. Default is True.

  • mrtrix_format (bool) – If True, converts SH coefficients between legacy-descoteaux07 and tournier07.

  • sh_order_max (int) – Maximum spherical harmonic order to use in the CSD model. Default is 8.

Return type:

ndarray

Returns: Array containing the spherical harmonic coefficients of the obtained FODs.

kwneuro.csd.compute_csd_peaks(dwi, mask, response=None, flip_bvecs_x=True, n_peaks=5, relative_peak_threshold=0.5, min_separation_angle=25)

Compute Constrained Spherical Deconvolution peaks from a DWI resource. This involves estimating the response function, fitting the CSD model, and extracting the peaks. :type dwi: Dwi :param dwi: The Diffusion Weighted Imaging (DWI) dataset. :type mask: VolumeResource :param mask: A binary brain mask volume. CSD is computed only within this mask. :type response: ResponseFunctionResource | None :param response: The single-fiber response function. If None, the response function is estimated using an ROI in the center of the brain mask. :type response: Optional :type flip_bvecs_x: bool :param flip_bvecs_x: Whether to flip the x-component of the b-vectors to match MRtrix3 convention. :type n_peaks: int :param n_peaks: Number of peaks to extract per voxel. Default is 5. :type relative_peak_threshold: float :param relative_peak_threshold: Only return peaks greater than relative_peak_threshold * m where m is the largest peak. :type min_separation_angle: float :param min_separation_angle: The minimum distance between directions. If two peaks are too close only the larger of the two is :param returned. Must be in range [0: :param 90]:

Returns: A tuple of VolumeResources containing the CSD peak directions stored as a 5-D array of shape [x,y,z,n_peaks,3], and the corresponding peak values stored as a 4D array of shape [x,y,z,n_peaks].

Return type:

tuple[VolumeResource, VolumeResource]

kwneuro.csd.estimate_response_function(dwi, mask, flip_bvecs_x=True, fa_thr=0.8, sh_order_max=8)

Estimate the single-shell single-tissue response function from a DWI dataset using the SSST method. :type dwi: Dwi :param dwi: The Diffusion Weighted Imaging (DWI) dataset. :type mask: VolumeResource :param mask: A binary brain mask volume. This is used to extract an ROI at the center of the brain. :type flip_bvecs_x: bool :param flip_bvecs_x: Whether to flip the x-component of the b-vectors to match MRtrix3 convention. :type fa_thr: float :param fa_thr: FA threshold for calculating the response function. :type sh_order_max: int :param sh_order_max: Maximum spherical harmonic order to use for the basis model. Default is 8.

Returns: A resource containing the estimated single-tissue response function.

Return type:

InMemoryResponseFunctionResource