-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwavelet_transform_matlab.m
81 lines (71 loc) · 2.38 KB
/
wavelet_transform_matlab.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
hor_coefficients = [];
vert_coefficients = [];
diagonal_coefficients = [];
approx_coefficients = [];
myDir = uigetdir; %gets directory
myFiles = dir(fullfile(myDir,'*.dcm')); %gets all wav files in struct
for k = 1:808 %ad = 383, cn = 424(training dataset)
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
input = dicomread(fullFileName); %Reads in MRI image
if size(input) ~= [256 256]
k = k - 1;
else
%imshow(input, 'DisplayRange', []);
dwtmode('per');
[C,S] = wavedec2(input, 4, 'db4');
% [cA,cH, cV, cD] = dwt2(y, 'db5')
% hor_coefficients(end+1)=cH(1);
% vert_coefficients(end+1) = cV(1);
% diagonal_coefficients(end+1) = cD(1);
% approx_coefficients(end+1) = cA(1);
A = appcoef2(C,S,'db4',2);
% [H1,V1,D1] = detcoef2('all',C,S,1);
% [H2,V2,D2] = detcoef2('all',C,S,2);
% [H3,V3,D3] = detcoef2('all',C,S,3);
[H4,V4,D4] = detcoef2('all',C,S,2);
D4_1D = reshape(D4,[1, 4096]); % used to be D4 or H4
size_level = size(D4_1D);
disp('new term');
if k == 1
writematrix(D4_1D, 'D4_train.csv')
else
writematrix(D4_1D, 'D4_train.csv', 'WriteMode', 'append')
end
end
%perform dwt within here and store coefficients within array for later use
end
myDir = uigetdir; %gets directory
myFiles = dir(fullfile(myDir,'*.dcm')); %gets all wav files in struct
for k = 1:203 %length(myFiles) ad = 102, cn = 101 for testing
baseFileName = myFiles(k).name;
fullFileName = fullfile(myDir, baseFileName);
input = dicomread(fullFileName);
size(input)
if size(input) ~= [256 256]
k = k - 1;
else
%imshow(input, 'DisplayRange', []);
dwtmode('per');
[C,S] = wavedec2(input, 4, 'db4');
% [cA,cH, cV, cD] = dwt2(y, 'db5')
% hor_coefficients(end+1)=cH(1);
% vert_coefficients(end+1) = cV(1);
% diagonal_coefficients(end+1) = cD(1);
% approx_coefficients(end+1) = cA(1);
A = appcoef2(C,S,'db4',2);
% [H1,V1,D1] = detcoef2('all',C,S,1);
% [H2,V2,D2] = detcoef2('all',C,S,2);
% [H3,V3,D3] = detcoef2('all',C,S,3);
[H4,V4,D4] = detcoef2('all',C,S,2);
D4_1D = reshape(D4,[1, 4096]);
size_level = size(D4_1D);
disp('new term');
if k == 1
writematrix(D4_1D, 'D4_test.csv')
else
writematrix(D4_1D, 'D4_test.csv', 'WriteMode', 'append')
end
end
%perform dwt within here and store coefficients within array for later use
end