code: def create_file_basename(
      postfix: str,
      input_file_name: PathLike,
      folder_path: PathLike,
      data_root_dir: PathLike = "",
      separate_folder: bool = True,
      patch_index=None,
      makedirs: bool = True,
  ) -> str:
      """
      Utility function to create the path to the output file based on the input
      filename (file name extension is not added by this function).
      When ``data_root_dir`` is not specified, the output file name is:
  
          `folder_path/input_file_name (no ext.) /input_file_name (no ext.)[_postfix][_patch_index]`
  
      otherwise the relative path with respect to ``data_root_dir`` will be inserted, for example:
  
      .. code-block:: python
  
          from monai.data import create_file_basename
          create_file_basename(
              postfix="seg",
              input_file_name="/foo/bar/test1/image.png",
              folder_path="/output",
              data_root_dir="/foo/bar",
              separate_folder=True,
              makedirs=False)
          # output: /output/test1/image/image_seg
  
      Args:
          postfix: output name's postfix
          input_file_name: path to the input image file.
          folder_path: path for the output file
          data_root_dir: if not empty, it specifies the beginning parts of the input file's
              absolute path. This is used to compute `input_file_rel_path`, the relative path to the file from
              `data_root_dir` to preserve folder structure when saving in case there are files in different
              folders with the same file names.
          separate_folder: whether to save every file in a separate folder, for example: if input filename is
              `image.nii`, postfix is `seg` and folder_path is `output`, if `True`, save as:
              `output/image/image_seg.nii`, if `False`, save as `output/image_seg.nii`. default to `True`.
          patch_index: if not None, append the patch index to filename.
          makedirs: whether to create the folder if it does not exist.
      """
  
      # get the filename and directory
      filedir, filename = os.path.split(input_file_name)
      # remove extension
      filename, ext = os.path.splitext(filename)
      if ext == ".gz":
          filename, ext = os.path.splitext(filename)
      # use data_root_dir to find relative path to file
      filedir_rel_path = ""
      if data_root_dir and filedir:
          filedir_rel_path = os.path.relpath(filedir, data_root_dir)
  
      # output folder path will be original name without the extension
      output = os.path.join(folder_path, filedir_rel_path)
  
      if separate_folder:
          output = os.path.join(output, filename)
  
      if makedirs:
          # create target folder if no existing
          os.makedirs(output, exist_ok=True)
  
      # add the sub-folder plus the postfix name to become the file basename in the output path
      output = os.path.join(
          output,
          filename + "_" + postfix if postfix != "" else filename,
      )
  
      if patch_index is not None:
          output += f"_{patch_index}"
  
      return os.path.normpath(output)
  
imports: from __future__ import annotations
  import hashlib
  import json
  import logging
  import math
  import os
  import pickle
  import sys
  from collections import abc, defaultdict
  from collections.abc import Generator, Iterable, Mapping, Sequence, Sized
  from copy import deepcopy
  from functools import reduce
  from itertools import product, starmap, zip_longest
  from pathlib import PurePath
  from typing import Any
  import numpy
  import torch
  from torch.utils.data._utils.collate import default_collate
  from monai import config
  from monai.config.type_definitions import NdarrayOrTensor, NdarrayTensor, PathLike
  from monai.data.meta_obj import MetaObj
  from monai.utils import MAX_SEED, BlendMode, Method, NumpyPadMode, TraceKeys, convert_data_type, convert_to_dst_type, ensure_tuple, ensure_tuple_rep, ensure_tuple_size, fall_back_tuple, first, get_equivalent_dtype, issequenceiterable, look_up_option, optional_import, pytorch_after
label_desc: Use image node_id 25 for calling a global function with example usage: create_file_basename(postfix, input_file_name, folder_path, data_root_dir, separate_folder, patch_index, makedirs) and returns: os