Matlab中的肺部分割

时间:2015-09-09 19:19:57

标签: image image-processing matlab-figure image-segmentation medical

试图分割出肺部区域,我遇到了很多麻烦。传入图像是这样的:(这实际上是一个jpg转换,每个像素是8位。) enter image description here

I = dicomread('000019.dcm');
I8 = uint8(I / 256);
B = im2bw(I8, 0.007);
segmented = imclearborder(B);

以上脚本生成: enter image description here

Q-1

我对整个内部黑色部分感兴趣 white matter以及。我几天前已经开始matlab,所以我不知道该怎么做。如果你不清楚我想要什么样的输出,请告诉我 - 我会上传一张图片。但我认为没有必要。

Q-2

B = im2bw(I8, 0.007);为什么我需要给出这么低的门槛?阈值越高,一切都是白色或黑色。我已阅读文档,据我了解,值小于0.007的像素标记为黑色,上面的所有内容均为白色。是因为我的16到8位转换?

1 个答案:

答案 0 :(得分:1)

这是使用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 saved as jpg due to upload issues

另外,我建议您裁剪底部和顶部X像素以剪切文字,因为没有肺会填满图片的顶部或底部。

使用tif而不是jpg格式来避免与压缩相关的工件。

我知道你注意到你也喜欢髓质(?)白质。很乐意为此提供帮助,但您能否首先用简单的英语解释您的共享matlab代码是如何工作的?似乎对WM工作得很好。

希望这有帮助!

相关问题