code: def drain_rois(img):
      
      img_data = get_img_data(img)
  
      out = np.zeros(img_data.shape, dtype=img_data.dtype)
  
      krn_dim = [3] * img_data.ndim
      kernel  = np.ones(krn_dim, dtype=int)
  
      vals = np.unique(img_data)
      vals = vals[vals != 0]
  
      for i in vals:
          roi  = img_data == i
          hits = scn.binary_hit_or_miss(roi, kernel)
          roi[hits] = 0
          out[roi > 0] = i
  
      return out
docs: Find all the ROIs in img and returns a similar volume with the ROIs
      emptied, keeping only their border voxels.
  
      This is useful for DTI tractography.
  
      Parameters
      ----------
      img: img-like object or str
          Can either be:
          - a file path to a Nifti image
          - any object with get_data() and get_affine() methods, e.g., nibabel.Nifti1Image.
          If niimg is a string, consider it as a path to Nifti image and
          call nibabel.load on it. If it is an object, check if get_data()
          and get_affine() methods are present, raise TypeError otherwise.
  
      Returns
      -------
      np.ndarray
          an array of same shape as img_data