def generate_output_image_filename(input_path: str | Path, output_path: str | Path) -> Path:
    """Generate output filename for inference image.

    Args:
        input_path (str | Path): Path to input image
        output_path (str | Path): Path to save output (file or directory)

    Returns:
        Path: Generated output filename

    Raises:
        ValueError: If input_path is not a file

    Examples:
        >>> generate_output_image_filename("input.jpg", "output.jpg")
        PosixPath('output.jpg')  # or output_1.jpg if exists

        >>> generate_output_image_filename("dir/input.jpg", "outdir")
        PosixPath('outdir/dir/input.jpg')
    """
    input_path = validate_path(input_path)
    output_path = validate_path(output_path, should_exist=False)

    if not input_path.is_file():
        msg = "input_path is expected to be a file"
        raise ValueError(msg)

    if output_path.is_dir():
        output_image_filename = output_path / input_path.parent.name / input_path.name
    elif output_path.is_file() and output_path.exists():
        msg = f"{output_path} already exists. Renaming to avoid overwriting."
        logger.warning(msg)
        output_image_filename = duplicate_filename(output_path)
    else:
        output_image_filename = output_path

    output_image_filename.parent.mkdir(parents=True, exist_ok=True)

    return output_image_filename
Generate output filename for inference image.

    Args:
        input_path (str | Path): Path to input image
        output_path (str | Path): Path to save output (file or directory)

    Returns:
        Path: Generated output filename

    Raises:
        ValueError: If input_path is not a file

    Examples:
        >>> generate_output_image_filename("input.jpg", "output.jpg")
        PosixPath('output.jpg')  # or output_1.jpg if exists

        >>> generate_output_image_filename("dir/input.jpg", "outdir")
        PosixPath('outdir/dir/input.jpg')
    
src/anomalib/data/utils/image.py