class_docstr: DBNet as described in `"Real-time Scene Text Detection with Differentiable Binarization"
  <https://arxiv.org/pdf/1911.08947.pdf>`_.
  
  Args:
  ----
      feature extractor: the backbone serving as feature extractor
      fpn_channels: number of channels each extracted feature maps is mapped to
class_docstr_tok: ["DBNet","as","described","in","`","``","Real-time","Scene","Text","Detection","with","Differentiable","Binarization","''","<","https",":","\/\/arxiv.org\/pdf\/1911.08947.pdf",">","`","_",".","Args",":","--","--","feature","extractor",":","the","backbone","serving","as","feature","extractor","fpn_channels",":","number","of","channels","each","extracted","feature","maps","is","mapped","to"]
docstr: Draw a polygon treshold map on a canvas, as described in the DB paper
  
  Args:
  ----
      polygon : array of coord., to draw the boundary of the polygon
      canvas : threshold map to fill with polygons
      mask : mask for training on threshold polygons
docstr_tok: ["Draw","a","polygon","treshold","map","on","a","canvas",",","as","described","in","the","DB","paper","Args",":","--","--","polygon",":","array","of","coord.",",","to","draw","the","boundary","of","the","polygon","canvas",":","threshold","map","to","fill","with","polygons","mask",":","mask","for","training","on","threshold","polygons"]
code: def draw_thresh_map(
      self,
      polygon: np.ndarray,
      canvas: np.ndarray,
      mask: np.ndarray,
  ) -> Tuple[np.ndarray, np.ndarray, np.ndarray]:
      """Draw a polygon treshold map on a canvas, as described in the DB paper
  
      Args:
      ----
          polygon : array of coord., to draw the boundary of the polygon
          canvas : threshold map to fill with polygons
          mask : mask for training on threshold polygons
      """
      if polygon.ndim != 2 or polygon.shape[1] != 2:
          raise AttributeError(
              "polygon should be a 2 dimensional array of coords"
          )
  
      # Augment polygon by shrink_ratio
      polygon_shape = Polygon(polygon)
      distance = (
          polygon_shape.area
          * (1 - np.power(self.shrink_ratio, 2))
          / polygon_shape.length
      )
      subject = [
          tuple(coor) for coor in polygon
      ]  # Get coord as list of tuples
      padding = pyclipper.PyclipperOffset()
      padding.AddPath(
          subject, pyclipper.JT_ROUND, pyclipper.ET_CLOSEDPOLYGON
      )
      padded_polygon: np.ndarray = np.array(
          padding.Execute(distance)[0]
      )
  
      # Fill the mask with 1 on the new padded polygon
      cv2.fillPoly(mask, [padded_polygon.astype(np.int32)], 1.0)  # type: ignore[call-overload]
  
      # Get min/max to recover polygon after distance computation
      xmin = padded_polygon[:, 0].min()
      xmax = padded_polygon[:, 0].max()
      ymin = padded_polygon[:, 1].min()
      ymax = padded_polygon[:, 1].max()
      width = xmax - xmin + 1
      height = ymax - ymin + 1
      # Get absolute polygon for distance computation
      polygon[:, 0] = polygon[:, 0] - xmin
      polygon[:, 1] = polygon[:, 1] - ymin
      # Get absolute padded polygon
      xs: np.ndarray = np.broadcast_to(
          np.linspace(0, width - 1, num=width).reshape(1, width),
          (height, width),
      )
      ys: np.ndarray = np.broadcast_to(
          np.linspace(0, height - 1, num=height).reshape(height, 1),
          (height, width),
      )
  
      # Compute distance map to fill the padded polygon
      distance_map = np.zeros(
          (polygon.shape[0], height, width), dtype=polygon.dtype
      )
      for i in range(polygon.shape[0]):
          j = (i + 1) % polygon.shape[0]
          absolute_distance = self.compute_distance(
              xs, ys, polygon[i], polygon[j]
          )
          distance_map[i] = np.clip(absolute_distance / distance, 0, 1)
      distance_map = np.min(distance_map, axis=0)
  
      # Clip the padded polygon inside the canvas
      xmin_valid = min(max(0, xmin), canvas.shape[1] - 1)
      xmax_valid = min(max(0, xmax), canvas.shape[1] - 1)
      ymin_valid = min(max(0, ymin), canvas.shape[0] - 1)
      ymax_valid = min(max(0, ymax), canvas.shape[0] - 1)
  
      # Fill the canvas with the distances computed inside the valid padded polygon
      canvas[
          ymin_valid : ymax_valid + 1, xmin_valid : xmax_valid + 1
      ] = np.fmax(
          1
          - distance_map[
              ymin_valid - ymin : ymax_valid - ymax + height,
              xmin_valid - xmin : xmax_valid - xmax + width,
          ],
          canvas[
              ymin_valid : ymax_valid + 1, xmin_valid : xmax_valid + 1
          ],
      )
  
      return polygon, canvas, mask
  
file_path: doctr/doctr/models/detection/differentiable_binarization/base.py
imports: from typing import Dict, List, Tuple, Union
  import cv2
  import numpy
  import pyclipper
  from shapely.geometry import Polygon
  from ..core import DetectionPostProcessor
label_desc: Use image node_id 2 for calling the _DBNet obj's underlying member method code with example usage: obj.draw_thresh_map(polygon, canvas, mask) and returns: polygon,  canvas,  mask