2 * folded-ctf is an implementation of the folded hierarchy of
3 * classifiers for object detection, developed by Francois Fleuret
6 * Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
7 * Written by Francois Fleuret <francois.fleuret@idiap.ch>
9 * This file is part of folded-ctf.
11 * folded-ctf is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published
13 * by the Free Software Foundation, either version 3 of the License,
14 * or (at your option) any later version.
16 * folded-ctf is distributed in the hope that it will be useful, but
17 * WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with folded-ctf. If not, see <http://www.gnu.org/licenses/>.
26 #include "rgb_image_subpixel.h"
28 RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * scale, height* scale) { }
30 RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * scale, image->height() * scale) {
31 for(int y = 0; y < _height; y++) {
32 for(int x = 0; x < _width; x++) {
34 image->pixel(x / scale, y / scale, RGBImage::RED),
35 image->pixel(x / scale, y / scale, RGBImage::GREEN),
36 image->pixel(x / scale, y / scale, RGBImage::BLUE));
41 RGBImageSubpixel::~RGBImageSubpixel() { }
43 void RGBImageSubpixel::read_png(const char *filename) {
47 void RGBImageSubpixel::write_png(const char *filename) {
48 RGBImage tmp(_width / scale, _height / scale);
49 for(int y = 0; y < _height / scale; y++) {
50 for(int x = 0; x < _width / scale; x++) {
51 int sr = 0, sg = 0, sb = 0;
52 for(int yy = y * scale; yy < (y + 1) * scale; yy++) {
53 for(int xx = x * scale; xx < (x + 1) * scale; xx++) {
54 sr += int(_bit_plans[RED][yy][xx]);
55 sg += int(_bit_plans[GREEN][yy][xx]);
56 sb += int(_bit_plans[BLUE][yy][xx]);
61 sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
64 tmp.write_png(filename);
68 void RGBImageSubpixel::read_jpg(const char *filename) {
72 void RGBImageSubpixel::write_jpg(const char *filename, int quality) {
73 RGBImage tmp(_width / scale, _height / scale);
75 for(int y = 0; y < _height / scale; y++) {
76 for(int x = 0; x < _width / scale; x++) {
77 int sr = 0, sg = 0, sb = 0;
78 for(int yy = y * scale; yy < (y + 1) * scale; yy++) {
79 for(int xx = x * scale; xx < (x + 1) * scale; xx++) {
80 sr += int(_bit_plans[RED][yy][xx]);
81 sg += int(_bit_plans[GREEN][yy][xx]);
82 sb += int(_bit_plans[BLUE][yy][xx]);
87 sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
91 tmp.write_jpg(filename, quality);
95 void RGBImageSubpixel::draw_line(int thickness,
96 unsigned char r, unsigned char g, unsigned char b,
97 scalar_t x0, scalar_t y0, scalar_t x1, scalar_t y1) {
98 RGBImage::draw_line(int(thickness * scale),
100 x0 * scale + scale/2, y0 * scale + scale/2,
101 x1 * scale + scale/2, y1 * scale + scale/2);