-
-///////////////////////////////////////////////////////////////////////////
-// 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 <http://www.gnu.org/licenses/>. //
-// //
-// Written by Francois Fleuret, (C) IDIAP //
-// Contact <francois.fleuret@idiap.ch> 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 <francois.fleuret@idiap.ch>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
#include <iostream>
#include <stdio.h>
deallocate();
}
-void RGBImage::write_ppm(const char *filename) {
- FILE *outfile;
-
- if ((outfile = fopen (filename, "wb")) == 0) {
- fprintf (stderr, "Can't open %s for reading\n", filename);
- exit(1);
- }
-
- fprintf(outfile, "P6\n%d %d\n255\n", _width, _height);
-
- char *raw = new char[_width * _height * 3];
-
- int k = 0;
- for(int y = 0; y < _height; y++) for(int x = 0; x < _width; x++) {
- raw[k++] = _bit_map[x + _width * (y + _height * RED)];
- raw[k++] = _bit_map[x + _width * (y + _height * GREEN)];
- raw[k++] = _bit_map[x + _width * (y + _height * BLUE)];
- }
-
- fwrite((void *) raw, sizeof(unsigned char), _width * _height * 3, outfile);
- fclose(outfile);
-
- delete[] raw;
-}
-
-void RGBImage::read_ppm(const char *filename) {
- const int buffer_size = 1024;
- FILE *infile;
- char buffer[buffer_size];
- int max;
-
- deallocate();
-
- if((infile = fopen (filename, "r")) == 0) {
- fprintf (stderr, "Can't open %s for reading\n", filename);
- exit(1);
- }
-
- fgets(buffer, buffer_size, infile);
-
- if(strncmp(buffer, "P6", 2) == 0) {
-
- do {
- fgets(buffer, buffer_size, infile);
- } while((buffer[0] < '0') || (buffer[0] > '9'));
- sscanf(buffer, "%d %d", &_width, &_height);
- fgets(buffer, buffer_size, infile);
- sscanf(buffer, "%d", &max);
-
- allocate();
-
- unsigned char *raw = new unsigned char[_width * _height * RGB_DEPTH];
- fread(raw, sizeof(unsigned char), _width * _height * RGB_DEPTH, infile);
-
- int k = 0;
- for(int y = 0; y < _height; y++) for(int x = 0; x < _width; x++) {
- _bit_plans[RED][y][x] = raw[k++];
- _bit_plans[GREEN][y][x] = raw[k++];
- _bit_plans[BLUE][y][x] = raw[k++];
- }
-
- delete[] raw;
-
- } else if(strncmp(buffer, "P5", 2) == 0) {
-
- do {
- fgets(buffer, buffer_size, infile);
- } while((buffer[0] < '0') || (buffer[0] > '9'));
- sscanf(buffer, "%d %d", &_width, &_height);
- fgets(buffer, buffer_size, infile);
- sscanf(buffer, "%d", &max);
-
- allocate();
-
- unsigned char *pixbuf = new unsigned char[_width * _height];
- fread(buffer, sizeof(unsigned char), _width * _height, infile);
-
- int k = 0, l = 0;
- for(int y = 0; y < _height; y++) for(int x = 0; x < _width; x++) {
- unsigned char c = pixbuf[k++];
- _bit_map[l++] = c;
- _bit_map[l++] = c;
- _bit_map[l++] = c;
- }
-
- delete[] pixbuf;
-
- } else {
- cerr << "Can not read ppm of type [" << buffer << "] from " << filename << ".\n";
- exit(1);
- }
-}
-
void RGBImage::read_png(const char *name) {
// This is the number of bytes the read_png routine will read to
// decide if the file is a PNG or not. According to the png