code: def rectify_header_sform_qform(img_nii):
      """
      Look at the sform and qform of the nifti object and
      correct it if any incompatibilities with pixel dimensions
  
      :param img_nii:
      :return:
      """
      pixdim = img_nii.header.get_zooms()
      sform = img_nii.get_sform()
      qform = img_nii.get_qform()
      norm_sform = np.sqrt(np.sum(np.square(sform[0:3, 0:3]), 0))
      norm_qform = np.sqrt(np.sum(np.square(qform[0:3, 0:3]), 0))
      flag_sform_problem = False
      flag_qform_problem = False
      if not np.array_equal(norm_sform, np.asarray(pixdim)):
          flag_sform_problem = True
      if not np.array_equal(norm_qform, np.asarray(pixdim)):
          flag_qform_problem = True
  
      if img_nii.header["sform_code"] > 0:
          if not flag_sform_problem:
              return img_nii
          if not flag_qform_problem:
              # recover by copying the qform over the sform
              img_nii.set_sform(np.copy(img_nii.get_qform()))
              return img_nii
      elif img_nii.header["qform_code"] > 0:
          if not flag_qform_problem:
              return img_nii
          if not flag_sform_problem:
              # recover by copying the sform over the qform
              img_nii.set_qform(np.copy(img_nii.get_sform()))
              return img_nii
      affine = img_nii.affine
      pixdim = img_nii.header.get_zooms()
      while len(pixdim) < 3:
          pixdim = pixdim + (1.0,)
      # assuming 3 elements
      new_affine = create_affine_pixdim(affine, pixdim[:3])
      img_nii.set_sform(new_affine)
      img_nii.set_qform(new_affine)
      return img_nii
  
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 5 for calling a global function with example usage: rectify_header_sform_qform(img_nii) and returns: img_nii, img_nii, img_nii, img_nii, img_nii