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 selector. 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, proper_margin, proper_connection;
53 xs = int(random_uniform_0_1() * Vignette::width);
54 ys = int(random_uniform_0_1() * Vignette::height);
55 shape.randomize(part_size, hole_size);
56 } while(shape.overwrites(&tmp, xs, ys)); // check not out-of-vignette
62 proper_margin = !shape.overwrites(&avoid, xs, ys);
65 if((label && (s == 1 || s == 3)) || (!label && (s >= 2))) {
66 proper_connection = shape.overwrites(vignette, xs, ys);
68 proper_connection = 1;
73 } while(nb_attempts < max_nb_attempts && !proper_margin);
75 shape.draw(s, &tmp, xs, ys);
76 tmp.fill(xs, ys, 128);
78 if(proper_margin && proper_connection) {
79 if((label && (s == 1 || s == 3)) || (!label && (s >= 2))) {
80 i = vignette->intersection(&tmp);
81 proper_connection = (i > 0) && (i < 4);
83 proper_connection = 1;
86 proper_connection = 0; // To avoid compilation warning
88 } while(nb_attempts < max_nb_attempts && (!proper_margin || !proper_connection));
90 if(nb_attempts < max_nb_attempts) {
91 shape.draw(s, vignette, xs, ys);
92 vignette->fill(xs, ys, 128);
93 if((label && s < 2) || (!label && s < 1)) {
94 for(int k = 0; k < dist_min; k++) tmp.grow();
95 avoid.superpose(&avoid, &tmp);
99 } while(nb_attempts >= max_nb_attempts);
101 vignette->replace_value(128, 255);