-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImage.h
More file actions
137 lines (101 loc) · 3.72 KB
/
Image.h
File metadata and controls
137 lines (101 loc) · 3.72 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#ifndef ImageH
#define ImageH
#include "Bounds.h"
#include "TMV.h"
namespace pca {
template <typename T>
class Image
{
public:
Image() {};
// Read new image from file
Image(std::string fits_file, int hdu=1);
void load(std::string fits_file, int hdu=1);
Image(std::string fits_file, int hdu,
int x1, int x2, int y1, int y2);
Image(std::string fits_file, int hdu, const Bounds<T>& b);
// Create blank image
Image(int x_size, int y_size) :
_filename(""), _hdu(0),
_xmin(0),_xmax(x_size),_ymin(0),_ymax(y_size),
_source(new tmv::Matrix<T>(x_size,y_size)),
_m(new tmv::MatrixView<T>(_source->view()))
{ _source->setZero(); }
// New copy of image
Image(const Image& rhs) :
_filename(""), _hdu(0),
_xmin(rhs._xmin), _xmax(rhs._xmax), _ymin(rhs._ymin), _ymax(rhs._ymax),
_source(new tmv::Matrix<T>(*rhs._m)),
_m(new tmv::MatrixView<T>(_source->view())) {}
// subImage (with new storage)
Image(const Image& rhs, int x1, int x2, int y1, int y2) :
_filename(""), _hdu(0),
_xmin(x1), _xmax(x2), _ymin(y1), _ymax(y2),
_source(new tmv::Matrix<T>(rhs._m->subMatrix(x1,x2,y1,y2))),
_m(new tmv::MatrixView<T>(_source->view())) {}
Image(const Image& rhs, const Bounds<T>& b) :
_filename(""), _hdu(0),
_xmin(int(floor(b.getXMin()))), _xmax(int(ceil(b.getXMax()))),
_ymin(int(floor(b.getYMin()))), _ymax(int(ceil(b.getYMax()))),
_source(new tmv::Matrix<T>(rhs._m->subMatrix(_xmin,_xmax,_ymin,_ymax))),
_m(new tmv::MatrixView<T>(_source->view())) {}
~Image() {}
// Copy image
void operator=(const Image& rhs) { *_m = *rhs._m; }
// Copy rhs to a subimage of this
void copy(const Image& rhs, int x1, int x2, int y1, int y2)
{ _m->subMatrix(x1,x2,y1,y2) = *rhs._m; }
// Write back to existing file
void flush() const;
void flush(std::string fits_file, int hdu=1) const;
// Write to new file
void write(std::string fits_file) const;
tmv::ConstMatrixView<T> getM() const { return *_m; }
const tmv::MatrixView<T>& getM() { return *_m; }
int getXMin() const { return _xmin; }
int getXMax() const { return _xmax; }
int getYMin() const { return _ymin; }
int getYMax() const { return _ymax; }
int getMaxI() const { return _m->colsize()-1; }
int getMaxJ() const { return _m->rowsize()-1; }
// Access elements
T& operator()(int i,int j) { return (*_m)(i,j); }
T operator()(int i,int j) const { return (*_m)(i,j); }
// Add two images
void operator+=(const Image& rhs) { *_m += *rhs._m; }
// Erase all values
void clear() { _m->setZero(); }
bool isSquare() { return _m->colsize() == _m->rowsize(); }
Bounds<T> getBounds() const
{ return Bounds<T>(_xmin,_xmax,_ymin,_ymax); }
// subImage refers to the same storage as this.
Image subImage(int x1, int x2, int y1, int y2)
{
return Image(_m->subMatrix(x1,x2,y1,y2),x1,x2,y1,y2);
}
// Split into nx x ny subimages
std::vector<Image*> divide(int nx, int ny) const;
// Iterpolate between integral pixel values
T interpolate(double x, double y) const;
T quadInterpolate(double x, double y) const;
// Median value of all pixels
T median() const;
bool loaded() { return _loaded; };
private:
mutable std::string _filename;
mutable int _hdu;
int _xmin,_xmax,_ymin,_ymax;
std::auto_ptr<tmv::Matrix<T> > _source;
std::auto_ptr<tmv::MatrixView<T> > _m;
template <class M>
Image(const M& m, int x1, int x2, int y1, int y2) :
_xmin(x1), _xmax(x2), _ymin(y1), _ymax(y2),
_source(0), _m(new tmv::MatrixView<T>(m)) {}
void readFits();
void readFits(int x1, int x2, int y1, int y2);
bool _loaded;
};
extern template class Image<double>;
extern template class Image<float>;
#endif
}