HypVINN.utils.img_processing_utils¶
- HypVINN.utils.img_processing_utils.get_clean_labels(segmentation)[source]¶
Get clean labels by removing non-connected components from a dilated mask and any connected component with size less than 3.
- Parameters:
- segmentation
np.ndarray The segmentation mask.
- segmentation
- Returns:
- clean_seg:
np.ndarray The cleaned segmentation mask.
- labels_cc:
np.ndarray The labels of the connected components in the segmentation mask.
- clean_seg:
- HypVINN.utils.img_processing_utils.get_clean_mask(segmentation, optic=False)[source]¶
Get a clean mask by removing non-connected components from a dilated mask.
This function takes a segmentation mask and an optional boolean flag indicating whether to consider optic labels. It removes not connected components from the segmentation mask and returns the cleaned segmentation mask, the labels of the connected components, and a flag indicating whether to save the mask.
- Parameters:
- segmentation
np.ndarray The input segmentation mask.
- optic
bool, default=False A flag indicating whether to consider optic labels. Default is False.
- segmentation
- Returns:
- clean_seg
np.ndarray The cleaned segmentation mask.
- labels_cc
np.ndarray The labels of the connected components in the segmentation mask.
- savemask
bool A flag indicating whether to save the mask.
- clean_seg
- HypVINN.utils.img_processing_utils.img2axcodes(img)[source]¶
Convert the affine matrix of an image to axis codes.
This function takes an image as input and returns the axis codes corresponding to the affine matrix of the image.
- HypVINN.utils.img_processing_utils.save_logits(logits, orig_path, ras_affine, ras_header, save_dir, mode)[source]¶
Save the logits (raw model outputs) as a NIfTI image.
This function takes the logits, reorients the image to match the original image’s orientation, and saves the results.
- Parameters:
- logits
npt.NDArray[float] The raw model outputs.
- orig_path
Path The path to the original image.
- ras_affine
npt.NDArray[float] The affine transformation of the RAS orientation.
- ras_header
nib.nifti1.Nifti1Header The header of the RAS orientation.
- save_dir
Path The directory where the logits will be saved.
- mode
str The mode of operation.
- logits
- Returns:
- save_as:
Path The path where the logits were saved.
- save_as:
- HypVINN.utils.img_processing_utils.save_segmentation(prediction, orig_path, ras_affine, ras_header, subject_dir, seg_file, mask_file, save_mask=False)[source]¶
Save the segmentation results.
This function takes the prediction results, cleans the labels, maps them to FreeSurfer Hypvinn Labels, and saves the results. It also reorients the mask and prediction images to match the original image’s orientation.
- Parameters:
- prediction
np.ndarray The prediction results.
- orig_path
Path The path to the original image.
- ras_affine
npt.NDArray[float] The affine transformation of the RAS orientation.
- ras_header
nibabelheaderobject The header of the RAS orientation.
- subject_dir
Path The directory where the subject’s data is stored.
- seg_file
Path The file where the segmentation will be saved (relative to subject_dir/mri).
- mask_file
str The file where the mask will be saved (relative to subject_dir/mri).
- save_mask
bool, default=False Whether to save the mask or not. Default is False.
- prediction
- Returns:
floatThe time taken to save the segmentation.