-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcifar10_10class_visualization.m
executable file
·97 lines (92 loc) · 3.45 KB
/
cifar10_10class_visualization.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
%Author: Yong Yuan;
%Homepage: yongyuan.name
% load cifar-10 dataset
load cifar-10-batches-mat/data_batch_1.mat;
data1=data;
labels1=labels;
clear data labels;
load cifar-10-batches-mat/data_batch_2.mat;
data2=data;
labels2=labels;
clear data labels;
load cifar-10-batches-mat/data_batch_3.mat;
data3=data;
labels3=labels;
clear data labels;
load cifar-10-batches-mat/data_batch_4.mat;
data4=data;
labels4=labels;
clear data labels;
load cifar-10-batches-mat/data_batch_5.mat;
data5=data;
labels5=labels;
clear data labels;
load cifar-10-batches-mat/test_batch.mat;
data6=data;
labels6=labels;
clear data labels;
database = [data1 labels1; data2 labels2; data3 labels3; data4 labels4; data5 labels5; data6 labels6];
cifar10labels = [labels1; labels2; labels3;labels4; labels5; labels6];
%method = 'show-in-random';
method = 'show-in-class';
switch(method)
%% sort in class
case 'show-in-class'
[sortedLabels, index] = sort(cifar10labels);
dataInClass = database(index, :);
clear database;
numShow = 100;
numInRow = 10;
numPerClass = 6000;
I2 = uint8(zeros(33, 33, 3, numShow)); % 32 and 32 are the size of the output image
for i=1:numInRow
randID = randi(numPerClass, numInRow, 1);
index = randID + (i-1)*numPerClass;
for j=1:length(index)
image_r=dataInClass(index(j,:),1:1024);
image_g=dataInClass(index(j,:),1025:2048);
image_b=dataInClass(index(j,:), 2049:end-1);
image_rer = reshape(image_r, 32, 32);
image_rer(:, end+1) = zeros(length(image_rer), 1);
image_rer(end+1, :) = zeros(1,length(image_rer));
image_reg = reshape(image_g, 32, 32);
image_reg(:, end+1) = zeros(length(image_reg), 1);
image_reg(end+1, :) = zeros(1,length(image_reg));
image_reb = reshape(image_b, 32, 32);
image_reb(:, end+1) = zeros(length(image_reb), 1);
image_reb(end+1, :) = zeros(1,length(image_reb));
image(:, :,1) = image_rer';
image(:, :, 2) = image_reg';
image(:, :, 3) = image_reb';
image = uint8(image);
I2(:, :, :, j+(i-1)*numInRow) = image;
end
end
figure('Color', [1 1 1]); hold on;
montage(I2(:, :, :, :));
%% sort in random
case 'show-in-random'
numInColum = 100;
numInRow = 100;
numImg = 60000;
I2 = uint8(zeros(32, 32, 3, numInRow*numInColum)); % 32 and 32 are the size of the output image
randID = randi(numImg, numInRow*numInColum, 1);
for i=1:numInRow
for j=1:numInColum
% sort with random
image_r=database(randID(j+(i-1)*numInColum,:),1:1024);
image_g=database(randID(j+(i-1)*numInColum,:),1025:2048);
image_b=database(randID(j+(i-1)*numInColum,:), 2049:end-1);
image_rer=reshape(image_r, 32, 32);
image_reg=reshape(image_g, 32, 32);
image_reb=reshape(image_b, 32, 32);
image(:, :,1)=image_rer';
image(:, :, 2)=image_reg';
image(:, :, 3)=image_reb';
image=uint8(image);
I2(:, :, :, j+(i-1)*numInColum) = image;
end
end
figure('Color', [1 1 1]); hold on;
montage(I2(:, :, :, :));
end