Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- THRESH_LEVEL = 20
- TARGET_SIZE = (512,512)
- img = cv2.imread('lungs.png', cv2.IMREAD_GRAYSCALE)
- _, im_th = cv2.threshold(img, THRESH_LEVEL, 255, cv2.THRESH_BINARY)
- points = cv2.findNonZero(im_th)
- x,y,w,h = cv2.boundingRect(points)
- roi = img[y:y+h,x:x+w]
- result = cv2.resize(roi, TARGET_SIZE)
- cv2.imshow("", result)
- cv2.waitKey()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement