original_docstring: 
          Expects an 4d-image and -mask file name and a target path
      filter mask and image volumes with segmentation
      copy all metadata
      save them to the destination path
      :param img_f:
      :param mask_f:
      :param export_path: str
      :param filter_by_mask: bool
      :param slice_threshold: int
      :return:
      
docstring: Expects an 4d-image and -mask file name and a target path
  filter mask and image volumes with segmentation
  copy all metadata
  save them to the destination path
docstring_tokens: Expects an 4d - image and - mask file name and a target path filter mask and image volumes with segmentation copy all metadata save them to the destination path
code: def create_2d_slices_from_4d_volume_files(img_f, mask_f, export_path, filter_by_mask=True, slice_threshold=2):
      """
          Expects an 4d-image and -mask file name and a target path
      filter mask and image volumes with segmentation
      copy all metadata
      save them to the destination path
      :param img_f:
      :param mask_f:
      :param export_path: str
      :param filter_by_mask: bool
      :param slice_threshold: int
      :return:
      """
  
      logging.info('process file: {}'.format(img_f))
  
      # get sitk images
      mask_4d_sitk = sitk.ReadImage(mask_f)
      img_4d_sitk = sitk.ReadImage(img_f)
  
      # filter 4d image nda according to given mask nda
      if filter_by_mask:
          mask_4d_nda, masked_t = filter_4d_vol(mask_4d_sitk, slice_threshold=slice_threshold)
          img_4d_nda = sitk.GetArrayFromImage(img_4d_sitk)[masked_t]
      else:
          img_4d_nda = sitk.GetArrayFromImage(img_4d_sitk)
          masked_t = list(range(img_4d_nda.shape[0]))
          mask_4d_nda = sitk.GetArrayFromImage(mask_4d_sitk)
  
      # create t x 3d volumes
      for img_3d, mask_3d, t in zip(img_4d_nda, mask_4d_nda, masked_t):
  
          # get patient_name
          patient_name = os.path.basename(img_f).split('.')[0].replace('volume_clean', '')
  
          # create z x 2d slices
          for z, slice_2d in enumerate(zip(img_3d, mask_3d)):
              # create filenames with reference to t and z position
              img_file = '{}_t{}_z{}_{}{}'.format(patient_name, str(t), str(z), 'img', '.nrrd')
              mask_file = '{}_t{}_z{}_{}{}'.format(patient_name, str(t), str(z), 'msk', '.nrrd')
  
              # save nrrd file with metadata
              copy_meta_and_save(slice_2d[0], img_4d_sitk, os.path.join(export_path, img_file), copy_direction=False)
              copy_meta_and_save(slice_2d[1], img_4d_sitk, os.path.join(export_path, mask_file), copy_direction=False)
  
      return [masked_t, list(img_4d_nda.shape)]
code_tokens: def create_2d_slices_from_4d_volume_files ( img_f , mask_f , export_path , filter_by_mask = True , slice_threshold = 2 ) : logging . info ( 'process file: {}' . format ( img_f ) ) mask_4d_sitk = sitk . ReadImage ( mask_f ) img_4d_sitk = sitk . ReadImage ( img_f ) if filter_by_mask : mask_4d_nda , masked_t = filter_4d_vol ( mask_4d_sitk , slice_threshold = slice_threshold ) img_4d_nda = sitk . GetArrayFromImage ( img_4d_sitk ) [ masked_t ] else : img_4d_nda = sitk . GetArrayFromImage ( img_4d_sitk ) masked_t = list ( range ( img_4d_nda . shape [ 0 ] ) ) mask_4d_nda = sitk . GetArrayFromImage ( mask_4d_sitk ) for img_3d , mask_3d , t in zip ( img_4d_nda , mask_4d_nda , masked_t ) : patient_name = os . path . basename ( img_f ) . split ( '.' ) [ 0 ] . replace ( 'volume_clean' , '' ) for z , slice_2d in enumerate ( zip ( img_3d , mask_3d ) ) : img_file = '{}_t{}_z{}_{}{}' . format ( patient_name , str ( t ) , str ( z ) , 'img' , '.nrrd' ) mask_file = '{}_t{}_z{}_{}{}' . format ( patient_name , str ( t ) , str ( z ) , 'msk' , '.nrrd' ) copy_meta_and_save ( slice_2d [ 0 ] , img_4d_sitk , os . path . join ( export_path , img_file ) , copy_direction = False ) copy_meta_and_save ( slice_2d [ 1 ] , img_4d_sitk , os . path . join ( export_path , mask_file ) , copy_direction = False ) return [ masked_t , list ( img_4d_nda . shape ) ]
short_docstring: Expects an 4d-image and -mask file name and a target path
  filter mask and image volumes with segmentation
  copy all metadata
  save them to the destination path
short_docstring_tokens: Expects an 4d - image and - mask file name and a target path filter mask and image volumes with segmentation copy all metadata save them to the destination path
comment: """
          Expects an 4d-image and -mask file name and a target path
      filter mask and image volumes with segmentation
      copy all metadata
      save them to the destination path
      :param img_f:
      :param mask_f:
      :param export_path: str
      :param filter_by_mask: bool
      :param slice_threshold: int
      :return:
      """$SEP$# get sitk images$SEP$# filter 4d image nda according to given mask nda$SEP$# create t x 3d volumes$SEP$# get patient_name$SEP$# create z x 2d slices$SEP$# create filenames with reference to t and z position$SEP$# save nrrd file with metadata