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 thebgr2gray
function. - threshold (
int
): Threshold type. There are two types of thresholds:cv2.THRESH_BINARY
:cv2.THRESH_OTSU + cv2.THRESH_BINARY
cv2.THRESH_BINARY_INV
:cv2.THRESH_OTSU + cv2.THRESH_BINARY_INV
- color_base (
str
): Color space of the input image. Default is'BGR'
.
- img (
-
Returns:
- np.ndarray: Binarized image.
-
Example:
import docsaidkit as D
img = D.imread('lena.png')
bin_img = D.imbinarize(img)