主要内容

Segment Lungs from 3-D Chest Scan

此示例显示了如何使用活动轮廓(SNAkes)执行3-D分段。您可以使用“卷查看器”应用程序查看结果。

准备数据

Load the human chest CT scan data into the workspace. To run this example, you must download the sample data from MathWorks™ using the Add-On Explorer. SeeInstall Sample Data Using Add-On Explorer.

loadChestvolumewhos
Name Size Bytes Class Attributes V 512x512x318 166723584 int16

Convert the CT scan data fromint16tosingleto normalize the values to the range [0, 1].

v = im2single(v);

使用卷查看器应用程序查看胸部扫描。从MATLAB®PoptOugkStrip打开应用程序。您也可以使用使用的应用程序volumeViewercommand and specifying the volume as an argument:VolumeViewer(v). Volume Viewer has preset alphamaps that are intended to provide the best view of certain types of data. To get the best view of the chest scans, select thect-bonepreset.

Segment the Lungs

使用主动轮廓技术在CT扫描数据中分段肺部。主动轮廓是一个区域生长算法,其需要初始种子点。该示例使用图像分段器应用程序通过在XY平面中分割两个正交的2-D切片,在XY平面中分割两个正交的2-D切片来创建此种子掩模。然后,该示例将这两个分段插入3-D掩模。该示例将此掩码传递给activecontourfunction to create a 3-D segmentation of the lungs in the chest cavity. (This example uses the active contour method but you could use other segmentation techniques to accomplish the same goal, such as flood-fill.)

Extract the center slice in both the XY and XZ dimensions.

XY = V(:,:160);XZ =挤压(v(256,:,:));

使用介绍2-D切片imshow.function.

数字imshow(xy,[],'边境','紧');

imshow(xz,[],'边境','紧');

You can perform the segmentation in the Image Segmenter app. Open the app from the MATLAB Apps toolstrip or use theImageStmmoner.命令,指定2-D切片作为参数,ImageStmmoner.(XY).

To start the segmentation process, clickThresholdto open the lung slice in theThreshold标签。在“阈值”选项卡上,选择手动阈值option and move the Threshold slider to specify a threshold value that achieves a good segmentation of the lungs. Click创造面具to accept the thresholding and return the Segmentation tab.

The app executes the following code to threshold the image.

BW = XY> 5.098000E-01;

在此初始肺部分割后,使用选项清理掩码Refine Maskmenu.

In the app, you can click each option to invert the mask image so that the lungs are in the foreground (Invert Mask), remove other segmented elements besides the lungs (清晰的边界), and fill holes inside the lung segmentation (填充孔)。最后,使用Morphology选择平滑肺部分割的边缘。在“形态”选项卡上,选择Erode Maskoperation. After performing these steps, selectShow Binary和save the mask image to the workspace.

该应用程序执行以下代码来改进掩码。

bw = ImComplement(BW);bw = inclearborder(bw);bw = imfill(bw,'洞');radius = 3; decomposition = 0; se = strel('disk',radius,decomposition); BW = imerode(BW, se); maskedImageXY = XY; maskedImageXY(~BW) = 0; imshow(maskedImageXY)

Perform the same operation on the XZ slice. Using Load Image, select theXZvariable. Use thresholding to perform the initial segmentation of the lungs. For the XZ slice, theGlobal Thresholdoption creates an adequate segmentation (the call toimbinarize下面的代码)。与XY片一样,使用options on theRefine Mask菜单创建肺部的抛光分割。在“形态”选项卡上的侵蚀操作中,指定半径为13以清除小型无关物体。

要分段XZ切片并抛光结果,该应用程序执行以下代码。

bw = imbinarize(xz);bw = ImComplement(BW);bw = inclearborder(bw);bw = imfill(bw,'洞');radius = 13; decomposition = 0; se = strel('disk',radius,decomposition); BW = imerode(BW, se); maskedImageXZ = XZ; maskedImageXZ(~BW) = 0; imshow(maskedImageXZ)

Create Seed Mask and Segment Lungs Using activecontour

Create the 3-D seed mask that you can use with theactivecontour用于分割肺部的功能。

Create a logical 3-D volume the same size as the input volume and insertmask_XYmask_XZ在适当的空间位置。

mask = false(大小(v));面具(:,:,160)= maskedimagexy;面具(256,:,:) =掩码(256,:,:) | REPAPE(MaskedImagexz,[1,512,318]);

Using this 3-D seed mask, segment the lungs in the 3-D volume using the active contour method. This operation can take a few minutes. To get a quality segmentation, usehisteq将体素值扩展到可用范围内。

V = histeq(V); BW = activecontour(V,mask,100,'Chan-Vese');semmentedimage = V. *单(BW);

您可以通过运行命令查看卷查看器应用程序中的分段肺部VolumeViewer(SegmentEdimage). By manipulating the alphamap settings in the Rendering Editor, you can get a good view of just the lungs.

Compute the Volume of the Segmented Lungs

Use theregionprops3用来的功能'volume'option to calculate the volume of the lungs.

volLungsPixels = regionprops3(logical(BW),'volume');

Specify the spacing of the voxels in thex,y,和z从原始文件元数据收集的尺寸。元数据不包括在附加资源管理器中下载的图像数据。

spacingx = 0.76;spacingy = 0.76;Spacingz = 1.26 * 1E-6;UnitEvol = spacingx * spacingy * spacingz;Vollungs1 = Vollungspixels.volume(1)* UnitVol;Vollungs2 = Vollungspixels.volume(2)* UnitVol;Vollungsliters = Vollungs1 + Vollungs2
volLungsLiters = 5.7726

See Also

||