这是使用 OpenCV 在 python 中的工作解决方案:
import cv2 #openCV
import numpy as np
filename = 'zFrkx.jpg' #name of file in quotations here... assumes file is in same dir as .py file
img_gray = cv2.imread(filename, 0) #converts jpg image to grayscale representation
min_val = 100 #try shifting these around to expand or collapse area of interest
max_val = 150
ret, lung_mask = cv2.threshold(img_gray, min_val, max_val, cv2.THRESH_BINARY_INV) #fixed threshold uses values you'll def above
lung_layer = cv2.bitwise_and(img_gray, img_gray, mask = lung_mask)
cv2.imwrite('cake.tif', lung_layer) #outputs desired layer to current working dir
我尝试使用任意设置为 100,150 的阈值运行脚本并得到以下结果,您可以从中选择使用膨胀和分割技术的最大连续元素(http://docs.opencv.org/master/d3/db4/tutorial_py_watershed .html#gsc.tab=0)。
![由于上传问题,LUNG 保存为 jpg](https://i.stack.imgur.com/xHgFH.jpg)
另外,我建议您裁剪底部和顶部 X 像素以剪切文本,因为没有肺会填充图片的顶部或底部。
使用 tif 代替 jpg 格式以避免压缩相关的伪影。
我知道你注意到你也想要髓质(?)白质。很乐意提供帮助,但您能先用简单的英语解释一下您的共享 matlab 代码是如何工作的吗?似乎对 WM 工作得很好。
希望这可以帮助!