SourceXtractorPlusPlus  0.12
Please provide a description of the project.
InterpolatedImageSource.h
Go to the documentation of this file.
1 
17 /*
18  * InterpolatedImageSource.h
19  *
20  * Created on: Jun 21, 2019
21  * Author: Alejandro Alvarez Ayllon
22  */
23 
24 #ifndef SEFRAMEWORK_SEFRAMEWORK_IMAGE_INTERPOLATEDIMAGESOURCE_H_
25 #define SEFRAMEWORK_SEFRAMEWORK_IMAGE_INTERPOLATEDIMAGESOURCE_H_
26 
28 
29 namespace SourceXtractor {
30 
34 template<typename T>
36 public:
38  WeightImage::PixelType variance_threshold, int interpolation_gap)
39  : ProcessingImageSource<T>(image),
40  m_variance_map(variance_map), m_variance_threshold(variance_threshold),
41  m_interpolation_gap(interpolation_gap) {
42  }
43 
44  std::string getRepr() const override {
45  return "InterpolatedImageSource(" + getImageRepr() + "," + m_variance_map->getRepr() + ")";
46  }
47 
48 protected:
50 
52  int x, int y, int width, int height) const override {
53  // Get the chunks we are interested in, and its surrounding area so we can convolve
54  auto chunk_start_x = x - m_interpolation_gap;
55  auto chunk_end_x = x + width;
56  auto chunk_start_y = y - m_interpolation_gap;
57  auto chunk_end_y = y + height;
58 
59  // Remember to clip to avoid accessing the image out of bounds!
60  auto chunk_pixel_x = std::max(chunk_start_x, 0);
61  auto chunk_pixel_y = std::max(chunk_start_y, 0);
62  auto chunk_w = std::min(chunk_end_x - chunk_pixel_x, image->getWidth() - chunk_pixel_x);
63  auto chunk_h = std::min(chunk_end_y - chunk_pixel_y, image->getHeight() - chunk_pixel_y);
64 
65  // Get the chunks for the image and the variance
66  // We rely on the underlying chain to generate them efficiently (i.e. BufferedImage across tiles)
67  auto img_chunk = image->getChunk(chunk_pixel_x, chunk_pixel_y, chunk_w, chunk_h);
68  auto variance_chunk = m_variance_map->getChunk(chunk_pixel_x, chunk_pixel_y, chunk_w, chunk_h);
69 
70  // Fill the tile interpolating from the chunks
71  int off_x = x - chunk_pixel_x;
72  int off_y = y - chunk_pixel_y;
73  auto& tile_data = *tile.getImage();
74  for (int iy = 0; iy < height; ++iy) {
75  for (int ix = 0; ix < width; ++ix) {
76  tile_data.at(ix, iy) = getInterpolatedValue(*img_chunk, *variance_chunk, ix + off_x, iy + off_y);
77  }
78  }
79  }
80 
81 private:
85 
86  inline T getInterpolatedValue(const ImageChunk<T>& img, const ImageChunk<T>& var, int x, int y) const {
87  if (var.getValue(x, y) < m_variance_threshold)
88  return img.getValue(x, y);
89 
90  for (int i = 1; i <= m_interpolation_gap; i++) {
91  if (x - i >= 0 && var.getValue(x - i, y) < m_variance_threshold) {
92  return img.getValue(x - i, y);
93  }
94  if (y - i >= 0 && var.getValue(x, y - i) < m_variance_threshold) {
95  return img.getValue(x, y - i);
96  }
97  }
98  return img.getValue(x, y);
99  }
100 };
101 
102 } // end namespace SourceXtractor
103 
104 #endif
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
STL class.
T min(T... args)
InterpolatedImageSource(std::shared_ptr< Image< T >> image, std::shared_ptr< WeightImage > variance_map, WeightImage::PixelType variance_threshold, int interpolation_gap)
T max(T... args)
std::string getRepr() const override
Human readable representation of this source.
T getInterpolatedValue(const ImageChunk< T > &img, const ImageChunk< T > &var, int x, int y) const
void generateTile(const std::shared_ptr< Image< T >> &image, ImageTile< T > &tile, int x, int y, int width, int height) const override
Interface representing an image.
Definition: Image.h:43
T getValue(int x, int y) const final
Returns the value of the pixel with the coordinates (x,y)
Definition: ImageChunk.h:57
std::shared_ptr< WeightImage > m_variance_map
std::shared_ptr< VectorImage< T > > & getImage()
Definition: ImageTile.h:87