code: def crop_mirror_normalize_func(
      crop_z,
      crop_y,
      crop_x,
      crop_d,
      crop_h,
      crop_w,
      should_pad,
      mean,
      std,
      scale,
      shift,
      input_layout,
      output_layout,
      dtype,
      image,
      should_flip,
  ):
      scale = scale or 1
      shift = shift or 0
  
      assert (
          input_layout == "HWC"
          or input_layout == "FHWC"
          or input_layout == "DHWC"
          or input_layout == "FDHWC"
      )
      assert len(input_layout) == len(image.shape)
  
      assert input_layout.count("H") > 0
      dim_h = input_layout.find("H")
      H = image.shape[dim_h]
  
      assert input_layout.count("W") > 0
      dim_w = input_layout.find("W")
      W = image.shape[dim_w]
  
      assert input_layout.count("C") > 0
      dim_c = input_layout.find("C")
      C = image.shape[dim_c]
  
      D = 1
      if input_layout.count("D") > 0:
          dim_d = input_layout.find("D")
          D = image.shape[dim_d]
          assert D >= crop_d
  
      F = 1
      if input_layout.count("F") > 0:
          dim_f = input_layout.find("F")
          F = image.shape[dim_f]
  
      assert H >= crop_h and W >= crop_w
  
      start_y = int(
          np.float32(crop_y) * np.float32(H - crop_h) + np.float32(0.5)
      )
      end_y = start_y + crop_h
      start_x = int(
          np.float32(crop_x) * np.float32(W - crop_w) + np.float32(0.5)
      )
      end_x = start_x + crop_w
      if input_layout.count("D") > 0:
          assert D >= crop_d
          start_z = int(
              np.float32(crop_z) * np.float32(D - crop_d)
              + np.float32(0.5)
          )
          end_z = start_z + crop_d
  
      # Crop
      if input_layout == "HWC":
          out = image[start_y:end_y, start_x:end_x, :]
          H, W = out.shape[0], out.shape[1]
      elif input_layout == "FHWC":
          out = image[:, start_y:end_y, start_x:end_x, :]
          H, W = out.shape[1], out.shape[2]
      elif input_layout == "DHWC":
          out = image[start_z:end_z, start_y:end_y, start_x:end_x, :]
          D, H, W = out.shape[0], out.shape[1], out.shape[2]
      elif input_layout == "FDHWC":
          out = image[:, start_z:end_z, start_y:end_y, start_x:end_x, :]
          D, H, W = out.shape[1], out.shape[2], out.shape[3]
  
      if not mean:
          mean = [0.0]
      if not std:
          std = [1.0]
  
      if len(mean) == 1:
          mean = C * mean
      if len(std) == 1:
          std = C * std
  
      assert len(mean) == C and len(std) == C
      inv_std = [np.float32(1.0) / np.float32(std[c]) for c in range(C)]
      mean = np.float32(mean)
  
      assert input_layout.count("W") > 0
      horizontal_dim = input_layout.find("W")
      out1 = np.flip(out, horizontal_dim) if should_flip else out
  
      # Pad, normalize, transpose
  
      out_C = next_power_of_two(C) if should_pad else C
  
      if input_layout == "HWC":
          out2 = np.zeros([H, W, out_C], dtype=np.float32)
          out2[:, :, 0:C] = (
              np.float32(out1) - mean
          ) * inv_std * scale + shift
          ret = (
              np.transpose(out2, (2, 0, 1))
              if output_layout == "CHW"
              else out2
          )
      elif input_layout == "FHWC":
          out2 = np.zeros([F, H, W, out_C], dtype=np.float32)
          out2[:, :, :, 0:C] = (
              np.float32(out1) - mean
          ) * inv_std * scale + shift
          ret = (
              np.transpose(out2, (0, 3, 1, 2))
              if output_layout == "FCHW"
              else out2
          )
      elif input_layout == "DHWC":
          out2 = np.zeros([D, H, W, out_C], dtype=np.float32)
          out2[:, :, :, 0:C] = (
              np.float32(out1) - mean
          ) * inv_std * scale + shift
          ret = (
              np.transpose(out2, (3, 0, 1, 2))
              if output_layout == "CDHW"
              else out2
          )
      elif input_layout == "FDHWC":
          out2 = np.zeros([F, D, H, W, out_C], dtype=np.float32)
          out2[:, :, :, :, 0:C] = (
              np.float32(out1) - mean
          ) * inv_std * scale + shift
          ret = (
              np.transpose(out2, (0, 4, 1, 2, 3))
              if output_layout == "FCDHW"
              else out2
          )
      else:
          raise RuntimeError(
              "The test function received unsupported layout {}".format(
                  input_layout
              )
          )
  
      # clamp the result to output type's dynamic range
      if np.issubdtype(dtype, np.integer):
          lo = np.iinfo(dtype).min
          hi = np.iinfo(dtype).max
          ret = np.clip(ret, lo, hi)
  
      return ret
  
imports: import numpy
  import nvidia.dali
  import nvidia.dali.fn
  import nvidia.dali.ops
  import nvidia.dali.types
  import os
  from functools import partial
  from nvidia.dali import pipeline_def
  from nvidia.dali.pipeline import Pipeline
  from nose2.tools import params
  from nose_utils import assert_raises
  from nose_utils import raises
  from test_slice import check_slice_output, abs_slice_start_and_end
  from test_utils import RandomDataIterator
  from test_utils import as_array
  from test_utils import compare_pipelines, dali_type_to_np
  from test_utils import get_dali_extra_path
  import itertools
label_desc: Use image node_id 4 for calling a global function with example usage: crop_mirror_normalize_func(crop_z, crop_y, crop_x, crop_d, crop_h, crop_w, should_pad, mean, std, scale, shift, input_layout, output_layout, dtype, image, should_flip) and returns: ret