def get_mask(self, idx: int) -> np.ndarray | None:
        """Retrieve masks from the file system.

        Args:
            idx (int): Index of the clip

        Returns:
            np.ndarray | None: Array of masks if available, else None
        """
        video_idx, frames_idx = self.get_clip_location(idx)
        matfile = self.mask_paths[video_idx]
        if matfile == "":  # no gt masks available for this clip
            return None
        frames = self.clips[video_idx][frames_idx]

        # read masks from .png files if available, otherwise from mat files
        mask_folder = Path(matfile).with_suffix("")
        if mask_folder.exists():
            mask_frames = sorted(mask_folder.glob("*"))
            mask_paths = [mask_frames[idx] for idx in frames.int()]
            masks = torch.stack([read_mask(mask_path, as_tensor=True) for mask_path in mask_paths])
        else:
            mat = scipy.io.loadmat(matfile)
            masks = np.vstack([np.stack(m) for m in mat["volLabel"]])
            masks = np.take(masks, frames, 0)
        return masks
Retrieve masks from the file system.

        Args:
            idx (int): Index of the clip

        Returns:
            np.ndarray | None: Array of masks if available, else None
        
src/anomalib/data/datasets/video/avenue.py