code: def resize3D_PIL(
      input, size, roi_start, roi_end, dtype, channel_first, resample
  ):
      size = list(size)
      if channel_first:
          input = input.transpose([1, 2, 3, 0])
  
      has_overshoot = resample in (LANCZOS, BICUBIC)
      if has_overshoot:
          # compress dynamic range to allow for overshoot
          input = (64 + input * 0.5).round().astype(np.uint8)
  
      mono = input.shape[3] == 1
  
      # First, slice along Z dimension and resize the XY slices
      sizeXY = [size[2], size[1]]
      boxXY = [roi_start[2], roi_start[1], roi_end[2], roi_end[1]]
      tmp = np.zeros(
          [input.shape[0], size[1], size[2], input.shape[3]],
          dtype=np.uint8,
      )
      for z in range(input.shape[0]):
          in_slice = input[z, :, :, 0] if mono else input[z]
          out_slice = np.array(
              PIL.Image.fromarray(in_slice).resize(
                  sizeXY, box=boxXY, resample=resample
              )
          )
          tmp[z] = out_slice[:, :, np.newaxis] if mono else out_slice
  
      # Then, slice along Y and resize XZ slices
      sizeXZ = [size[2], size[0]]
      boxXZ = [0, roi_start[0], size[2], roi_end[0]]
      out = np.zeros(size + [input.shape[3]], dtype=np.uint8)
      for y in range(size[1]):
          in_slice = tmp[:, y, :, 0] if mono else tmp[:, y]
          out_slice = np.array(
              PIL.Image.fromarray(in_slice).resize(
                  sizeXZ, box=boxXZ, resample=resample
              )
          )
          out[:, y, :, :] = (
              out_slice[:, :, np.newaxis] if mono else out_slice
          )
  
      # Restore dynamic range, losing some bit depth
      if has_overshoot:
          out = (out.astype(np.float32) - 64) * 2.0
      if dtype == np.uint8:
          out = out.round().clip(0, 255).astype(np.uint8)
      elif dtype == types.FLOAT:
          out = out.astype(np.float32)
      if channel_first:
          out = out.transpose([3, 0, 1, 2])
      return out
  
imports: import cv2
  import functools
  import math
  import numpy
  import nvidia.dali
  import nvidia.dali.fn
  import nvidia.dali.types
  import os.path
  from nvidia.dali import Pipeline, pipeline_def
  from nvidia.dali.data_node import DataNode
  from test_utils import check_batch, get_dali_extra_path, as_array
  import PIL.Image
label_desc: Use image node_id 3 for calling a global function with example usage: resize3D_PIL(input, size, roi_start, roi_end, dtype, channel_first, resample) and returns: out