-
Notifications
You must be signed in to change notification settings - Fork 0
/
GaborFilter.m
52 lines (46 loc) · 1.22 KB
/
GaborFilter.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
function Out = GaborFilter(Out,Workers)
% Out = GaborFilter(Out,Workers)
if nargin<2
Workers=10;
end
disp('Gabor filter is used');
% set up parallel pool
poolobj = gcp('nocreate');
delete(poolobj);
parpool('local',Workers);
poolobj = gcp('nocreate');
wavelength=2;
orientation=0;
g = gabor(wavelength,orientation);
Layers = size(Out.XTrain,3);
clear GB
for lyr=1:Layers
parfor j=1:size(Out.XTrain,4)
GB(:,:,1,j) = im2uint8(imgaborfilt(im2double(Out.XTrain(:,:,lyr,j)), g));
end
Out.XTrain(:,:,lyr,:)=GB;
clear GB
end
if any(strcmp('XValidation',fieldnames(Out)))==1
if isempty(Out.XValidation)~=1
for lyr=1:Layers
parfor j=1:size(Out.XValidation,4)
GB(:,:,1,j) = im2uint8(imgaborfilt(im2double(Out.XValidation(:,:,lyr,j)), g));
end
Out.XValidation(:,:,lyr,:)=GB;
clear GB
end
end
end
if any(strcmp('XTest',fieldnames(Out)))==1
if isempty(Out.XTest)~=1
for lyr=1:Layers
parfor j=1:size(Out.XTest,4)
GB(:,:,1,j) = im2uint8(imgaborfilt(im2double(Out.XTest(:,:,lyr,j)), g));
end
Out.XTest(:,:,lyr,:)=GB;
clear GB
end
end
end
delete(poolobj);