code: def layer_op(self, image):
      if image.ndim == 3:
          return self.__make_mask_3d(image)
  
      if image.ndim == 5:
          mod_to_mask = [
              m
              for m in range(image.shape[4])
              if np.any(image[..., :, m])
          ]
          mask = np.zeros_like(image, dtype=bool)
          mod_mask = None
          for mod in mod_to_mask:
              for t in range(image.shape[3]):
                  mask[..., t, mod] = self.__make_mask_3d(
                      image[..., t, mod]
                  )
              # combine masks across the modalities dim
              if self.multimod_fusion == "or":
                  if mod_mask is None:
                      mod_mask = np.zeros(image.shape[:4], dtype=bool)
                  mod_mask = np.logical_or(mod_mask, mask[..., mod])
              elif self.multimod_fusion == "and":
                  if mod_mask is None:
                      mod_mask = np.ones(image.shape[:4], dtype=bool)
                  mod_mask = np.logical_and(mod_mask, mask[..., mod])
          for mod in mod_to_mask:
              mask[..., mod] = mod_mask
          return mask
      else:
          raise ValueError("unknown input format")
  
file_path: NiftyNet/niftynet/layer/binary_masking.py
imports: from __future__ import absolute_import, print_function, division
  import numpy
  import scipy.ndimage
  from scipy.ndimage.morphology import binary_fill_holes
  from niftynet.layer.base_layer import Layer
  from niftynet.utilities.util_common import look_up_operations
  from niftynet.utilities.util_common import otsu_threshold
label_desc: Use image node_id 3 for calling the BinaryMaskingLayer obj's underlying member method code with example usage: obj.layer_op(image) and returns: self, mask