class_docstr: A general geometric augmentation tool for text images in the CVPR 2020
  paper "Learn to Augment: Joint Data Augmentation and Network Optimization
  for Text Recognition". It applies distortion, stretching, and perspective
  transforms to an image.
  
  This implementation is adapted from
  https://github.com/RubanSeven/Text-Image-Augmentation-python/blob/master/augment.py  # noqa
  
  TODO: Split this transform into three transforms.
  
  Required Keys:
  
  - img
  
  Modified Keys:
  
  - img
  - img_shape
class_docstr_tok: ["A","general","geometric","augmentation","tool","for","text","images","in","the","CVPR","2020","paper","``","Learn","to","Augment",":","Joint","Data","Augmentation","and","Network","Optimization","for","Text","Recognition","''",".","It","applies","distortion",",","stretching",",","and","perspective","transforms","to","an","image",".","This","implementation","is","adapted","from","https",":","\/\/github.com\/RubanSeven\/Text-Image-Augmentation-python\/blob\/master\/augment.py","#","noqa","TODO",":","Split","this","transform","into","three","transforms",".","Required","Keys",":","-","img","Modified","Keys",":","-","img","-","img_shape"]
docstr: Generate the image based on delta.
docstr_tok: ["Generate","the","image","based","on","delta","."]
code: def _gen_img(
      self,
      src: np.ndarray,
      rdx: np.ndarray,
      rdy: np.ndarray,
      dst_w: int,
      dst_h: int,
      grid_size: int,
      trans_ratio: float,
  ) -> np.ndarray:
      """Generate the image based on delta."""
  
      src_h, src_w = src.shape[:2]
      dst = np.zeros_like(src, dtype=np.float32)
  
      for i in np.arange(0, dst_h, grid_size):
          for j in np.arange(0, dst_w, grid_size):
              ni = i + grid_size
              nj = j + grid_size
              w = h = grid_size
              if ni >= dst_h:
                  ni = dst_h - 1
                  h = ni - i + 1
              if nj >= dst_w:
                  nj = dst_w - 1
                  w = nj - j + 1
  
              di = np.reshape(np.arange(h), (-1, 1))
              dj = np.reshape(np.arange(w), (1, -1))
              delta_x = self._bilinear_interp(
                  di / h,
                  dj / w,
                  rdx[i, j],
                  rdx[i, nj],
                  rdx[ni, j],
                  rdx[ni, nj],
              )
              delta_y = self._bilinear_interp(
                  di / h,
                  dj / w,
                  rdy[i, j],
                  rdy[i, nj],
                  rdy[ni, j],
                  rdy[ni, nj],
              )
              nx = j + dj + delta_x * trans_ratio
              ny = i + di + delta_y * trans_ratio
              nx = np.clip(nx, 0, src_w - 1)
              ny = np.clip(ny, 0, src_h - 1)
              nxi = np.array(np.floor(nx), dtype=np.int32)
              nyi = np.array(np.floor(ny), dtype=np.int32)
              nxi1 = np.array(np.ceil(nx), dtype=np.int32)
              nyi1 = np.array(np.ceil(ny), dtype=np.int32)
  
              if len(src.shape) == 3:
                  x = np.tile(
                      np.expand_dims(ny - nyi, axis=-1), (1, 1, 3)
                  )
                  y = np.tile(
                      np.expand_dims(nx - nxi, axis=-1), (1, 1, 3)
                  )
              else:
                  x = ny - nyi
                  y = nx - nxi
              dst[i : i + h, j : j + w] = self._bilinear_interp(
                  x,
                  y,
                  src[nyi, nxi],
                  src[nyi, nxi1],
                  src[nyi1, nxi],
                  src[nyi1, nxi1],
              )
  
      dst = np.clip(dst, 0, 255)
      dst = np.array(dst, dtype=np.uint8)
  
      return dst
  
imports: import math
  import random
  from typing import Dict, List, Optional, Tuple
  import cv2
  import mmcv
  import numpy
  from mmcv.transforms.base import BaseTransform
  from mmcv.transforms.utils import cache_randomness
  from mmocr.registry import TRANSFORMS
label_desc: Use image node_id 8 for calling the TextRecogGeneralAug obj's underlying member method code with example usage: obj._gen_img(src, rdx, rdy, dst_w, dst_h, grid_size, trans_ratio) and returns: dst