def validate_anomaly_map(anomaly_map: np.ndarray | None) -> np.ndarray | None:
        """Validate the anomaly map batch.

        This method validates batches of anomaly maps. It handles:
            - Channel-first and channel-last formats
            - Type conversion to float32
            - Shape validation

        Args:
            anomaly_map (``np.ndarray`` | ``None``): Input anomaly map batch.

        Returns:
            ``np.ndarray`` | ``None``: Validated anomaly map batch, or ``None``.

        Raises:
            TypeError: If ``anomaly_map`` is not a numpy array.
            ValueError: If ``anomaly_map`` shape is invalid.

        Examples:
            Validate channel-last maps::

                >>> maps = np.random.rand(4, 224, 224)
                >>> validated = NumpyImageBatchValidator.validate_anomaly_map(maps)
                >>> validated.shape
                (4, 224, 224)
                >>> validated.dtype
                dtype('float32')

            Validate channel-first maps::

                >>> maps = np.random.rand(4, 1, 224, 224)
                >>> validated = NumpyImageBatchValidator.validate_anomaly_map(maps)
                >>> validated.shape
                (4, 224, 224, 1)
        """
        if anomaly_map is None:
            return None
        if not isinstance(anomaly_map, np.ndarray):
            msg = f"Anomaly map batch must be a numpy.ndarray, got {type(anomaly_map)}."
            raise TypeError(msg)
        if anomaly_map.ndim not in {3, 4}:
            msg = f"Anomaly map batch must have shape [N, H, W] or [N, H, W, 1], got shape {anomaly_map.shape}."
            raise ValueError(msg)
        # Check if the anomaly map is in [N, C, H, W] format and rearrange if necessary
        if anomaly_map.ndim == 4 and anomaly_map.shape[1] not in {1, 3}:
            anomaly_map = np.transpose(anomaly_map, (0, 2, 3, 1))
        return anomaly_map.astype(np.float32)
Validate the anomaly map batch.

        This method validates batches of anomaly maps. It handles:
            - Channel-first and channel-last formats
            - Type conversion to float32
            - Shape validation

        Args:
            anomaly_map (``np.ndarray`` | ``None``): Input anomaly map batch.

        Returns:
            ``np.ndarray`` | ``None``: Validated anomaly map batch, or ``None``.

        Raises:
            TypeError: If ``anomaly_map`` is not a numpy array.
            ValueError: If ``anomaly_map`` shape is invalid.

        Examples:
            Validate channel-last maps::

                >>> maps = np.random.rand(4, 224, 224)
                >>> validated = NumpyImageBatchValidator.validate_anomaly_map(maps)
                >>> validated.shape
                (4, 224, 224)
                >>> validated.dtype
                dtype('float32')

            Validate channel-first maps::

                >>> maps = np.random.rand(4, 1, 224, 224)
                >>> validated = NumpyImageBatchValidator.validate_anomaly_map(maps)
                >>> validated.shape
                (4, 224, 224, 1)
        
src/anomalib/data/validators/numpy/image.py