automatic commit
[mlp.git] / images.h
1 /*
2  *  mlp-mnist is an implementation of a multi-layer neural network.
3  *
4  *  Copyright (c) 2008 Idiap Research Institute, http://www.idiap.ch/
5  *  Written by Francois Fleuret <francois.fleuret@idiap.ch>
6  *
7  *  This file is part of mlp-mnist.
8  *
9  *  mlp-mnist is free software: you can redistribute it and/or modify
10  *  it under the terms of the GNU General Public License version 3 as
11  *  published by the Free Software Foundation.
12  *
13  *  mlp-mnist is distributed in the hope that it will be useful, but
14  *  WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  *  General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with mlp-mnist.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22
23 // $Id: images.h,v 1.1 2005-12-13 17:19:11 fleuret Exp $
24
25 #ifndef IMAGES_H
26 #define IMAGES_H
27
28 #include <iostream>
29 #include <fstream>
30 #include <stdint.h>
31
32 using namespace std;
33
34 #include "features.h"
35
36 class PixelMaps {
37 public:
38   unsigned int _nb_ref;
39   unsigned char *_core;
40   PixelMaps(int size);
41   ~PixelMaps();
42   PixelMaps *add_ref();
43   void del_ref();
44 };
45
46 class ImageSet {
47   int _nb_pics, _nb_obj;
48   int _width, _height;
49   PixelMaps *_pixel_maps;
50   unsigned char **_pixels, *_labels;
51   bool *_used_picture;
52
53 public:
54   ImageSet();
55   ~ImageSet();
56
57   inline int nb_pics() { return _nb_pics; }
58   inline int nb_obj() { return _nb_obj; }
59   inline int width() { return _width; }
60   inline int height() { return _height; }
61   inline unsigned char *pixels(int p) { return _pixels[p]; }
62   inline unsigned char pixel(int p, int x, int y) { return _pixels[p][x + y * _width]; }
63   inline unsigned char label(int p) { return _labels[p]; }
64
65   void reset_used_pictures();
66   int nb_unused_pictures();
67   int pick_unused_picture();
68
69   void load_mnist_format(char *picture_file_name, char *label_file_name);
70
71   void extract_unused_pictures(ImageSet &is, int nb);
72
73 };
74
75 #endif