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 version 3 as
13 * published by the Free Software Foundation.
15 * folded-ctf 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 folded-ctf. If not, see <http://www.gnu.org/licenses/>.
25 #include "rgb_image_subpixel.h"
27 RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * scale, height* scale) { }
29 RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * scale, image->height() * scale) {
30 for(int y = 0; y < _height; y++) {
31 for(int x = 0; x < _width; x++) {
33 image->pixel(x / scale, y / scale, RGBImage::RED),
34 image->pixel(x / scale, y / scale, RGBImage::GREEN),
35 image->pixel(x / scale, y / scale, RGBImage::BLUE));
40 RGBImageSubpixel::~RGBImageSubpixel() { }
42 void RGBImageSubpixel::read_png(const char *filename) {
46 void RGBImageSubpixel::write_png(const char *filename) {
47 RGBImage tmp(_width / scale, _height / scale);
48 for(int y = 0; y < _height / scale; y++) {
49 for(int x = 0; x < _width / scale; x++) {
50 int sr = 0, sg = 0, sb = 0;
51 for(int yy = y * scale; yy < (y + 1) * scale; yy++) {
52 for(int xx = x * scale; xx < (x + 1) * scale; xx++) {
53 sr += int(_bit_plans[RED][yy][xx]);
54 sg += int(_bit_plans[GREEN][yy][xx]);
55 sb += int(_bit_plans[BLUE][yy][xx]);
60 sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
63 tmp.write_png(filename);
67 void RGBImageSubpixel::read_jpg(const char *filename) {
71 void RGBImageSubpixel::write_jpg(const char *filename, int quality) {
72 RGBImage tmp(_width / scale, _height / scale);
74 for(int y = 0; y < _height / scale; y++) {
75 for(int x = 0; x < _width / scale; x++) {
76 int sr = 0, sg = 0, sb = 0;
77 for(int yy = y * scale; yy < (y + 1) * scale; yy++) {
78 for(int xx = x * scale; xx < (x + 1) * scale; xx++) {
79 sr += int(_bit_plans[RED][yy][xx]);
80 sg += int(_bit_plans[GREEN][yy][xx]);
81 sb += int(_bit_plans[BLUE][yy][xx]);
86 sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
90 tmp.write_jpg(filename, quality);
94 void RGBImageSubpixel::draw_line(int thickness,
95 unsigned char r, unsigned char g, unsigned char b,
96 scalar_t x0, scalar_t y0, scalar_t x1, scalar_t y1) {
97 RGBImage::draw_line(int(thickness * scale),
99 x0 * scale + scale/2, y0 * scale + scale/2,
100 x1 * scale + scale/2, y1 * scale + scale/2);