original_docstring: 
      Helper to split a GCN 3D dicom file into z x 2D slices
  
      Expects an 3d-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 full_path:
      :return:
      
docstring: Helper to split a GCN 3D dicom file into z x 2D slices
  Expects an 3d-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: Helper to split a GCN 3D dicom file into z x 2D slices Expects an 3d - 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_3d_volume_files_any_filename(img_f, mask_f, export_path):
      """
      Helper to split a GCN 3D dicom file into z x 2D slices
  
      Expects an 3d-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 full_path:
      :return:
      """
      import re
      logging.info('process file: {}'.format(img_f))
  
      # get sitk images
      mask_3d_sitk = sitk.ReadImage(mask_f)
      img_3d_sitk = sitk.ReadImage(img_f)
  
      # filter 4d image nda according to given mask nda
      mask_3d = sitk.GetArrayFromImage(mask_3d_sitk)
      img_3d = sitk.GetArrayFromImage(img_3d_sitk)
  
      # get file names
      _, img_f = os.path.split(img_f)
      _, mask_f = os.path.split(mask_f)
  
      def get_new_name(f_name, z):
          match = ''
          # check if image or mask
          m = re.search('_img|_msk', f_name)
          if m:
              match = m.group(0)
          # extend filename at the very last position before 'img' or 'msk'
          return re.sub('{}.nrrd'.format(match), '_{}{}.nrrd'.format(z, match), f_name)
  
      # 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
          # extend the filename
  
          img_file = get_new_name(img_f, z)
          mask_file = get_new_name(mask_f, z)
  
          # save nrrd file with metadata
          copy_meta_and_save(slice_2d[0], img_3d_sitk, os.path.join(export_path, img_file))
          copy_meta_and_save(slice_2d[1], img_3d_sitk, os.path.join(export_path, mask_file))
  
      return list(img_3d.shape)
code_tokens: def create_2d_slices_from_3d_volume_files_any_filename ( img_f , mask_f , export_path ) : import re logging . info ( 'process file: {}' . format ( img_f ) ) mask_3d_sitk = sitk . ReadImage ( mask_f ) img_3d_sitk = sitk . ReadImage ( img_f ) mask_3d = sitk . GetArrayFromImage ( mask_3d_sitk ) img_3d = sitk . GetArrayFromImage ( img_3d_sitk ) _ , img_f = os . path . split ( img_f ) _ , mask_f = os . path . split ( mask_f ) def get_new_name ( f_name , z ) : match = '' m = re . search ( '_img|_msk' , f_name ) if m : match = m . group ( 0 ) return re . sub ( '{}.nrrd' . format ( match ) , '_{}{}.nrrd' . format ( z , match ) , f_name ) for z , slice_2d in enumerate ( zip ( img_3d , mask_3d ) ) : img_file = get_new_name ( img_f , z ) mask_file = get_new_name ( mask_f , z ) copy_meta_and_save ( slice_2d [ 0 ] , img_3d_sitk , os . path . join ( export_path , img_file ) ) copy_meta_and_save ( slice_2d [ 1 ] , img_3d_sitk , os . path . join ( export_path , mask_file ) ) return list ( img_3d . shape )
short_docstring: Helper to split a GCN 3D dicom file into z x 2D slices
  Expects an 3d-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: Helper to split a GCN 3D dicom file into z x 2D slices Expects an 3d - 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: """
      Helper to split a GCN 3D dicom file into z x 2D slices
  
      Expects an 3d-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 full_path:
      :return:
      """$SEP$# get sitk images$SEP$# filter 4d image nda according to given mask nda$SEP$# get file names$SEP$# check if image or mask$SEP$# extend filename at the very last position before 'img' or 'msk'$SEP$# create z x 2d slices$SEP$# create filenames with reference to t and z position$SEP$# extend the filename$SEP$# save nrrd file with metadata