-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathparseLabelFolder.m
More file actions
49 lines (43 loc) · 1.48 KB
/
parseLabelFolder.m
File metadata and controls
49 lines (43 loc) · 1.48 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
function [volumeList,labelList,classIndices] = parseLabelFolder(dirPath,vResizeFactor,zStretch)
files = dir(dirPath);
% how many annotated volumes (all that don't have 'Class' in the name)
nVolumes = 0;
for i = 1:length(files)
fName = files(i).name;
if ~contains(fName,'Class') && ~contains(fName,'.mat') && fName(1) ~= '.'
nVolumes = nVolumes+1;
volumePaths{nVolumes} = [dirPath filesep fName];
end
end
% list of class indices per volume
classIndices = [];
[~,volName] = fileparts(volumePaths{1});
for i = 1:length(files)
fName = files(i).name;
k = strfind(fName,'Class');
if contains(fName,volName) && ~isempty(k)
[~,imn] = fileparts(fName);
classIndices = [classIndices str2double(imn(k(1)+5:end))];
end
end
nClasses = length(classIndices);
% read volumes/labels
volumeList = cell(1,nVolumes);
labelList = cell(1,nVolumes);
parfor i = 1:nVolumes
fprintf('parsing training example %d of %d\n', i, nVolumes);
V = volumeRead(volumePaths{i});
V = imresize3(V,[round(vResizeFactor*size(V,1)),...
round(vResizeFactor*size(V,2)),...
round(vResizeFactor*zStretch*size(V,3))]);
[imp,imn] = fileparts(volumePaths{i});
L = uint8(zeros(size(V)));
for j = 1:nClasses
classJ = volumeRead([imp filesep imn sprintf('_Class%d.tif',classIndices(j))]);
classJ = imresize3(classJ,size(V),'nearest');
L(classJ > 0) = j;
end
volumeList{i} = V;
labelList{i} = L;
end
end