original_docstring: 
      filter emtpy slices along axis 0
      expect a 4d numpy array with shape t, z, x, y
      Returns numpy with shape t - emtpy, z, x, y
      :param sitk_img_4d:
      :param slice_threshold: min number of masked slices per volume
      :return:
      
docstring: filter emtpy slices along axis 0
  expect a 4d numpy array with shape t, z, x, y
  Returns numpy with shape t - emtpy, z, x, y
docstring_tokens: filter emtpy slices along axis 0 expect a 4d numpy array with shape t z x y Returns numpy with shape t - emtpy z x y
code: def filter_4d_vol(sitk_img_4d, slice_threshold=2):
      """
      filter emtpy slices along axis 0
      expect a 4d numpy array with shape t, z, x, y
      Returns numpy with shape t - emtpy, z, x, y
      :param sitk_img_4d:
      :param slice_threshold: min number of masked slices per volume
      :return:
      """
      if isinstance(sitk_img_4d, sitk.Image):
          nda_4d = sitk.GetArrayFromImage(sitk_img_4d)
      elif isinstance(sitk_img_4d, np.ndarray):
          nda_4d = sitk_img_4d
  
      logging.info(nda_4d.shape)
      timesteps = []
      # get indexes for masked volumes
      # filter 3d volumes with less masked slices than threshold
      for t, nda_3d in enumerate(nda_4d):
          if nda_3d.max() > 0:  # 3d volume with masks
              masked_slices = 0
              for slice in nda_3d:  # check how many slices are masked
                  if slice.max() > 0:
                      masked_slices += 1
              if masked_slices > slice_threshold:
                  timesteps.append(t)
              else:
                  logging.info('filter volume by masked slices threshold')
  
      logging.info('filtered timesteps: {}'.format(timesteps))
      filtered_nda = nda_4d[timesteps]
  
      return filtered_nda, timesteps
code_tokens: def filter_4d_vol ( sitk_img_4d , slice_threshold = 2 ) : if isinstance ( sitk_img_4d , sitk . Image ) : nda_4d = sitk . GetArrayFromImage ( sitk_img_4d ) elif isinstance ( sitk_img_4d , np . ndarray ) : nda_4d = sitk_img_4d logging . info ( nda_4d . shape ) timesteps = [ ] for t , nda_3d in enumerate ( nda_4d ) : if nda_3d . max ( ) > 0 : masked_slices = 0 for slice in nda_3d : if slice . max ( ) > 0 : masked_slices += 1 if masked_slices > slice_threshold : timesteps . append ( t ) else : logging . info ( 'filter volume by masked slices threshold' ) logging . info ( 'filtered timesteps: {}' . format ( timesteps ) ) filtered_nda = nda_4d [ timesteps ] return filtered_nda , timesteps
short_docstring: filter emtpy slices along axis 0
  expect a 4d numpy array with shape t, z, x, y
  Returns numpy with shape t - emtpy, z, x, y
short_docstring_tokens: filter emtpy slices along axis 0 expect a 4d numpy array with shape t z x y Returns numpy with shape t - emtpy z x y
comment: """
      filter emtpy slices along axis 0
      expect a 4d numpy array with shape t, z, x, y
      Returns numpy with shape t - emtpy, z, x, y
      :param sitk_img_4d:
      :param slice_threshold: min number of masked slices per volume
      :return:
      """$SEP$# get indexes for masked volumes$SEP$# filter 3d volumes with less masked slices than threshold$SEP$# 3d volume with masks$SEP$# check how many slices are masked