Skip to main content

imbinarize

imbinarize(img: np.ndarray, threth: int = cv2.THRESH_BINARY, color_base: str = 'BGR') -> np.ndarray

  • Description: Perform binarization on the input image.

  • Parameters:

    • img (np.ndarray): Input image to be binarized. If the input image is 3-channel, the function will automatically apply the bgr2gray function.
    • threshold (int): Threshold type. There are two types of thresholds:
      1. cv2.THRESH_BINARY: cv2.THRESH_OTSU + cv2.THRESH_BINARY
      2. cv2.THRESH_BINARY_INV: cv2.THRESH_OTSU + cv2.THRESH_BINARY_INV
    • color_base (str): Color space of the input image. Default is 'BGR'.
  • Returns:

    • np.ndarray: Binarized image.
  • Example:

    import docsaidkit as D

    img = D.imread('lena.png')
    bin_img = D.imbinarize(img)

    imbinarize