24 #ifndef _SEIMPLEMENTATION_IMAGE_WRITEABLEIMAGEINTERFACETRAITS_H_
25 #define _SEIMPLEMENTATION_IMAGE_WRITEABLEIMAGEINTERFACETRAITS_H_
30 namespace ModelFitting {
44 class WriteableIterator;
46 class WriteableSetter {
52 friend class WriteableIterator;
56 : m_image{image}, m_accessor{image}, m_x{
x}, m_y{
y} {}
59 m_image->setValue(m_x, m_y, v);
64 v += m_accessor.getValue(m_x, m_y);
65 m_image->setValue(m_x, m_y, v);
70 return m_accessor.getValue(m_x, m_y);
74 class WriteableIterator :
std::iterator<std::forward_iterator_tag, WriteableInterfaceType::PixelType> {
85 : m_image{image}, m_accessor{image}, m_x{0}, m_y{0},
86 m_width{image->getWidth()},
87 m_height{image->getHeight()},
88 m_setter{image, 0, 0} {
96 return m_x != b.m_x || m_y != b.m_y || m_width != b.m_width || m_height != b.m_height || m_image != b.m_image;
100 if (m_y < m_height) {
102 if (m_x >= m_width) {
105 if (m_y >= m_height) {
127 return image->getWidth();
131 return image->getHeight();
135 return WriteableSetter(image, x, y);
144 return WriteableIterator{image};
148 return WriteableIterator{image, 0};
152 double scale_factor,
double x,
double y);
161 double x_shift,
double y_shift) {
162 int window_width =
width(window);
163 int window_height =
height(window);
164 for (
int x_win = 0; x_win < window_width; x_win++) {
165 for (
int y_win = 0; y_win < window_height; y_win++) {
166 double x = (x_win - 0.5 - x_shift) / scale_factor;
167 double y = (y_win - 0.5 - y_shift) / scale_factor;
172 double x_delta = x - xi;
173 double y_delta = y - yi;
178 double v11 =
getClamped(source, xi + 1, yi + 1);
180 window->setValue(x_win, y_win, (1.0 - y_delta) * ((1.0 - x_delta) * v00 + x_delta * v10) +
181 y_delta * ((1.0 - x_delta) * v01 + x_delta * v11));
189 double x_shift,
double y_shift) {
191 int window_width =
width(window);
192 int window_height =
height(window);
193 for (
int x_win = 0; x_win < window_width; x_win++) {
194 for (
int y_win = 0; y_win < window_height; y_win++) {
195 float x = (x_win - x_shift) / scale_factor;
196 float y = (y_win - y_shift) / scale_factor;
205 int src_x = ix + i - INTERP_MAXKERNELWIDTH / 2;
206 int src_y = iy + j - INTERP_MAXKERNELWIDTH / 2;
208 if (source->isInside(src_x, src_y)) {
209 buffer[j * INTERP_MAXKERNELWIDTH + i] = accessor.
getValue(src_x, src_y);
214 window->setValue(x_win, y_win,
216 INTERP_MAXKERNELWIDTH / 2 + y - iy,
228 double scale_factor,
double x,
double y) {
230 double scaled_width =
width(image2) * scale_factor;
231 double scaled_height =
height(image2) * scale_factor;
233 int x_min =
std::floor(x - scaled_width / 2.);
234 int x_max =
std::ceil(x + scaled_width / 2.);
235 int window_width = x_max - x_min;
236 int y_min =
std::floor(y - scaled_height / 2.);
237 int y_max =
std::ceil(y + scaled_height / 2.);
238 int window_height = y_max - y_min;
240 double x_shift = x - scaled_width / 2. - x_min;
241 double y_shift = y - scaled_height / 2. - y_min;
243 auto window =
factory(window_width, window_height);
250 double corr_factor = 1. / (scale_factor * scale_factor);
252 for (
int x_im =
std::max(x_min, 0); x_im < std::min<int>(x_max,
width(image1)); ++x_im) {
253 for (
int y_im =
std::max(y_min, 0); y_im < std::min<int>(y_max,
height(image1)); ++y_im) {
254 int x_win = x_im - x_min;
255 int y_win = y_im - y_min;
256 at(image1, x_im, y_im) += corr_factor *
at(window, x_win, y_win);
static ImageType factory(std::size_t width, std::size_t height)
#define INTERP_MAXKERNELWIDTH
static std::size_t height(const WriteableInterfaceTypePtr &image)
WriteableIterator iterator
SourceXtractor::WriteableImage< SourceXtractor::SeFloat > WriteableInterfaceType
SourceXtractor::ImageAccessor< WriteableInterfaceType::PixelType > m_accessor
static std::size_t height(ImageType &image)
static WriteableInterfaceTypePtr factory(std::size_t width, std::size_t height)
static double & at(ImageType &image, std::size_t x, std::size_t y)
static void addImageToImage(ImageType &image1, const ImageType &image2, double scale, double x, double y)
WriteableInterfaceType::PixelType operator+=(WriteableInterfaceType::PixelType v)
static iterator end(const WriteableInterfaceTypePtr &image)
SourceXtractor::ImageAccessor< WriteableInterfaceType::PixelType > m_accessor
WriteableIterator(WriteableInterfaceTypePtr image, int)
WriteableSetter(WriteableInterfaceTypePtr &image, int x, int y)
WriteableSetter & operator*()
WriteableInterfaceType::PixelType operator=(WriteableInterfaceType::PixelType v)
static double getClamped(const WriteableInterfaceTypePtr &image, int x, int y)
WriteableInterfaceTypePtr m_image
static iterator begin(const WriteableInterfaceTypePtr &image)
WriteableIterator & operator++()
bool operator!=(const WriteableIterator &b) const
static WriteableSetter at(WriteableInterfaceTypePtr &image, std::size_t x, std::size_t y)
static std::size_t width(const WriteableInterfaceTypePtr &image)
static void shiftResize(const WriteableInterfaceTypePtr &source, WriteableInterfaceTypePtr &window, double scale_factor, double x_shift, double y_shift)
static void shiftResizeLancszos(const WriteableInterfaceTypePtr &source, WriteableInterfaceTypePtr &window, double scale_factor, double x_shift, double y_shift)
static ImageInterfaceType::PixelType at(const WriteableInterfaceTypePtr &image, std::size_t x, std::size_t y)
WriteableInterfaceTypePtr m_image
std::shared_ptr< WriteableInterfaceType > WriteableInterfaceTypePtr
static std::size_t width(ImageType &image)
WriteableIterator(WriteableInterfaceTypePtr image)