Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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:

image description

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:

image description

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: image description

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.

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:

image description

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:

image description

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: image description

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: image description

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:

image description

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:

image description

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: image description

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:

image description