SourceXtractorPlusPlus 1.0.3
SourceXtractor++, the next generation SExtractor
Loading...
Searching...
No Matches
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
29namespace SourceXtractor {
30
34template<typename T>
36public:
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 ImageTile::ImageType getType() const override {
49 return ImageTile::getTypeValue(T());
50 }
51
52protected:
54
56 int x, int y, int width, int height) const override {
57 // Get the chunks we are interested in, and its surrounding area so we can convolve
58 auto chunk_start_x = x - m_interpolation_gap;
59 auto chunk_end_x = x + width;
60 auto chunk_start_y = y - m_interpolation_gap;
61 auto chunk_end_y = y + height;
62
63 // Remember to clip to avoid accessing the image out of bounds!
64 auto chunk_pixel_x = std::max(chunk_start_x, 0);
65 auto chunk_pixel_y = std::max(chunk_start_y, 0);
66 auto chunk_w = std::min(chunk_end_x - chunk_pixel_x, image->getWidth() - chunk_pixel_x);
67 auto chunk_h = std::min(chunk_end_y - chunk_pixel_y, image->getHeight() - chunk_pixel_y);
68
69 // Get the chunks for the image and the variance
70 // We rely on the underlying chain to generate them efficiently (i.e. BufferedImage across tiles)
71 auto img_chunk = image->getChunk(chunk_pixel_x, chunk_pixel_y, chunk_w, chunk_h);
72 auto variance_chunk = m_variance_map->getChunk(chunk_pixel_x, chunk_pixel_y, chunk_w, chunk_h);
73
74 // Fill the tile interpolating from the chunks
75 int off_x = x - chunk_pixel_x;
76 int off_y = y - chunk_pixel_y;
77 auto& tile_data = *tile.getImage();
78 for (int iy = 0; iy < height; ++iy) {
79 for (int ix = 0; ix < width; ++ix) {
80 tile_data.at(ix, iy) = getInterpolatedValue(*img_chunk, *variance_chunk, ix + off_x, iy + off_y);
81 }
82 }
83 }
84
85private:
89
90 inline T getInterpolatedValue(const ImageChunk<T>& img, const ImageChunk<T>& var, int x, int y) const {
91 if (var.getValue(x, y) < m_variance_threshold)
92 return img.getValue(x, y);
93
94 for (int i = 1; i <= m_interpolation_gap; i++) {
95 if (x - i >= 0 && var.getValue(x - i, y) < m_variance_threshold) {
96 return img.getValue(x - i, y);
97 }
98 if (y - i >= 0 && var.getValue(x, y - i) < m_variance_threshold) {
99 return img.getValue(x, y - i);
100 }
101 }
102 return img.getValue(x, y);
103 }
104};
105
106} // end namespace SourceXtractor
107
108#endif
T getValue(int x, int y) const
Returns the value of the pixel with the coordinates (x,y).
Definition ImageChunk.h:58
const std::shared_ptr< VectorImage< T > > & getImage() const
Definition ImageTile.h:178
static ImageType getTypeValue(float)
Definition ImageTile.h:97
Interface representing an image.
Definition Image.h:44
T getInterpolatedValue(const ImageChunk< T > &img, const ImageChunk< T > &var, int x, int y) const
std::string getRepr() const override
Human readable representation of this source.
InterpolatedImageSource(std::shared_ptr< Image< T > > image, std::shared_ptr< WeightImage > variance_map, WeightImage::PixelType variance_threshold, int interpolation_gap)
std::shared_ptr< WeightImage > m_variance_map
void generateTile(const std::shared_ptr< Image< T > > &image, ImageTileWithType< T > &tile, int x, int y, int width, int height) const override
ImageTile::ImageType getType() const override
ProcessingImageSource(std::shared_ptr< Image< T > > image)
T max(T... args)
T min(T... args)