code: def expand_to_5d(img_data):
      """
      Expands an array up to 5d if it is not the case yet;
      The first three spatial dims are rearranged so that
      1-d is always [X, 1, 1]
      2-d is always [X, y, 1]
      :param img_data:
      :return:
      """
      while img_data.ndim < 5:
          img_data = np.expand_dims(img_data, axis=-1)
  
      spatial_dims = img_data.shape[:3]
      spatial_rank = np.sum([dim > 1 for dim in spatial_dims])
      if spatial_rank == 1:
          return np.swapaxes(img_data, 0, np.argmax(spatial_dims))
      if spatial_rank == 2:
          return np.swapaxes(img_data, 2, np.argmin(spatial_dims))
      return img_data
  
imports: from __future__ import absolute_import, print_function, unicode_literals
  import errno
  import importlib
  import logging
  import os
  import re
  import sys
  import warnings
  import nibabel
  import numpy
  import pandas
  import scipy.ndimage
  import tensorflow
  from tensorflow.core.framework import summary_pb2
  from niftynet.io.image_loader import load_image_obj
  from niftynet.utilities.niftynet_global_config import NiftyNetGlobalConfig
  from niftynet.utilities.util_import import require_module
label_desc: Use image node_id 13 for calling a global function with example usage: expand_to_5d(img_data) and returns: img_data, np, np