How to create a Binary Mask for medical images
Hello,
I'm try to create binary mask for medical images, im new to OpenCV and any advice will help on how, or if it possible, to do so with OpenCV. Below is the type of pictures I try to create mask for:
I need to color the vocal cords area in white(Marked with triangle) and the rest in black, so it will look something like that:
i tried to find the contours using that code:
import cv2
import numpy as np
img = cv2.imread("LPR.png", cv2.IMREAD_GRAYSCALE)
_, threshold = cv2.threshold(img, 50, 255, cv2. THRESH_BINARY_INV)
_, contours, _ = cv2.findContours(threshold, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
for cnt in contours:
cv2.drawContours(img, [cnt], 0, (0))
cv2.imshow("LPR", img)
cv2.imshow("Threshold", threshold)
cv2.waitKey(0)
this is the result:
i tried to clean the rest of the image using some adaptiveThreshold but the result was worse. i also try to detect the triangle shape that created by the Vocal cords, also without success.
Does anyone have any suggestions on how I can get the desired result or what method I can use?
Any advice will help, Thanks.
The original image for example:
you may need some grabcut or gmm method (which is good for the image with similar color in ROI but bad contours) to extract the triangle region
@Sagi. Can you post original image w/out marking triangle?
@supra56 I added the original image, Thank you.
In line 4.Whitespaces
cv2. THRESH_BINARY_INV
should becv2.THRESH_BINARY_INV