Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. import matplotlib.image as pli
  3. from skimage.filters import threshold_otsu as otsu
  4. from PIL import Image
  5.  
  6. cnh_cinza = Image.open("cnh.jpg").convert('L')
  7. cnh_cinza.save('cnhcinza.jpg')
  8.  
  9. img = pli.imread('cnhcinza.jpg')
  10. imagem = Image.open('cnhcinza.jpg')
  11.  
  12.  
  13. limiar = otsu(img)
  14.  
  15. mask = img < limiar
  16.  
  17. msk = Image.fromarray(mask,'L')
  18.  
  19. caixa = msk.getbbox()
  20.  
  21. corte = imagem.crop(caixa)
  22.  
  23.  
  24.  
  25. _,ax = plt.subplots (1,3)
  26. ax[0].imshow (img,cmap='gray')
  27. ax[1].imshow (mask,cmap='gray')
  28. ax[2].imshow (corte,cmap='gray')
  29. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement