code: def compute_mask(
      anomaly_map: np.ndarray, threshold: float, kernel_size: int = 4
  ) -> np.ndarray:
      """Compute anomaly mask via thresholding the predicted anomaly map.
  
      Args:
          anomaly_map (np.ndarray): Anomaly map predicted via the model
          threshold (float): Value to threshold anomaly scores into 0-1 range.
          kernel_size (int): Value to apply morphological operations to the predicted mask. Defaults to 4.
  
      Returns:
          Predicted anomaly mask
      """
  
      anomaly_map = anomaly_map.squeeze()
      mask: np.ndarray = np.zeros_like(anomaly_map).astype(np.uint8)
      mask[anomaly_map > threshold] = 1
  
      kernel = morphology.disk(kernel_size)
      mask = morphology.opening(mask, kernel)
  
      mask *= 255
  
      return mask
  
file_path: anomalib/src/anomalib/post_processing/post_process.py
imports: from __future__ import annotations
  import math
  from enum import Enum
  import cv2
  import numpy
  from skimage import morphology
label_desc: Use image node_id 6 for calling a global function with example usage: compute_mask(anomaly_map, threshold, kernel_size) and returns: mask