-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathlungSegment.m
37 lines (21 loc) · 875 Bytes
/
lungSegment.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
function lungSegment
%code for segmentation using ground truth
imageDir = dir('/path/dataset/Grayscale/COPD/*.png'); % the folder in which ur images exists
maskDir = dir('/path/dataset/GroundTruth/COPD/*.png');
outputDir = '/path/dataset/Output/COPD';
for i = 1 : length(imageDir)
imageFilename = strcat('/path/dataset/Grayscale/COPD/',imageDir(i).name);
maskFileName = strcat('/path/dataset/GroundTruth/COPD/',maskDir(i).name);
image = imread(imageFilename);
maskImage=imread(maskFileName);
maskImage=rgb2gray(maskImage);
mask = zeros(size(maskImage));
mask(25:end-25,25:end-25) = 1;
bw = activecontour(maskImage,mask,2000);
binary = logical(bw);
image(~binary)=0;
outputFileName = sprintf('%d.png',i);
imwrite(image, fullfile(outputDir, outputFileName));
end
disp('finish');
end