parameters: (data_dir, imname, spacing, slice_intv, do_clip=False, num_slice=3, is_train=False)
return_statement: return im, im_scale, c
docstring: load volume, windowing, interpolate multiple slices, clip black border, resize according to spacing
docstring_summary: load volume, windowing, interpolate multiple slices, clip black border, resize according to spacing
docstring_tokens: load volume windowing interpolate multiple slices clip black border resize according to spacing
function: def load_prep_img(data_dir, imname, spacing, slice_intv, do_clip=False, num_slice=3, is_train=False):
      """load volume, windowing, interpolate multiple slices, clip black border, resize according to spacing"""
      im, mask = load_multislice_img_16bit_png(data_dir, imname, slice_intv, do_clip, num_slice)
  
      im = windowing(im, cfg.INPUT.WINDOWING)
  
      if do_clip:  # clip black border
          c = get_range(mask, margin=0)
          if cfg.INPUT.DATA_AUG_POSITION is not False and is_train:
              offset_aug = np.random.randint(16)-8
              c[0] += offset_aug
              offset_aug = np.random.randint(16)-8
              c[2] += offset_aug
              c = [max(0, val) for val in c]
          im = im[c[0]:c[1] + 1, c[2]:c[3] + 1, :]
          # mask = mask[c[0]:c[1] + 1, c[2]:c[3] + 1]
          # print(im.shape)
      else:
          c = [0, im.shape[0]-1, 0, im.shape[1]-1]
  
      im_shape = im.shape[0:2]
      if spacing is not None and cfg.INPUT.NORM_SPACING > 0:  # spacing adjust, will overwrite simple scaling
          im_scale = float(spacing) / cfg.INPUT.NORM_SPACING
      else:
          im_scale = float(cfg.INPUT.MAX_IM_SIZE) / float(np.max(im_shape))  # simple scaling
  
      if cfg.INPUT.DATA_AUG_SCALE is not False and is_train:
          aug_scale = cfg.INPUT.DATA_AUG_SCALE
          im_scale *= np.random.rand(1)*(aug_scale[1]-aug_scale[0])+aug_scale[0]
      max_shape = np.max(im_shape)*im_scale
      if max_shape > cfg.INPUT.MAX_IM_SIZE:
          im_scale1 = float(cfg.INPUT.MAX_IM_SIZE) / max_shape
          im_scale *= im_scale1
  
      if im_scale != 1:
          im = cv2.resize(im, None, None, fx=im_scale, fy=im_scale, interpolation=cv2.INTER_LINEAR)
          # mask = cv2.resize(mask, None, None, fx=im_scale, fy=im_scale, interpolation=cv2.INTER_LINEAR)
  
      return im, im_scale, c
function_tokens: def load_prep_img ( data_dir , imname , spacing , slice_intv , do_clip = False , num_slice = 3 , is_train = False ) : im , mask = load_multislice_img_16bit_png ( data_dir , imname , slice_intv , do_clip , num_slice ) im = windowing ( im , cfg . INPUT . WINDOWING ) if do_clip : # clip black border c = get_range ( mask , margin = 0 ) if cfg . INPUT . DATA_AUG_POSITION is not False and is_train : offset_aug = np . random . randint ( 16 ) - 8 c [ 0 ] += offset_aug offset_aug = np . random . randint ( 16 ) - 8 c [ 2 ] += offset_aug c = [ max ( 0 , val ) for val in c ] im = im [ c [ 0 ] : c [ 1 ] + 1 , c [ 2 ] : c [ 3 ] + 1 , : ] # mask = mask[c[0]:c[1] + 1, c[2]:c[3] + 1] # print(im.shape) else : c = [ 0 , im . shape [ 0 ] - 1 , 0 , im . shape [ 1 ] - 1 ] im_shape = im . shape [ 0 : 2 ] if spacing is not None and cfg . INPUT . NORM_SPACING > 0 : # spacing adjust, will overwrite simple scaling im_scale = float ( spacing ) / cfg . INPUT . NORM_SPACING else : im_scale = float ( cfg . INPUT . MAX_IM_SIZE ) / float ( np . max ( im_shape ) ) # simple scaling if cfg . INPUT . DATA_AUG_SCALE is not False and is_train : aug_scale = cfg . INPUT . DATA_AUG_SCALE im_scale *= np . random . rand ( 1 ) * ( aug_scale [ 1 ] - aug_scale [ 0 ] ) + aug_scale [ 0 ] max_shape = np . max ( im_shape ) * im_scale if max_shape > cfg . INPUT . MAX_IM_SIZE : im_scale1 = float ( cfg . INPUT . MAX_IM_SIZE ) / max_shape im_scale *= im_scale1 if im_scale != 1 : im = cv2 . resize ( im , None , None , fx = im_scale , fy = im_scale , interpolation = cv2 . INTER_LINEAR ) # mask = cv2.resize(mask, None, None, fx=im_scale, fy=im_scale, interpolation=cv2.INTER_LINEAR) return im , im_scale , c