Vision plot


source

validate_anatomical_plane


def validate_anatomical_plane(
    anatomical_plane
):

Ensure anatomical_plane is either 0, 1, or 2.


source

show_med_img


def show_med_img(
    im, ctx, channel:int, slice_index:int, anatomical_plane:int, voxel_size:(<class 'int'>, <class 'list'>),
    ax:NoneType=None, figsize:NoneType=None, title:NoneType=None, cmap:NoneType=None, norm:NoneType=None,
    aspect:NoneType=None, interpolation:NoneType=None, alpha:NoneType=None, vmin:NoneType=None, vmax:NoneType=None,
    colorizer:NoneType=None, origin:NoneType=None, extent:NoneType=None, interpolation_stage:NoneType=None,
    filternorm:bool=True, filterrad:float=4.0, resample:NoneType=None, url:NoneType=None, data:NoneType=None,
    kwargs:VAR_KEYWORD
):

Show an image on ax. This is a modified code from the fastai function show_image.

Args: im: The input image. ctx: The context. channel: Channel of the image. slice_index: Index of the 2D slice. anatomical_plane: Anatomical plane of the image. voxel_size: Voxel size for the image. ax: Axis for the plot. figsize: Figure size for the plot. title: Title for the plot. kwargs: Additional parameters for plt.Axes.imshow method.

Returns: Axis with the plot.


source

find_max_slice


def find_max_slice(
    mask_data, anatomical_plane
):

Find slice index based on mask


source

show_segmentation_comparison


def show_segmentation_comparison(
    image, ground_truth, prediction, slice_index:int=None, anatomical_plane:int=2, metric_value:float=None,
    metric_name:str='DSC', channel:int=0, figsize:tuple=(15, 5), cmap_img:str='gray', cmap_mask:str='gray',
    voxel_size:NoneType=None
):

Display 3-panel comparison: Image | Ground Truth | Prediction.

Useful for validating segmentation results, especially after patch-based inference where results are not in standard fastai batch format.

Args: image: Input image (MedImage, MedMask, or tensor [C, H, W, D]) ground_truth: Ground truth mask (MedMask or tensor [C, H, W, D]) prediction: Predicted mask (tensor [C, H, W, D]) slice_index: Slice to display. If None, uses find_max_slice on ground_truth. anatomical_plane: 0=sagittal, 1=coronal, 2=axial (default) metric_value: Optional metric value to display in prediction title metric_name: Name of metric for title (default ‘DSC’) channel: Channel to display for multi-channel data (default 0) figsize: Figure size (default (15, 5)) cmap_img: Colormap for image (default ‘gray’) cmap_mask: Colormap for masks (default ‘gray’) voxel_size: Voxel spacing for aspect ratio. If None, aspect=1.

Example::

# After patch_inference()
show_segmentation_comparison(
    image=val_img,
    ground_truth=val_gt,
    prediction=predictions[0],
    metric_value=results_df.iloc[0]['DSC'],
    anatomical_plane=2
)