Advertisement
dan-masek

Untitled

Nov 27th, 2017
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. import cv2
  2. import numpy as np
  3.  
  4. THRESH_LEVEL = 20
  5. TARGET_SIZE = (512,512)
  6.  
  7.  
  8. img = cv2.imread('lungs.png', cv2.IMREAD_GRAYSCALE)
  9.  
  10. _, im_th = cv2.threshold(img, THRESH_LEVEL, 255, cv2.THRESH_BINARY)
  11.  
  12. points = cv2.findNonZero(im_th)
  13. x,y,w,h = cv2.boundingRect(points)
  14.  
  15. roi = img[y:y+h,x:x+w]
  16.  
  17. result = cv2.resize(roi, TARGET_SIZE)
  18.  
  19. cv2.imshow("", result)
  20. cv2.waitKey()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement