class_docstr: generate randomised scaling along each dim for data augmentation
code: def _apply_transformation(self, image, interp_order=3):
      if interp_order < 0:
          return image
      assert self._rand_zoom is not None
      full_zoom = np.array(self._rand_zoom)
      while len(full_zoom) < image.ndim:
          full_zoom = np.hstack((full_zoom, [1.0]))
      is_undersampling = all(full_zoom[:3] < 1)
      run_antialiasing_filter = self.antialiasing and is_undersampling
      if run_antialiasing_filter:
          sigma = self._get_sigma(full_zoom[:3])
      if image.ndim == 4:
          output = []
          for mod in range(image.shape[-1]):
              to_scale = (
                  ndi.gaussian_filter(image[..., mod], sigma)
                  if run_antialiasing_filter
                  else image[..., mod]
              )
              scaled = ndi.zoom(
                  to_scale, full_zoom[:3], order=interp_order
              )
              output.append(scaled[..., np.newaxis])
          return np.concatenate(output, axis=-1)
      elif image.ndim == 3:
          to_scale = (
              ndi.gaussian_filter(image, sigma)
              if run_antialiasing_filter
              else image
          )
          scaled = ndi.zoom(to_scale, full_zoom[:3], order=interp_order)
          return scaled[..., np.newaxis]
      else:
          raise NotImplementedError("not implemented random scaling")
  
file_path: NiftyNet/niftynet/layer/rand_spatial_scaling.py
imports: from __future__ import absolute_import, print_function
  import warnings
  import numpy
  import scipy.ndimage
  from niftynet.layer.base_layer import RandomisedLayer
label_desc: Use image node_id 4 for calling the RandomSpatialScalingLayer obj's underlying member method code with example usage: obj._apply_transformation(image, interp_order) and returns: image, np, scaled