code: def extract_data(
      nifti_file, mask_file, out_file, zscore, detrend, smoothing_fwmw
  ):
      if mask_file is None:
          # whole brain, get coordinate info from nifti_file itself
          mask = nib.load(nifti_file.name)
      else:
          mask = nib.load(mask_file.name)
      affine = mask.get_affine()
      if mask_file is None:
          mask_data = mask.get_fdata()
          if mask_data.ndim == 4:
              # get mask in 3D
              img_data_type = mask.header.get_data_dtype()
              n_tr = mask_data.shape[3]
              mask_data = mask_data[:, :, :, n_tr // 2].astype(bool)
              mask = nib.Nifti1Image(
                  mask_data.astype(img_data_type), affine
              )
          else:
              mask_data = mask_data.astype(bool)
      else:
          mask_data = mask.get_fdata().astype(bool)
  
      # get voxel coordinates
      R = np.float64(np.argwhere(mask_data))
  
      # get scanner RAS coordinates based on voxel coordinates
      if affine is not []:
          R = (np.dot(affine[:3, :3], R.T) + affine[:3, 3:4]).T
  
      # get ROI data, and run preprocessing
      nifti_masker = NiftiMasker(
          mask_img=mask,
          standardize=zscore,
          detrend=detrend,
          smoothing_fwhm=smoothing_fwmw,
      )
      img = nib.load(nifti_file.name)
      all_images = np.float64(nifti_masker.fit_transform(img))
      data = all_images.T.copy()
  
      # save data
      subj_data = {"data": data, "R": R}
      scipy.io.savemat(out_file.name, subj_data)
  
file_path: brainiak/examples/factoranalysis/get_tfa_input_from_nifti.py
imports: import scipy.io
  from scipy.stats import stats
  import numpy
  import nibabel
  from nilearn.input_data import NiftiMasker
  import os
  import logging
  import sys
  import click
label_desc: Use image node_id 1 for calling a global function with example usage: extract_data(nifti_file, mask_file, out_file, zscore, detrend, smoothing_fwmw) without return types