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_14.h"
28 VisionProblem_14::VisionProblem_14() { }
30 void VisionProblem_14::sample_shapes_positions_aligned(int nb_shapes, int *xs, int *ys) {
31 for(int n = 0; n < nb_shapes - 1; n++) {
32 xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size + 1)) + part_size/2;
33 ys[n] = int(random_uniform_0_1() * (Vignette::height - part_size + 1)) + part_size/2;
35 scalar_t alpha = random_uniform_0_1();
36 xs[nb_shapes - 1] = int(alpha * xs[0] + (1 - alpha) * xs[1]);
37 ys[nb_shapes - 1] = int(alpha * ys[0] + (1 - alpha) * ys[1]);
40 void VisionProblem_14::sample_shapes_positions_uniformly(int nb_shapes, int *xs, int *ys) {
41 for(int n = 0; n < nb_shapes; n++) {
42 xs[n] = int(random_uniform_0_1() * (Vignette::width - part_size + 1)) + part_size/2;
43 ys[n] = int(random_uniform_0_1() * (Vignette::height - part_size + 1)) + part_size/2;
47 int VisionProblem_14::there_is_an_alignment(scalar_t dist_threshold, int nb_shapes, int *xs, int *ys) {
48 for(int a = 0; a < nb_shapes; a++) {
49 for(int b = 0; b < nb_shapes; b++) {
50 for(int c = 0; c < b; c++) {
51 if(a != b && a != c) {
52 if(point_in_band(scalar_t(xs[a]), scalar_t(ys[a]),
53 scalar_t(xs[b]), scalar_t(ys[b]),
54 scalar_t(xs[c]), scalar_t(ys[c]),
55 dist_threshold)) return 1;
64 void VisionProblem_14::generate(int label, Vignette *vignette) {
66 int xs[nb_shapes], ys[nb_shapes];
71 sample_shapes_positions_aligned(nb_shapes, xs, ys);
74 sample_shapes_positions_uniformly(nb_shapes, xs, ys);
75 } while(there_is_an_alignment(Vignette::width/20, 3, xs, ys));
83 for(int n = 0; n < nb_shapes; n++) {
85 shape.randomize(part_size/2, hole_size/2);
87 error |= shape.overwrites(vignette, xs[n], ys[n]);
89 shape.draw(n, vignette, xs[n], ys[n]);