Vision plot


source

validate_anatomical_plane

 validate_anatomical_plane (anatomical_plane)

Ensure anatomical_plane is either 0, 1, or 2.


source

show_med_img

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

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

 find_max_slice (mask_data, anatomical_plane)

Find slice index based on mask


source

show_segmentation_comparison

 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=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
)