-
Notifications
You must be signed in to change notification settings - Fork 11
/
image.h
71 lines (64 loc) · 2.51 KB
/
image.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* @file image.h
* @brief image class with shallow copy
* @author Pascal Monasse <[email protected]>
*
* Copyright (c) 2012-2014, Pascal Monasse
* All rights reserved.
*
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* You should have received a copy of the GNU General Pulic License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef IMAGE_H
#define IMAGE_H
#include <vector>
/// Float image class, with shallow copy for performance.
///
/// Copy constructor and operator= perform a shallow copy, so pixels are shared.
/// To perform a deep copy, use method clone().
/// There is a constructor taking array of pixels; no copy is done, make sure
/// the array exists during the lifetime of the image.
/// The channels of a color image are interlaced, meaning RGBRGB...
class Image {
int* count; ///< number of shallow copies
float* tab; ///< array of pixels
int w, h, c; ///< width, height, channels
void kill();
public:
Image();
Image(int width, int height, int channels=1);
Image(float* pix, int width, int height, int channels=1);
Image(const Image& I);
~Image() { kill(); }
Image& operator=(const Image& I);
Image clone() const;
int width() const { return w; }
int height() const { return h; }
int channels() const { return c; }
float operator()(int i,int j,int d=0) const { return tab[(j*w+i)*c+d]; }
float& operator()(int i,int j,int d=0) { return tab[(j*w+i)*c+d]; }
Image gray() const;
// Filters (implemented in filters.cpp)
Image gradX() const;
void fillMinX(float vMin);
void fillMaxX(float vMin);
Image median(int radius) const;
Image weightedMedian(const Image& guidance,
const Image& where, int vMin, int vMax,
int radius,
float sigmaSpace, float sigmaColor) const;
private:
void fillX(float vMin, const float& (*cmp)(const float&,const float&));
float dist2(int x1,int y1, int x2,int y2) const;
void weighted_histo(std::vector<float>& tab, int x, int y, int radius,
int vMin, const Image& guidance,
float sSpace, float sColor) const;
};
bool save_disparity(const char* file_name, const Image& disparity,
int dMin, int dMax);
#endif