1 #include "CalibratedPyramid.hh"
3 #include <Base/Math/Vector2.hh>
4 #include <Geometry/ProjectionParametersBase.hh>
5 #include <Base/Image/ImageIO.hh>
10 template <
class StorageType>
13 : PyramidImage_(), Data_(), PositionOffset_(0.)
17 for (
int i=0; i<size; i++){
24 template <
class StorageType>
27 : PyramidImage_(), Data_(PyramidImage_.Size())
33 template <
class StorageType>
36 : PyramidImage_(cp), Data_(cp.size()), PositionOffset_(cp.GetPositionOffset())
38 const unsigned size =
Size();
39 for (
unsigned i=0; i<size; i++){
46 template <
class StorageType>
53 template <
class StorageType>
56 const unsigned pyramid_size,
const double rescale_factor)
58 BIASASSERT(pyramid_size>0);
60 PyramidImage_.SetRescaleFactor(rescale_factor);
61 const unsigned ui_factor = (unsigned)rint(rescale_factor);
63 if ( (ui_factor==2 || ui_factor==4) &&
64 Equal((
double)ui_factor, rescale_factor) &&
false){
68 PositionOffset_ = ((double)(ui_factor)*0.5)-0.5;
69 PyramidImage_.clear();
70 PyramidImage_.Init(*(ci.
image), pyramid_size);
71 PyramidImage_.resize(pyramid_size);
72 cout <<
"CalibratedPyramid: using own downsampling\n";
73 *PyramidImage_[0] = *ci.
image;
74 for (
unsigned p=1; p<pyramid_size; p++){
75 Downsample_(PyramidImage_[p-1], PyramidImage_[p], ui_factor);
78 cout <<
"CalibratedPyramid: using downsampling from Resize class\n";
79 PyramidImage_.Init(*(ci.
image), pyramid_size);
80 PyramidImage_.Downsample();
81 PositionOffset_ = PyramidImage_.GetPositionOffset();
83 cout <<
" using position offset "<<PositionOffset_<<
" for coo transfer\n";
84 cout <<
" using rescale factor: "<<rescale_factor<<
" "
85 <<PyramidImage_.GetRescaleFactor()<<endl;
87 Data_.resize(pyramid_size);
93 Data_[0].image = PyramidImage_[0];
94 for (
unsigned i=1; i<pyramid_size; i++){
95 if (Data_[i-1].projection){
98 Data_[i].projection->Rescale(rescale_factor, PositionOffset_);
103 Data_[i].image = PyramidImage_[i];
108 template <
class StorageType>
115 template <
class StorageType>
120 const int size = cp.
Size();
123 for (
int i=0; i<size; i++){
124 if (cp[i].projection)
127 Data_[i].image = PyramidImage_[i];
135 template <
class StorageType>
140 if (index==0) { coo_index=coo0; return ; }
141 coo_index[0] = (coo0[0]-PositionOffset_) /
142 (PyramidImage_.GetFactors()[index]);
143 coo_index[1] = (coo0[1]-PositionOffset_) /
144 (PyramidImage_.GetFactors()[index]);
150 template <
class StorageType>
155 BIASASSERT((factor == 2) | (factor == 4));
160 bin.
Filter(*src, filtered);
161 BIASASSERT(filtered.
GetWidth() == src->GetWidth() &&
162 filtered.
GetHeight() == src->GetHeight() &&
164 const int ow = src->GetWidth(), oh = src->GetHeight();
165 const int cc = src->GetChannelCount();
166 const int nw = ow / factor, nh = oh / factor;
167 if ((
int)dst->GetWidth() != nw || (int)dst->GetHeight() != nh ||
168 (int)dst->GetChannelCount() != cc ) {
169 if (!dst->IsEmpty()){
172 dst->Init(nw, nh, cc);
174 if (!dst->GetColorModel() != src->GetColorModel()){
175 dst->SetColorModel(src->GetColorModel());
178 StorageType **dst_ida = dst->GetImageDataArray();
180 int x, y, c, xc, yb, xb, xbc;
182 # pragma omp parallel for private (x, y, c, xc, yb, xb, xbc)
184 for (y=0; y<nh; y++){
185 yb = y*factor + (int)PositionOffset_;
186 for (x=0; x<nw; x++){
187 xb = x * factor + (int)PositionOffset_;
190 for (c=0; c<cc; c++){
191 dst_ida[y][xc+c] = fil_ida[yb][xbc+c];
202 #define INST(type) template class BIASImage_EXPORT CalibratedPyramid<type>
207 #ifdef BUILD_IMAGE_INT
210 #ifdef BUILD_IMAGE_CHAR
213 #ifdef BUILD_IMAGE_SHORT
216 #ifdef BUILD_IMAGE_USHORT
217 INST(
unsigned short);
219 #ifdef BUILD_IMAGE_UINT
222 #ifdef BUILD_IMAGE_DOUBLE
This class takes care of consisiten re-sampling of images and associated ProjectionParameters.
unsigned Size() const
returns the number of images stored in the pyramid
CalibratedPyramid< StorageType > & operator=(const CalibratedPyramid< StorageType > &cp)
shallow copy operator, only copies the pointers
pointer with reference count and automatic deletion
virtual void resize(const unsigned size)
virtual parent class for API definition of all (future) filters
void CoordinateTransf(const Vector2< double > &coo0, const unsigned index, Vector2< double > &coo_index) const
unsigned int GetWidth() const
PyramidImage< StorageType > PyramidImage_
Internal data: Data_.size() must always be equal to PyramidImage_.GetPyramidSize() ...
std::vector< CalibratedImage< StorageType > > Data_
holds the projection parameters and ptrs to the associated images
void Clear()
clears the pyramid image and the internal vector, does not explicitly delet the pointers ...
unsigned int GetChannelCount() const
returns the number of Color channels, e.g.
unsigned int GetHeight() const
void SetBorderHandling(const int bh)
SharedPtr< Image< StorageType > > image
The image template class for specific storage types.
helper class holding image and associated calibration
virtual int Filter(const Image< InputStorageType > &src, Image< OutputStorageType > &dst)
sets kernel if params changed and calls convolution
bool Equal(const T left, const T right, const T eps)
comparison function for floating point values See http://www.boost.org/libs/test/doc/components/test_...
SharedPtr< ProjectionParametersBase > projection
void Downsample_(SharedPtr< const Image< StorageType > > src, SharedPtr< Image< StorageType > > dst, const unsigned factor) const
Downsampling for factor 2 or 4, using a binomial lowpass filter.
void Init(const CalibratedImage< StorageType > &image, const unsigned pyramid_size=2, const double rescale_factor=4.0)
initialization with original image, total number of images in the pyramid and a rescale factor...
binomial low pass filter class
void SetHalfWinSize(int hws)
const StorageType ** GetImageDataArray() const
overloaded GetImageDataArray() from ImageBase