code: def generate_output_image_filename(
      input_path: str | Path, output_path: str | Path
  ) -> Path:
      """Generate an output filename to save the inference image.
  
      This function generates an output filaname by checking the input and output filenames. Input path is
      the input to infer, and output path is the path to save the output predictions specified by the user.
  
      The function expects ``input_path`` to always be a file, not a directory. ``output_path`` could be a
      filename or directory. If it is a filename, the function checks if the specified filename exists on
      the file system. If yes, the function calls ``duplicate_filename`` to duplicate the filename to avoid
      overwriting the existing file. If ``output_path`` is a directory, this function adds the parent and
      filenames of ``input_path`` to ``output_path``.
  
      Args:
          input_path (str | Path): Path to the input image to infer.
          output_path (str | Path): Path to output to save the predictions.
              Could be a filename or a directory.
  
      Examples:
          >>> input_path = Path("datasets/MVTec/bottle/test/broken_large/000.png")
          >>> output_path = Path("datasets/MVTec/bottle/test/broken_large/000.png")
          >>> generate_output_image_filename(input_path, output_path)
          PosixPath('datasets/MVTec/bottle/test/broken_large/000_1.png')
  
          >>> input_path = Path("datasets/MVTec/bottle/test/broken_large/000.png")
          >>> output_path = Path("results/images")
          >>> generate_output_image_filename(input_path, output_path)
          PosixPath('results/images/broken_large/000.png')
  
      Raises:
          ValueError: When the ``input_path`` is not a file.
  
      Returns:
          Path: The output filename to save the output predictions from the inferencer.
      """
  
      if isinstance(input_path, str):
          input_path = Path(input_path)
  
      if isinstance(output_path, str):
          output_path = Path(output_path)
  
      # This function expects an ``input_path`` that is a file. This is to check if output_path
      if input_path.is_file() is False:
          raise ValueError(
              "input_path is expected to be a file to generate a proper output filename."
          )
  
      file_path: Path
      if output_path.is_dir():
          # If the output is a directory, then add parent directory name
          # and filename to the path. This is to ensure we do not overwrite
          # images and organize based on the categories.
          file_path = (
              output_path / input_path.parent.name / input_path.name
          )
      else:
          file_path = output_path
  
      # This new ``file_path`` might contain a directory path yet to be created.
      # Create the parent directory to avoid such cases.
      file_path.parent.mkdir(parents=True, exist_ok=True)
  
      if file_path.is_file():
          warnings.warn(
              f"{output_path} already exists. Renaming the file to avoid overwriting."
          )
          file_path = duplicate_filename(file_path)
  
      return file_path
  
file_path: anomalib/src/anomalib/data/utils/image.py
imports: from __future__ import annotations
  import math
  import warnings
  from pathlib import Path
  import cv2
  import numpy
  import tifffile
  import torch.nn.functional
  from torch import Tensor
  from torchvision.datasets.folder import IMG_EXTENSIONS
label_desc: Use image node_id 3 for calling a global function with example usage: generate_output_image_filename(input_path, output_path) and returns: file_path