-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakeNormalisedFigureMatrixFromDataArray.m
36 lines (30 loc) · 1.29 KB
/
makeNormalisedFigureMatrixFromDataArray.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
function AnswerMatrix = makeNormalisedFigureMatrixFromDataArray(data_array)
%{
This function takes in a CIFAR type data-array and make a RGB tensor out
of it. The tensor is then normalized before output, so that the MATLAB
'image' function can be applied on it directly for check the image.
%}
%%
channel_length = max(size(data_array)) / 3;
image_dim = sqrt(channel_length);
red_array = data_array(1:channel_length);
green_array = data_array(channel_length+1:2*channel_length);
blue_array = data_array(2*channel_length + 1:3 * channel_length);
red_matrix = zeros(image_dim,image_dim);
for row=(1:image_dim)
red_matrix(row,:) = red_array(((row-1)*image_dim)+1:((row-1)*image_dim)+image_dim);
end
green_matrix = zeros(image_dim,image_dim);
for row=(1:image_dim)
green_matrix(row,:) = green_array(((row-1)*image_dim)+1:((row-1)*image_dim)+image_dim);
end
blue_matrix = zeros(image_dim,image_dim);
for row=(1:image_dim)
blue_matrix(row,:) = blue_array(((row-1)*image_dim)+1:((row-1)*image_dim)+image_dim);
end
AnswerMatrix = zeros(image_dim,image_dim,3);
AnswerMatrix(:,:,1) = red_matrix;
AnswerMatrix(:,:,2) = green_matrix;
AnswerMatrix(:,:,3) = blue_matrix;
AnswerMatrix = AnswerMatrix./max(max(AnswerMatrix)); %% makes sure things are normlized enough for the image function to work properly
end