Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
lixilinx authored Nov 29, 2018
1 parent 0f44e04 commit 7c518fa
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 0 deletions.
54 changes: 54 additions & 0 deletions svhn/extra_preprocessing.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
clear all; close all; clc;
load digitStruct.mat
Images12 = zeros(64,64,3,length(digitStruct),'uint8');
Labels12 = cell(length(digitStruct), 1);
max_label_len = 0;
%MatFileName = 'extra.mat'
echo = false
for i = 1:length(digitStruct)
im = imread([digitStruct(i).name]);
min_aa=inf; min_cc=inf; max_bb=-inf; max_dd=-inf;
label = [];
for j = 1:length(digitStruct(i).bbox)
[height, width, ~] = size(im);
aa = max(digitStruct(i).bbox(j).top+1,1);
bb = min(digitStruct(i).bbox(j).top+digitStruct(i).bbox(j).height, height);
cc = max(digitStruct(i).bbox(j).left+1,1);
dd = min(digitStruct(i).bbox(j).left+digitStruct(i).bbox(j).width, width);

%imshow(im(aa:bb, cc:dd, :));
%fprintf('%d\n',digitStruct(i).bbox(j).label );
%pause(eps);

min_aa=min(min_aa, aa);
min_cc=min(min_cc, cc);
max_bb=max(max_bb, bb);
max_dd=max(max_dd, dd);
label = [label, num2str(mod(digitStruct(i).bbox(j).label, 10))];
end
max_label_len = max(max_label_len, length(label));

extend = 1/7*(6 - length(label));
centre = 0.5*[max_bb+min_aa, max_dd+min_cc];
half_crop_size = (1 + extend)*max(max_bb - min_aa, max_dd - min_cc)/2;

bound_aa = max(round(centre(1) - half_crop_size), 1);
bound_bb = min(round(centre(1) + half_crop_size), height);
bound_cc = max(round(centre(2) - half_crop_size), 1);
bound_dd = min(round(centre(2) + half_crop_size), width);
scaled_im = imresize(im(bound_aa:bound_bb, bound_cc:bound_dd, :), [64,64]);
if echo
imshow(scaled_im);
title(label)
pause(1)
end
Images12(:,:,:,i) = scaled_im;
Labels12{i} = label;
end
Images = Images12(:,:,:,1:2:end);
Labels = Labels12(1:2:end);
save('extra_part1.mat', 'Images', 'Labels', '-v7');
Images = Images12(:,:,:,2:2:end);
Labels = Labels12(2:2:end);
save('extra_part2.mat', 'Images', 'Labels', '-v7');
max_label_len
49 changes: 49 additions & 0 deletions svhn/test_preprocessing.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
clear all; close all; clc;
load digitStruct.mat
Images = zeros(64,64,3,length(digitStruct),'uint8');
Labels = cell(length(digitStruct), 1);
max_label_len = 0;
MatFileName = 'test.mat'
echo = false
for i = 1:length(digitStruct)
im = imread([digitStruct(i).name]);
min_aa=inf; min_cc=inf; max_bb=-inf; max_dd=-inf;
label = [];
for j = 1:length(digitStruct(i).bbox)
[height, width, ~] = size(im);
aa = max(digitStruct(i).bbox(j).top+1,1);
bb = min(digitStruct(i).bbox(j).top+digitStruct(i).bbox(j).height, height);
cc = max(digitStruct(i).bbox(j).left+1,1);
dd = min(digitStruct(i).bbox(j).left+digitStruct(i).bbox(j).width, width);

%imshow(im(aa:bb, cc:dd, :));
%fprintf('%d\n',digitStruct(i).bbox(j).label );
%pause(eps);

min_aa=min(min_aa, aa);
min_cc=min(min_cc, cc);
max_bb=max(max_bb, bb);
max_dd=max(max_dd, dd);
label = [label, num2str(mod(digitStruct(i).bbox(j).label, 10))];
end
max_label_len = max(max_label_len, length(label));

extend = 1/7*(6 - length(label));
centre = 0.5*[max_bb+min_aa, max_dd+min_cc];
half_crop_size = (1 + extend)*max(max_bb - min_aa, max_dd - min_cc)/2;

bound_aa = max(round(centre(1) - half_crop_size), 1);
bound_bb = min(round(centre(1) + half_crop_size), height);
bound_cc = max(round(centre(2) - half_crop_size), 1);
bound_dd = min(round(centre(2) + half_crop_size), width);
scaled_im = imresize(im(bound_aa:bound_bb, bound_cc:bound_dd, :), [64,64]);
if echo
imshow(scaled_im);
title(label)
pause(1)
end
Images(:,:,:,i) = scaled_im;
Labels{i} = label;
end
save(MatFileName, 'Images', 'Labels', '-v7');
max_label_len
49 changes: 49 additions & 0 deletions svhn/train_preprocessing.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
clear all; close all; clc;
load digitStruct.mat
Images = zeros(64,64,3,length(digitStruct),'uint8');
Labels = cell(length(digitStruct), 1);
max_label_len = 0;
MatFileName = 'train.mat'
echo = false
for i = 1:length(digitStruct)
im = imread([digitStruct(i).name]);
min_aa=inf; min_cc=inf; max_bb=-inf; max_dd=-inf;
label = [];
for j = 1:length(digitStruct(i).bbox)
[height, width, ~] = size(im);
aa = max(digitStruct(i).bbox(j).top+1,1);
bb = min(digitStruct(i).bbox(j).top+digitStruct(i).bbox(j).height, height);
cc = max(digitStruct(i).bbox(j).left+1,1);
dd = min(digitStruct(i).bbox(j).left+digitStruct(i).bbox(j).width, width);

%imshow(im(aa:bb, cc:dd, :));
%fprintf('%d\n',digitStruct(i).bbox(j).label );
%pause(eps);

min_aa=min(min_aa, aa);
min_cc=min(min_cc, cc);
max_bb=max(max_bb, bb);
max_dd=max(max_dd, dd);
label = [label, num2str(mod(digitStruct(i).bbox(j).label, 10))];
end
max_label_len = max(max_label_len, length(label));

extend = 1/7*(6 - length(label));
centre = 0.5*[max_bb+min_aa, max_dd+min_cc];
half_crop_size = (1 + extend)*max(max_bb - min_aa, max_dd - min_cc)/2;

bound_aa = max(round(centre(1) - half_crop_size), 1);
bound_bb = min(round(centre(1) + half_crop_size), height);
bound_cc = max(round(centre(2) - half_crop_size), 1);
bound_dd = min(round(centre(2) + half_crop_size), width);
scaled_im = imresize(im(bound_aa:bound_bb, bound_cc:bound_dd, :), [64,64]);
if echo
imshow(scaled_im);
title(label)
pause(1)
end
Images(:,:,:,i) = scaled_im;
Labels{i} = label;
end
save(MatFileName, 'Images', 'Labels', '-v7');
max_label_len

0 comments on commit 7c518fa

Please sign in to comment.