I want to extract the endotracheal region from the MRI
of the Sagittal plane of the neck image, but after applying image processing techniques like thresholding, contour detection and binary masking,
I could find that there are other undesired regions as well which are being extracted along with the required region of interest.
import cv2 as cv
import numpy as np
img = cv.imread('sam_mri01.jpg')
cv.imshow('pre1',img)
image_contours = np.zeros((img.shape[1],
img.shape[0], 1),
np.uint8)
binary_img = np.zeros((img.shape[1],
img.shape[0], 1),
np.uint8)
for channel in range(img.shape[2]):
ret, thresh_img = cv.threshold(img[:, :, channel],
25, 255,
cv.THRESH_BINARY)
cv.imshow('pre3', thresh_img)
contours = cv.findContours(thresh_img, 1, 1)[0]
cv.drawContours(image_contours,
contours, -1,
(255,255,255), 1)
cv.imshow('pre4',image_contours)
contours = cv.findContours(image_contours, cv.RETR_LIST,
cv.CHAIN_APPROX_SIMPLE)[0]
cv.drawContours(binary_img, [max(contours, key = cv.contourArea)],
-1, (255, 255, 255), -1)
cv.imshow('result', binary_img)
cv.imwrite('result.jpg',binary_img)
cv.waitKey(0)
The image:
the result obtained:
.
I want only the particular tube-like endotracheal channel to be extracted or differentiated. the other regions in black need to be eliminated from the result and this has to be done automatically for any image of this type so that I don't need to set different parameters for different images. The region of interest is the black coloured channel which is the endotracheal region: