-
Notifications
You must be signed in to change notification settings - Fork 0
/
Images_Generator.m
133 lines (96 loc) · 3.96 KB
/
Images_Generator.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
function [SECTIONS, MATRICES, IMAGES] = Images_Generator(inputArg1, inputArg2, inputArg3)
%'Images_Generator' transforms a series of vibration signals captured with
%an accelerometer carrying information about the health status of Rolling
%Element Bearings (REBs) into 48 images/signal and stores them into several
%folders to be defined according to the REBs' health status.
%Inputs' description
%'inputArg1' is a cell array containing healthy and faulty REBs'
%time-domain vibration signals. Faults are located on the inner race,
%outer race and balls.
%'inputArg2' is a cell array of the same dimensionality as the latter,
%containing labels for each type of signal ('0' for healthy REBs, '1' for
%REBs with inner race faults, '2' for REBs with faulty balls and '3' for
%REBs with outer race faults), for later classification.
%'inputArg3' is a cell array of the same dimensionality as the
%latter, containing each signal's name for a proper storage.
%Reference
%[1] Cascales Fulgencio, D.; Quiles Cucarella, E.; García Moreno, E.
%Computation and Statistical Analysis of Bearings’ Time- and
%Frequency-Domain Features Enhanced Using Cepstrum Pre-Whitening: A ML-
%and DL-Based Classification.
%Appl. Sci. 2022.
%------------------------------
%Author: David Cascales Fulgencio
%Last revision: 17/09/2022
%------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Define storage cell arrays
SECTIONS = cell(size(inputArg1,1),1);
MATRICES = cell(size(inputArg1,1),1);
IMAGES = cell(size(inputArg1,1),1);
%Define storage folders
folder_0 = 'D:\to be defined';
folder_1 = 'D:\to be defined';
folder_2 = 'D:\to be defined';
folder_3 = 'D:\to be defined';
%Extract 48 images from each raw time-domain signal
for i = 1:size(inputArg1,1)
m = inputArg2{i};
n = inputArg3{i};
sections_i = cell(48,1);
matrices_i = cell(48,1);
images_i = cell(48,1);
if m == 0
for j = 1:48
k = inputArg1{i};
section_j = k(((2500*(j-1))+1):(2500*j));
sections_i{j,:} = section_j;
matrix_j = reshape(section_j,[50,50]);
matrices_i{j,:} = matrix_j;
image_j = mat2gray(matrix_j);
images_i{j,:} = image_j;
file_name = fullfile(folder_0, sprintf(strcat(n,'_%04d.jpg'), i,j));
imwrite(image_j, file_name);
end
elseif m == 1
for j = 1:48
k = inputArg1{i};
section_j = k(((2500*(j-1))+1):(2500*j));
sections_i{j,:} = section_j;
matrix_j = reshape(section_j,[50,50]);
matrices_i{j,:} = matrix_j;
image_j = mat2gray(matrix_j);
images_i{j,:} = image_j;
file_name = fullfile(folder_1, sprintf(strcat(n,'_%04d.jpg'), i,j));
imwrite(image_j, file_name);
end
elseif m == 2
for j = 1:48
k = inputArg1{i};
section_j = k(((2500*(j-1))+1):(2500*j));
sections_i{j,:} = section_j;
matrix_j = reshape(section_j,[50,50]);
matrices_i{j,:} = matrix_j;
image_j = mat2gray(matrix_j);
images_i{j,:} = image_j;
file_name = fullfile(folder_2, sprintf(strcat(n,'_%04d.jpg'), i,j));
imwrite(image_j, file_name);
end
elseif m == 3
for j = 1:48
k = inputArg1{i};
section_j = k(((2500*(j-1))+1):(2500*j));
sections_i{j,:} = section_j;
matrix_j = reshape(section_j,[50,50]);
matrices_i{j,:} = matrix_j;
image_j = mat2gray(matrix_j);
images_i{j,:} = image_j;
file_name = fullfile(folder_3, sprintf(strcat(n,'_%04d.jpg'), i,j));
imwrite(image_j, file_name);
end
end
SECTIONS{i,:} = sections_i;
MATRICES{i,:} = matrices_i;
IMAGES{i,:} = images_i;
end
end