code: def _rotate_cv2(img, angle, expand, fill, interpolation):
      if interpolation == PIL.Image.NEAREST:
          cv_interpolation = cv2.INTER_NEAREST
      elif interpolation == PIL.Image.BILINEAR:
          cv_interpolation = cv2.INTER_LINEAR
      elif interpolation == PIL.Image.BICUBIC:
          cv_interpolation = cv2.INTER_CUBIC
  
      _, H, W = img.shape
      affine_mat = cv2.getRotationMatrix2D((W / 2, H / 2), angle, 1)
      # Logic borrowed from Pillow
      if expand:
          # calculate output size
          yy = []
          xx = []
          for y, x in ((0, 0), (H, 0), (H, W), (0, W)):
              yy.append(
                  affine_mat[1, 0] * x
                  + affine_mat[1, 1] * y
                  + affine_mat[1, 2]
              )
              xx.append(
                  affine_mat[0, 0] * x
                  + affine_mat[0, 1] * y
                  + affine_mat[0, 2]
              )
          out_H = int(np.ceil(max(yy)) - np.floor(min(yy)))
          out_W = int(np.ceil(max(xx)) - np.floor(min(xx)))
  
          affine_mat[1][2] += out_H / 2 - H / 2
          affine_mat[0][2] += out_W / 2 - W / 2
      else:
          out_H = H
          out_W = W
  
      img = img.transpose((1, 2, 0))
      img = cv2.warpAffine(
          img,
          affine_mat,
          (out_W, out_H),
          flags=cv_interpolation,
          borderValue=fill,
      )
      if img.ndim == 2:
          img = img[:, :, None]
      img = img.transpose((2, 0, 1))
      return img
  
imports: from __future__ import division
  import numpy
  import PIL
  import chainer
label_desc: Use image node_id 1 for calling a global function with example usage: _rotate_cv2(img, angle, expand, fill, interpolation) and returns: img