X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=rgb_image_subpixel.cc;h=4c3e16aeac8a67f2e9d4d616b8c81dd6709a5009;hb=e6dd9046eb73320d6374c92ca53b91f5e167360d;hp=3338f50c76ffe769f74babee33ed75c507380ab8;hpb=d922ad61d35e9a6996730bec24b16f8bf7bc426c;p=folded-ctf.git
diff --git a/rgb_image_subpixel.cc b/rgb_image_subpixel.cc
index 3338f50..4c3e16a 100644
--- a/rgb_image_subpixel.cc
+++ b/rgb_image_subpixel.cc
@@ -1,58 +1,55 @@
-
-///////////////////////////////////////////////////////////////////////////
-// This program is free software: you can redistribute it and/or modify //
-// it under the terms of the version 3 of the GNU General Public License //
-// as published by the Free Software Foundation. //
-// //
-// This program is distributed in the hope that it will be useful, but //
-// WITHOUT ANY WARRANTY; without even the implied warranty of //
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU //
-// General Public License for more details. //
-// //
-// You should have received a copy of the GNU General Public License //
-// along with this program. If not, see . //
-// //
-// Written by Francois Fleuret, (C) IDIAP //
-// Contact for comments & bug reports //
-///////////////////////////////////////////////////////////////////////////
+/*
+ * folded-ctf is an implementation of the folded hierarchy of
+ * classifiers for object detection, developed by Francois Fleuret
+ * and Donald Geman.
+ *
+ * Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
+ * Written by Francois Fleuret
+ *
+ * This file is part of folded-ctf.
+ *
+ * folded-ctf is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * folded-ctf is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with folded-ctf. If not, see .
+ *
+ */
#include "rgb_image_subpixel.h"
-RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * _scale, height* _scale) { }
+RGBImageSubpixel::RGBImageSubpixel(int width, int height) : RGBImage(width * scale, height* scale) { }
-RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * _scale, image->height() * _scale) {
+RGBImageSubpixel::RGBImageSubpixel(RGBImage *image) : RGBImage(image->width() * scale, image->height() * scale) {
for(int y = 0; y < _height; y++) {
for(int x = 0; x < _width; x++) {
set_pixel(x, y,
- image->pixel(x / _scale, y / _scale, RGBImage::RED),
- image->pixel(x / _scale, y / _scale, RGBImage::GREEN),
- image->pixel(x / _scale, y / _scale, RGBImage::BLUE));
+ image->pixel(x / scale, y / scale, RGBImage::RED),
+ image->pixel(x / scale, y / scale, RGBImage::GREEN),
+ image->pixel(x / scale, y / scale, RGBImage::BLUE));
}
}
}
RGBImageSubpixel::~RGBImageSubpixel() { }
-void RGBImageSubpixel::read_ppm(const char *filename) {
- abort();
-}
-
-void RGBImageSubpixel::write_ppm(const char *filename) {
- abort();
-}
-
-
void RGBImageSubpixel::read_png(const char *filename) {
abort();
}
void RGBImageSubpixel::write_png(const char *filename) {
- RGBImage tmp(_width / _scale, _height / _scale);
- for(int y = 0; y < _height / _scale; y++) {
- for(int x = 0; x < _width / _scale; x++) {
+ RGBImage tmp(_width / scale, _height / scale);
+ for(int y = 0; y < _height / scale; y++) {
+ for(int x = 0; x < _width / scale; x++) {
int sr = 0, sg = 0, sb = 0;
- for(int yy = y * _scale; yy < (y + 1) * _scale; yy++) {
- for(int xx = x * _scale; xx < (x + 1) * _scale; xx++) {
+ for(int yy = y * scale; yy < (y + 1) * scale; yy++) {
+ for(int xx = x * scale; xx < (x + 1) * scale; xx++) {
sr += int(_bit_plans[RED][yy][xx]);
sg += int(_bit_plans[GREEN][yy][xx]);
sb += int(_bit_plans[BLUE][yy][xx]);
@@ -60,7 +57,7 @@ void RGBImageSubpixel::write_png(const char *filename) {
}
tmp.set_pixel(x, y,
- sr / (_scale * _scale), sg / (_scale * _scale), sb / (_scale * _scale));
+ sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
}
}
tmp.write_png(filename);
@@ -72,15 +69,33 @@ void RGBImageSubpixel::read_jpg(const char *filename) {
}
void RGBImageSubpixel::write_jpg(const char *filename, int quality) {
- abort();
+ RGBImage tmp(_width / scale, _height / scale);
+
+ for(int y = 0; y < _height / scale; y++) {
+ for(int x = 0; x < _width / scale; x++) {
+ int sr = 0, sg = 0, sb = 0;
+ for(int yy = y * scale; yy < (y + 1) * scale; yy++) {
+ for(int xx = x * scale; xx < (x + 1) * scale; xx++) {
+ sr += int(_bit_plans[RED][yy][xx]);
+ sg += int(_bit_plans[GREEN][yy][xx]);
+ sb += int(_bit_plans[BLUE][yy][xx]);
+ }
+ }
+
+ tmp.set_pixel(x, y,
+ sr / (scale * scale), sg / (scale * scale), sb / (scale * scale));
+ }
+ }
+
+ tmp.write_jpg(filename, quality);
}
void RGBImageSubpixel::draw_line(int thickness,
unsigned char r, unsigned char g, unsigned char b,
scalar_t x0, scalar_t y0, scalar_t x1, scalar_t y1) {
- RGBImage::draw_line(int(thickness * _scale),
+ RGBImage::draw_line(int(thickness * scale),
r, g, b,
- x0 * _scale + _scale/2, y0 * _scale + _scale/2,
- x1 * _scale + _scale/2, y1 * _scale + _scale/2);
+ x0 * scale + scale/2, y0 * scale + scale/2,
+ x1 * scale + scale/2, y1 * scale + scale/2);
}