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_3.h"
28 VisionProblem_3::VisionProblem_3() { }
30 void VisionProblem_3::generate(int label, Vignette *vignette) {
33 const int dist_min = Vignette::width / 8;
36 const int max_nb_attempts = 100;
44 for(int s = 0; nb_attempts < max_nb_attempts && s < nb_shapes; s++) {
47 int xs, ys, i, right_margin, right_connection;
53 xs = int(drand48() * Vignette::width);
54 ys = int(drand48() * Vignette::height);
55 shape.randomize(part_size, hole_size);
56 } while(shape.overwrites(&tmp, xs, ys)); // check not out-of-vignette
62 right_margin = !shape.overwrites(&avoid, xs, ys);
65 if((label && (s == 1 || s == 3)) || (!label && (s >= 2))) {
66 right_connection = shape.overwrites(vignette, xs, ys);
73 } while(nb_attempts < max_nb_attempts && !right_margin);
75 shape.draw(&tmp, xs, ys);
78 if(right_margin && right_connection) {
79 if((label && (s == 1 || s == 3)) || (!label && (s >= 2))) {
80 i = vignette->intersection(&tmp);
81 right_connection = (i > 0) && (i < 4);
85 } else right_connection = 0; // To avoid compilation warning
86 } while(nb_attempts < max_nb_attempts && (!right_margin || !right_connection));
88 if(nb_attempts < max_nb_attempts) {
89 shape.draw(vignette, xs, ys);
90 vignette->fill(xs, ys, 128);
91 if((label && s < 2) || (!label && s < 1)) {
92 for(int k = 0; k < dist_min; k++) tmp.grow();
93 avoid.superpose(&avoid, &tmp);
97 } while(nb_attempts >= max_nb_attempts);
99 vignette->replace_value(128, 255);