①在对肺部CT图像进行处理过程中,需要初步提取肺实质区域。用到了bwboundaries函数进行边界标记。
clear
clc
I = imread('IMG-0025-00001.jpg');%read pic
p=imcomplement(I);
se=strel('square',2);
se1=strel('disk',2);
bw=imerode(p,se);
[L,N]=bwlabel(bw,4);
s = regionprops(L,'Area');
bw1=ismember(L,find([s.Area]>=10000 & [s.Area]<=50000 ));
bw2=imerode(bw1,se);
%bw2=imdilate(bw2,se1);
bw2=imerode(bw2,se);
bw2=imdilate(bw2,se1);
%bw2 = bwmorph(bw2,'thin',Inf);
%bw2 = imclearborder(bw2);
%bw2=imerode(bw2,se1);
[B,L]=bwboundaries(bw2);
bw3=bwperim(bw2);%boundaries
figure;subplot(2,3,1);imshow(p);title('binaryinvert');
subplot(2,3,2);imshow(bw);title('beforeimeroderegionpops');
subplot(2,3,3);imshow(bw1);title('afterimerodese>10000<50000');
subplot(2,3,4);imshow(bw2);title('imdilatese');
subplot(2,3,5);imshow(bw3);title('boundaries');
subplot(2,3,6);imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 1)
end
;title('contur');
使用MATLAP版本为7.0英文版,所以目录及文件中都不能有中文。图像最好放在源文件同一目录中。目录分布
②原始图像(经过阈值处理后)我们要做的是提取图像中两个大的黑色区域,分别为左右肺实质。而中间的类圆形黑色区域为肺气管,需要去除。至于白色区域为胸腔骨骼等组织。: