forked from quantombone/exemplarsvm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esvm_generate_dataset.m
96 lines (84 loc) · 2.27 KB
/
esvm_generate_dataset.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
function [Ipos,Ineg] = esvm_generate_dataset(Npos,Nneg)
% Generate a synthetic dataset of circles (see esvm_demo_train_synthetic.m)
% Copyright (C) 2011-12 by Tomasz Malisiewicz
% All rights reserved.
%
% This file is part of the Exemplar-SVM library and is made
% available under the terms of the MIT license (see COPYING file).
% Project homepage: https://github.com/quantombone/exemplarsvm
if nargin == 0
Npos = 3;
Nneg = 10
elseif nargin == 1
Nneg = 10;
end
A = zeros(39,39);
A(20,20)=1;
A = double(bwdist(A)<15);
A = bwmorph(A,'remove');
A = bwmorph(A,'dilate',2);
Asave = repmat(A,[1 1 3]);
Ipos = cell(Npos,1);
for i = 1:Npos
I = rand(100,100,3);
I = rand(50,50,3);
rscale = (rand*.8)+(1.0-.4);
A = imresize(Asave,rscale,'nearest');
I = max(0.0,min(1.0,imresize(I,[100 100],'bicubic')));
sub1 = ceil(rand.*(size(I,1)-size(A,1)-1));
sub2 = ceil(rand.*(size(I,2)-size(A,2)-1));
%A2 = A + rand(size(A)).*(A<.9);
I2 = zeros(size(I));
I2(sub1+(1:size(A,1)),sub2+(1:size(A,2)),:)=A;
inds = find(I2);
I(inds) = 0;
Irand = rand(size(I));
I = .4*I+.6*Irand;
Ipos{i}.I = I;
recs.folder = '';
recs.filename = '';
recs.source = '';
[recs.size.width,recs.size.height,recs.size.depth] = size(I);
recs.segmented = 0;
recs.imgname = sprintf('%08d',i);;
recs.imgsize = size(I);
recs.database = '';
object.class = 'circle';
object.view = '';
object.truncated = 0;
object.occluded = 0;
object.difficult = 0;
object.label = 'circle';
object.bbox = [sub2 sub1 sub2+size(A,2) sub1+size(A,1) ];
object.bndbox.xmin =object.bbox(1);
object.bndbox.ymin =object.bbox(2);
object.bndbox.xmax =object.bbox(3);
object.bndbox.ymax =object.bbox(4);
object.polygon = [];
recs.objects = [object];
%object.mask = [];
%object.hasparts = 0;
%object.par
Ipos{i}.recs = recs;
% Ipos{i}.bbox =
% Ipos{i}.cls = 'synthetic';
% Ipos{i}.curid = sprintf('%05d',i);
% filer = sprintf('%s.%d.%s.mat', Ipos{i}.curid, 1, ...
% 'synthetic');
% Ipos{i}.filer = filer;
% Ipos{i}.objectid = 1;
if 0
figure(1)
clf
imagesc(I)
plot_bbox(bbs{i});
pause
end
end
Ineg = cell(Nneg,1);
for i = 1:Nneg
I = rand(100,100,3);
I = rand(50,50,3);
I = max(0.0,min(1.0,imresize(I,[100 100],'bicubic')));
Ineg{i} = I;
end