2 * svrt is the ``Synthetic Visual Reasoning Test'', an image
3 * generator for evaluating classification performance of machine
4 * learning systems, humans and primates.
6 * Copyright (c) 2009 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of svrt.
11 * svrt is free software: you can redistribute it and/or modify it
12 * under the terms of the GNU General Public License version 3 as
13 * published by the Free Software Foundation.
15 * svrt is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with svrt. If not, see <http://www.gnu.org/licenses/>.
25 #include "vision_problem_13.h"
28 VisionProblem_13::VisionProblem_13() { }
30 void VisionProblem_13::generate(int label, Vignette *vignette) {
31 Shape big_shape, small_shape;
32 int big_xs1, big_ys1, small_xs1, small_ys1;
33 int big_xs2, big_ys2, small_xs2, small_ys2;
34 int translated_small_xs, translated_small_ys;
36 const int dist_min = Vignette::width/4;
38 const int max_nb_attempts = 100;
46 big_shape.randomize(big_part_size / 2, big_part_hole_size / 2);
50 big_xs1 = int(drand48() * Vignette::width);
51 big_ys1 = int(drand48() * Vignette::height);
53 } while(nb_attempts < max_nb_attempts &&
54 big_shape.overwrites(vignette, big_xs1, big_ys1));
56 big_shape.draw(vignette, big_xs1, big_ys1);
57 big_shape.draw(&tmp, big_xs1, big_ys1);
58 for(int k = 0; k < dist_min; k++) tmp.grow();
61 small_shape.randomize(small_part_size / 2, small_part_hole_size / 2);
62 small_xs1 = int(drand48() * Vignette::width);
63 small_ys1 = int(drand48() * Vignette::height);
65 } while(nb_attempts < max_nb_attempts &&
66 (!small_shape.overwrites(&tmp, small_xs1, small_ys1) ||
67 small_shape.overwrites(vignette, small_xs1, small_ys1)));
69 small_shape.draw(vignette, small_xs1, small_ys1);
73 big_xs2 = int(drand48() * Vignette::width);
74 big_ys2 = int(drand48() * Vignette::height);
76 } while(nb_attempts < max_nb_attempts &&
77 big_shape.overwrites(vignette, big_xs2, big_ys2));
78 big_shape.draw(vignette, big_xs2, big_ys2);
79 big_shape.draw(&tmp, big_xs2, big_ys2);
80 for(int k = 0; k < dist_min; k++) tmp.grow();
82 translated_small_xs = small_xs1 + (big_xs2 - big_xs1);
83 translated_small_ys = small_ys1 + (big_ys2 - big_ys1);
85 } while(nb_attempts < max_nb_attempts &&
86 small_shape.overwrites(vignette,
88 translated_small_ys));
91 small_xs2 = translated_small_xs;
92 small_ys2 = translated_small_ys;
95 small_xs2 = int(drand48() * Vignette::width);
96 small_ys2 = int(drand48() * Vignette::height);
98 } while(nb_attempts < max_nb_attempts &&
99 (sq(small_xs2 - translated_small_xs) + sq(small_ys2 - translated_small_ys) < sq(dist_min) ||
100 !small_shape.overwrites(&tmp, small_xs2, small_ys2) ||
101 small_shape.overwrites(vignette, small_xs2, small_ys2)));
103 } while(nb_attempts >= max_nb_attempts);
104 small_shape.draw(vignette, small_xs2, small_ys2);