pymuster.core package
Submodules
pymuster.core.field_calculus module
Containing useful functions for field calculus
- pymuster.core.field_calculus.curl(J)
- Returns the curl of a 3D field :param J: Jacobian of shape (batch_size, 3, 3, x, y, z) 
- pymuster.core.field_calculus.determinant(J)
- Computes the determinant of a 3x3 matrix 
- pymuster.core.field_calculus.divergence(J)
- Returns the divergence of a 3D field :param J: Jacobian of shape (batch_size, 3, 3, x, y, z) 
- pymuster.core.field_calculus.forward_alpha(v_t, sp_tr, n_iter, dt=1)
- helper function for step (4): Calculation of forward flows @param v_t: the velocity field @param sp_tr: the spatial transformer @return: 
- pymuster.core.field_calculus.integrate_forward_flow(v, sp_tr, n_iter=5, dt=1)
- implements step (4): Calculation of forward flows @return: 
- pymuster.core.field_calculus.jacobian(x, pix_dim=(1.0, 1.0, 1.0), filter=False, midpoint=False)
- Calculates the Jacobian of a 3D field :param x: tensor of shape (batch_size, channels, x, y, z) - Returns:
- jacobian of shape (batch_size, 3, channels, x, y, z) 
- Return type:
- J 
 
- pymuster.core.field_calculus.laplacian(J, pix_dim=(1.0, 1.0, 1.0))
- Return the second order jacobian of a field 
pymuster.core.losses module
- class pymuster.core.losses.Fourier(filter_omega, img_size, pix_dim)
- Bases: - object- Spatial jacobian loss using the fourier space. - Parameters:
- filter_omega (float) – The cutoff frequency of the filter 
- img_size (tuple) – The size of the image 
- pix_dim (tuple) – The pixel dimensions of the image 
 
 - filter(y)
 - loss(y_true, y_pred, mask=None)
 
- class pymuster.core.losses.GaussNCC(filter_omega, img_size, pix_dim, reduce=True, scale_invariant=True)
- Bases: - object- loss(y_true, y_pred, mask=None)
 
- class pymuster.core.losses.GroupVELLN(kernal_size=7, kernal_type='gaussian', pix_dim=(1, 1, 1), img_size=(256, 256, 256))
- Bases: - object- Variance Estimating Local Linear compansated Normal distribution loss - Parameters:
- kernal_size (int) – The size of the kernal used for calculating the local mean 
 - loss(images, masks=None)
- Parameters:
- y_true (torch.Tensor) – The true field 
- y_pred (torch.Tensor) – The predicted field 
- mask (torch.Tensor) – The mask used for calculating the loss 
 
 
 
- class pymuster.core.losses.LogLinLoss(kernal_size=7, kernal_type='gaussian', pix_dim=(1, 1, 1), img_size=(256, 256, 256), log_transform=True)
- Bases: - object- Assuming I_ix = a_i I_x e find the I_ix that maximizes the likelihood of this model - Parameters:
- kernal_size (int) – The size of the kernal used for calculating the local mean 
 - loss(images, masks=None, sigma_beta=1.0)
- Parameters:
- images (torch.Tensor) – the images warped to the same space 
- mask (torch.Tensor) – The mask used for calculating the loss 
 
 
 
- class pymuster.core.losses.MSE
- Bases: - object- Mean squared error loss. - loss(y_true, y_pred, mask=None)
 
- class pymuster.core.losses.MutualInformation(sigma=0.1, num_bins=256, normalize=True, reduce=True)
- Bases: - Module- getMutualInformation(input1, input2)
- input1: B, C, H, W, D input2: B, C, H, W, D - return: scalar 
 - jointPdf(kernel_values1, kernel_values2)
 - loss(y_true, y_pred)
 - marginalPdf(values)
 
- class pymuster.core.losses.NCC(kernal_size=7, reduce=True, scale_invariant=True)
- Bases: - object- Normalized Local Cross Correlation. - Parameters:
- kernal_size (int) – The size of the kernal used for calculating the local mean 
 - loss(y_true, y_pred, mask=None)
- Parameters:
- y_true (torch.Tensor) – The true field 
- y_pred (torch.Tensor) – The predicted field 
- mask (torch.Tensor) – The mask used for calculating the loss 
 
 
 
- class pymuster.core.losses.NCCS(kernal_size=13)
- Bases: - object- NCC with Sobel filter. See: https://doi.org/10.3390/app12062828 - Parameters:
- kernal_size (int) – The size of the kernal used for calculating the local mean 
 - loss(y_true, y_pred, mask=None)
 
- class pymuster.core.losses.VELLN(kernal_size=7, kernal_type='gaussian', pix_dim=(1, 1, 1), img_size=(256, 256, 256))
- Bases: - object- Variance Estimating Local Linear compansated Normal distribution loss - Parameters:
- kernal_size (int) – The size of the kernal used for calculating the local mean 
 - loss(y_true, y_pred, sigma_true, sigma_pred, mask=None)
- Parameters:
- y_true (torch.Tensor) – The true field 
- y_pred (torch.Tensor) – The predicted field 
- mask (torch.Tensor) – The mask used for calculating the loss 
 
 
 
- pymuster.core.losses.fourier_filter(img, filter_response, dims=(-3, -2, -1))
pymuster.core.utils module
- class pymuster.core.utils.RunningMeanVar(n=10)
- Bases: - object- This class is used to calculate the mean and variance of the n last values .. rubric:: Example - >>> rmv = RunningMeanVar(n=10) >>> for i in range(100): >>> rmv.add(i) >>> print(rmv.mean()) - Parameters:
- n – The number of values to use for calculating the mean and variance 
 - add(value)
- Add a value to the running mean and variance :param value: The value to add 
 - mean()
- Returns: The mean of the last n values 
 - var()
- Returns: The variance of the last n values 
 
- pymuster.core.utils.VectorPearsonCorrelation(x, y)
- Calculates the Pearson correlation between two vectors sets :param x: (num_samples, num_features) :param y: (num_samples, num_features) 
- pymuster.core.utils.get_color_wheel(x, y, r, rgb)
- Create a color wheel :param x: x coordinate of the center of the color wheel :param y: y coordinate of the center of the color wheel :param r: radius of the color wheel :param rgb: rgb color of the color wheel 
- pymuster.core.utils.get_dig_ind(N, offset)
- Returns the indices of the diagonal elements of the offset diagonal matrices. 
- pymuster.core.utils.grid(grid_size, grid_interval)
- Constructs a 3d image of a grid with a given size For visualization purposes :param grid_size: (x, y, z) :param grid_interval: The interval between the grid lines 
- pymuster.core.utils.plot_vector_field(deformation, axis, slice_in=None, vmax=None, color_wheel=True)
- Visualize a vector field :param deformation: 3d tensor of shape [x, y, z, 3] :param slice_ind: slice to visualize :param axis: axis to visualize 
- pymuster.core.utils.render_brain(img, theta, chi, N, zoom, gpu=False, alpha_mask=None)
- Renderer for 3d brain output_image :param img: 3d brain image [x, y, z] :param theta: viewing angle rotate :param chi: viewing angle up and down :param N: camera grid resolution in x axis :param zoom: zoom factor 
- pymuster.core.utils.view_brain(img, view_3d=False, gpu=False, vmax=None)
- Visualize brain output_image :param img: 3d brain image tensor or numpy array [x, y, z] :param view_3d: if True, show 3d brain image 
- pymuster.core.utils.view_stacked_brains(imgs, n, view_3d=False, gpu=False)
- Place n brain views in a row :param imgs: tensor or numpy array of shape (n, 1, x, y, z) :param n: number of brain views to place in a row, is set to batch size if n > batch size :param view_3d: if True, render the 3d view. Might be slow