automatic commit
[mlp.git] / images.h
1 /*
2  *  mlp-mnist is an implementation of a multi-layer neural network.
3  *
4  *  Copyright (c) 2006 École Polytechnique Fédérale de Lausanne,
5  *  http://www.epfl.ch
6  *
7  *  Written by Francois Fleuret <francois@fleuret.org>
8  *
9  *  This file is part of mlp-mnist.
10  *
11  *  mlp-mnist 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.
14  *
15  *  mlp-mnist 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.
19  *
20  *  You should have received a copy of the GNU General Public License
21  *  along with mlp-mnist.  If not, see <http://www.gnu.org/licenses/>.
22  *
23  */
24
25 // $Id: images.h,v 1.1 2005-12-13 17:19:11 fleuret Exp $
26
27 #ifndef IMAGES_H
28 #define IMAGES_H
29
30 #include <iostream>
31 #include <fstream>
32 #include <stdint.h>
33
34 using namespace std;
35
36 #include "features.h"
37
38 class PixelMaps {
39 public:
40   unsigned int _nb_ref;
41   unsigned char *_core;
42   PixelMaps(int size);
43   ~PixelMaps();
44   PixelMaps *add_ref();
45   void del_ref();
46 };
47
48 class ImageSet {
49   int _nb_pics, _nb_obj;
50   int _width, _height;
51   PixelMaps *_pixel_maps;
52   unsigned char **_pixels, *_labels;
53   bool *_used_picture;
54
55 public:
56   ImageSet();
57   ~ImageSet();
58
59   inline int nb_pics() { return _nb_pics; }
60   inline int nb_obj() { return _nb_obj; }
61   inline int width() { return _width; }
62   inline int height() { return _height; }
63   inline unsigned char *pixels(int p) { return _pixels[p]; }
64   inline unsigned char pixel(int p, int x, int y) { return _pixels[p][x + y * _width]; }
65   inline unsigned char label(int p) { return _labels[p]; }
66
67   void reset_used_pictures();
68   int nb_unused_pictures();
69   int pick_unused_picture();
70
71   void load_mnist_format(char *picture_file_name, char *label_file_name);
72
73   void sample_among_unused_pictures(ImageSet &is, int nb);
74
75 };
76
77 #endif