|
a |
|
b/Image features calculation code/Working/Utility and Misc/loadRadiologistImages.m |
|
|
1 |
function [ allImages ] = loadRadiologistImages( dirIc, dirIn ) |
|
|
2 |
%LOADRADIOLOGISTSIMAGES Takes two directories of images and creates an |
|
|
3 |
%structure array with all information from those DICOM images |
|
|
4 |
|
|
|
5 |
%Path to crops: '\\ailab03\WeakSegmentation\6K largest slice crops' |
|
|
6 |
%Path to nodules: '\\ailab03\WeakSegmentation\6k largest slice nodules' |
|
|
7 |
|
|
|
8 |
|
|
|
9 |
%% Pre-process |
|
|
10 |
|
|
|
11 |
%append \*.dcm to the end of the string so it will only load dicom |
|
|
12 |
%files |
|
|
13 |
dirIcNew = strcat(dirIc,'\*.dcm'); |
|
|
14 |
|
|
|
15 |
%append \*.dcm to the end of the string so it will only load dicom |
|
|
16 |
%files |
|
|
17 |
dirInNew = strcat(dirIn,'\*.dcm'); |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
|
|
|
21 |
% set the directory where nodule crops are stored |
|
|
22 |
imageCrops = dir(dirIcNew); |
|
|
23 |
% set the directory where nodule are stored |
|
|
24 |
imageNodules = dir(dirInNew); |
|
|
25 |
|
|
|
26 |
|
|
|
27 |
%get size of directory |
|
|
28 |
sizeDir = size(imageCrops,1); |
|
|
29 |
|
|
|
30 |
%create structure array of all dicom info and masks |
|
|
31 |
allImages = struct('imageNumber',0,'imageName',char,... |
|
|
32 |
'originalImage',[],'segmentations',cell(1,1),... |
|
|
33 |
'dicomInfo',struct([]),'map',[],'alpha',[],... |
|
|
34 |
'overlay',[],'segmentationType',char,'masks',... |
|
|
35 |
cell(1,1)); |
|
|
36 |
|
|
|
37 |
sg = 'org'; |
|
|
38 |
|
|
|
39 |
%% load images and masks |
|
|
40 |
|
|
|
41 |
for i = 1:sizeDir |
|
|
42 |
|
|
|
43 |
%get image crop name |
|
|
44 |
ic = char(imageCrops(i).name); |
|
|
45 |
%Construct the file name and path needed to open the file |
|
|
46 |
icfn = sprintf('%s/%s', dirIc, ic); |
|
|
47 |
%load image crop |
|
|
48 |
try |
|
|
49 |
[dicomImage,info,m,a,o] = loadDicom(icfn); |
|
|
50 |
catch ME |
|
|
51 |
% TODO: Handle this exception |
|
|
52 |
end |
|
|
53 |
|
|
|
54 |
%get image nodule name |
|
|
55 |
in = char(imageNodules(i).name); |
|
|
56 |
%Construct the file name and path needed to open the file |
|
|
57 |
infn = sprintf('%s/%s', dirIn, in); |
|
|
58 |
%load image nodule |
|
|
59 |
try |
|
|
60 |
mask = loadDicom(infn); |
|
|
61 |
catch ME |
|
|
62 |
% TODO: Handle this exception |
|
|
63 |
end |
|
|
64 |
|
|
|
65 |
|
|
|
66 |
%change mask to a binary image |
|
|
67 |
mask = logical(mask); |
|
|
68 |
|
|
|
69 |
%save in the structure |
|
|
70 |
%save segmentation type |
|
|
71 |
allImages(i).segmentationType = sg; |
|
|
72 |
%save name |
|
|
73 |
allImages(i).imageName = in; |
|
|
74 |
%save image number |
|
|
75 |
allImages(i).imageNumber = str2num( in(1:(strfind(in,'.')-1)) ); |
|
|
76 |
%save dicom image |
|
|
77 |
allImages(i).originalImage = dicomImage; |
|
|
78 |
%save org dicom information |
|
|
79 |
allImages(i).dicomInfo = info; |
|
|
80 |
%save org dicom map |
|
|
81 |
allImages(i).map = m; |
|
|
82 |
%save org dicom alpha |
|
|
83 |
allImages(i).alpha = a; |
|
|
84 |
%save org dicom overlay |
|
|
85 |
allImages(i).overlay = o; |
|
|
86 |
%save the mask |
|
|
87 |
allImages(i).masks{1} = mask; |
|
|
88 |
|
|
|
89 |
end |
|
|
90 |
|
|
|
91 |
|
|
|
92 |
end |
|
|
93 |
|