Visualize Module#

Vizualization module.

landmarker.visualize.detection_report(true_landmarks, pred_landmarks, dim, dim_orig, pixel_spacing, padding, class_names=None, radius=[2, 2.5, 3, 4], digits=2, unit='mm', output_dict=False)[source]#

Calculate the detection report.

Parameters:
  • true_landmarks (Tensor) – torch.Tensor The true landmarks, with shape (n, p, 2). n is the number of samples, p is the number of landmarks, and 2 is respectively the y and x coordinates of the landmarks.

  • pred_landmarks (Tensor) – torch.Tensor The predicted landmarks, with shape (n, p, 2). n is the number of samples, p is the number of landmarks, and 2 is respectively the y and x coordinates of the landmarks.

  • dim (tuple[int, ...] | Tensor) – tuple[int, …] | torch.Tensor The dimension of the image, with shape (2,). 2 is respectively the height and width of the image.

  • dim_orig (Tensor) – torch.Tensor The original dimension of the image, with shape (2,). 2 is respectively the height and width of the image.

  • pixel_spacing (Tensor) – torch.Tensor The pixel spacing of the image, with shape (2,). 2 is respectively the height and width of the image.

  • padding (Tensor) – torch.Tensor The padding of the image, with shape (2,). 2 is respectively the height and width of the image.

  • class_names (list[str] | None) – list The names of the landmarks. The default is None.

  • radius (list[float]) – list[float], optional The radius of the success detection rate (SDR). The default is [2, 2.5, 3, 4].

  • digits (int) – int, optional The number of digits to round the statistics. The default is 2.

  • unit (str) – str, optional The unit of distance. The default is β€˜mm’.

  • output_dict (bool) – bool, optional Whether to output the detection report as a dictionary. The default is False.

Returns:

dict

The detection report. Only output when output_dict is True.

Return type:

report

landmarker.visualize.inspection_plot(ds, idx, heatmap_generator=None, save_path=None, fig_title='Landmark Dataset Inspection Plot')[source]#

Plots the transformed image, heatmap, and original image with landmarks for the given dataset indices.

Parameters:
  • ds (LandmarkDataset) – Dataset to inspect.

  • idx (int | Iterable[int]) – Indices of the dataset to inspect.

  • heatmap_generator (HeatmapGenerator, optional) – Heatmap generator to use. Defaults to None.

  • save_path (str, optional) – Path to save the plot to. If None, the plot is not saved. Defaults to None.

  • fig_title (str, optional) – Title of the figure. Defaults to β€œLandmark Dataset Inspection Plot”.

landmarker.visualize.plot_cpe(true_landmarks, pred_landmarks, dim, dim_orig, pixel_spacing, padding, class_names=None, group=True, title=None, save_path=None, stat='proportion', unit='mm', kind='ecdf')[source]#

Calculate the cumulative point-to-point error (CPE) and plot the CPE curve.

Parameters:
  • y_true – numpy.ndarray The true values of the target variable, with shape (n, p, 2). n is the number of samples, p is the number of landmarks, and 2 is respectively the y and x coordinates of the landmarks.

  • y_pred – numpy.ndarray The predicted values of the target variable, with shape (n, p, 2). n is the number of samples, p is the number of landmarks, and 2 is respectively the y and x coordinates of the landmarks.

  • class_names (list[str] | None) – list The names of the landmarks. The default is None.

  • group (bool) – bool, optional Whether to group the CPE curves by landmarks. The default is True.

  • title (str | None) – str, optional The title of the plot. The default is None.

  • save_path (str | None) – str, optional The path to save the plot. The default is None.

  • stat (str) – str, optional The type of statistic to plot. The default is β€˜proportion’.

  • unit (str) – str, optional The unit of distance. The default is β€˜mm’.

  • kind (str) – str, optional The type of plot. The default is β€˜ecdf’. Possible values are β€˜ecdf’, β€˜kde’, and β€˜hist’.

  • true_landmarks (Tensor) –

  • pred_landmarks (Tensor) –

  • dim (tuple[int, ...] | Tensor) –

  • dim_orig (Tensor) –

  • pixel_spacing (Tensor) –

  • padding (Tensor) –

landmarker.visualize.prediction_inspect_plot(ds, model, idx, activation=Identity(), save_path=None, fig_title='Landmark Prediction Model Inspection Plot')[source]#

Plots the transformed image, predicted heatmap, and original image with predicted and true landmarks for the given dataset indices.

Parameters:
  • ds (LandmarkDataset) – Dataset to inspect.

  • model (nn.Module) – Model to use for prediction.

  • idx (int | Sequence[int]) – Indices of the dataset to inspect.

  • activation (nn.Module, optional) – Activation function to use. Defaults to nn.Identity().

  • save_path (str, optional) – Path to save the plot to. If None, the plot is not saved. Defaults to None.

  • fig_title (str, optional) – Title of the figure. Defaults to β€œLandmark Prediction Model Inspection Plot”.