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/>.
26 #include "rgb_image.h"
28 void Vignette::clear() {
29 for(int k = 0; k < width * height; k++) {
34 void Vignette::write_png(const char *name, int delta) {
35 RGBImage result(width * delta - (delta > 1 ? 1 : 0), height * delta - (delta > 1 ? 1 : 0));
36 for(int y = 0; y < result.height(); y++) {
37 for(int x = 0; x < result.width(); x++) {
39 if(delta > 4 && (x%delta == 0 || y%delta == 0)) {
42 c = content[(x / delta) + width * (y / delta)];
44 result.set_pixel(x, y, c, c, c);
48 result.write_png(name);
51 void Vignette::fill(int x, int y, int v) {
52 if(x >= 0 && x < Vignette::width && y >= 0 && y < Vignette::height &&
53 content[x + Vignette::width * y] == 255) {
54 content[x + Vignette::width * y] = v;
62 void Vignette::switch_values(int v1, int v2) {
63 for(int k = 0; k < Vignette::height * Vignette::width; k++) {
64 if(content[k] == v1) {
66 } else if(content[k] == v2) {
72 void Vignette::replace_value(int from, int to) {
73 for(int k = 0; k < Vignette::height * Vignette::width; k++) {
74 if(content[k] == from) {
80 void Vignette::superpose(Vignette *infront, Vignette *inback) {
81 for(int k = 0; k < Vignette::height * Vignette::width; k++) {
82 if(infront->content[k] < 255) {
83 content[k] = infront->content[k];
85 content[k] = inback->content[k];
90 int Vignette::surface() {
92 for(int k = 0; k < Vignette::height * Vignette::width; k++) {
93 if(content[k] < 255) {
100 int Vignette::intersection(Vignette *v) {
102 for(int k = 0; k < Vignette::height * Vignette::width; k++) {
103 if(content[k] < 255 && v->content[k] < 255) {
110 void Vignette::grow() {
111 int tmp[Vignette::width * Vignette::height];
112 for(int k = 0; k < Vignette::height * Vignette::width; k++) {
116 for(int y = 1; y < Vignette::height - 1; y++) {
117 for(int x = 1; x < Vignette::width - 1; x++) {
118 k = x + Vignette::width * y;
119 content[k] = min(tmp[k],
120 min(min(tmp[k - Vignette::width], tmp[k - 1]),
121 min(tmp[k + 1], tmp[k + Vignette::width])));