Created
January 17, 2020 18:29
-
-
Save fiorentinogiuseppe/cfccd7035be3e9acb2e84c8c55a07c91 to your computer and use it in GitHub Desktop.
Função que aplica a binarização na imagem
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def binarization(image): | |
""" | |
Função que aplica a binarização na imagem. | |
Parameters | |
---------- | |
image : PIL.Image.Image | |
Imagem para ser binarizada. | |
Returns | |
------- | |
PIL.Image.Image | |
Imagem binarizada. | |
""" | |
image = image.convert('RGB') | |
npimage = np.asarray(image).astype(np.uint8) | |
npimage[:, :, 0] = 0 | |
npimage[:, :, 2] = 0 | |
im = cv2.cvtColor(npimage, cv2.COLOR_RGB2GRAY) | |
ret, thresh = cv2.threshold(im, 80, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) | |
binimage = Image.fromarray(thresh) | |
return binimage |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment