-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaugment3dPatch.m
More file actions
30 lines (25 loc) · 840 Bytes
/
augment3dPatch.m
File metadata and controls
30 lines (25 loc) · 840 Bytes
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
function patchOut = augment3dPatch(patchIn)
% Randomly rotate and reflect image patches and return the augmented
% patches in a two-column table as required by the trainNetwork function.
%
% Copyright 2018 The MathWorks, Inc.
inpVol = cell(size(patchIn,1),1);
inpResponse = cell(size(patchIn,1),1);
% 5 augmentations: nil,rot90,fliplr,flipud,rot90(fliplr)
fliprot = @(x) rot90(fliplr(x));
augType = {@rot90,@fliplr,@flipud,fliprot};
for id=1:size(patchIn,1)
rndIdx = randi(8,1);
tmpImg = patchIn.InputImage{id};
tmpResp = patchIn.ResponsePixelLabelImage{id};
if rndIdx < 5
out = augType{rndIdx}(tmpImg);
respOut = augType{rndIdx}(tmpResp);
else
out = tmpImg;
respOut = tmpResp;
end
inpVol{id}=out;
inpResponse{id}=respOut;
end
patchOut = table(inpVol,inpResponse);