1 | initial version |
I obtained better results by changing my approach.Instead of trying to take the brain out of the MRI , I separate the text from the image since the text are completely white.
img = cv2.imread("IM_00024.TIF", 0)
ret, mask = cv2.threshold(img, 254, 255, cv2.THRESH_BINARY)
mask_inv = cv2.bitwise_not(mask)
foreground = cv2.bitwise_and(img, img, mask=mask_inv)
background = cv2.bitwise_and(img, img, mask=mask)
save_img("IM_00024_bg.pnm", background)
save_img("IM_00024_fg.pnm", foreground)