22#ifndef EOS_IMAGE_RESIZE_HPP
23#define EOS_IMAGE_RESIZE_HPP
25#include "eos/core/Image.hpp"
51 using Eigen::Vector3i;
57 const float scaling_width =
static_cast<float>(width) / image.width();
58 const float scaling_height =
static_cast<float>(height) / image.height();
61 for (
int w = 0; w < width; ++w)
63 for (
int h = 0; h < height; ++h)
65 const float left = (
static_cast<float>(w)) / scaling_width;
66 const float right = (
static_cast<float>(w) + 1.0f) / scaling_width;
67 const float bottom = (
static_cast<float>(h)) / scaling_height;
68 const float top = (
static_cast<float>(h) + 1.0f) / scaling_height;
70 Vector3i color = Vector3i::Zero();
73 for (
int a = ceil(left); a <= floor(right); ++a)
75 for (
int b = ceil(bottom); b <= floor(top); ++b)
78 if (a < image.width() && b < image.height())
81 color += Vector3i(image(b, a)[0], image(b, a)[1], image(b, a)[2]);
86 color = color / num_texels;
90 const int source_x = round(
static_cast<float>(w) / scaling_width);
91 const int source_y = round(
static_cast<float>(h) / scaling_height);
93 if (source_y < image.height() && source_x < image.width())
95 color = Vector3i(image(source_y, source_x)[0], image(source_y, source_x)[1],
96 image(source_y, source_x)[2]);
100 resized_image(h, w) = {
static_cast<std::uint8_t
>(round(color[0])),
101 static_cast<std::uint8_t
>(round(color[1])),
102 static_cast<std::uint8_t
>(round(color[2]))};
106 return resized_image;
124 using Eigen::Vector4i;
130 const float scaling_width =
static_cast<float>(width) / image.width();
131 const float scaling_height =
static_cast<float>(height) / image.height();
134 for (
int w = 0; w < width; ++w)
136 for (
int h = 0; h < height; ++h)
138 const float left = (
static_cast<float>(w)) / scaling_width;
139 const float right = (
static_cast<float>(w) + 1.0f) / scaling_width;
140 const float bottom = (
static_cast<float>(h)) / scaling_height;
141 const float top = (
static_cast<float>(h) + 1.0f) / scaling_height;
143 Vector4i color = Vector4i::Zero();
146 for (
int a = ceil(left); a <= floor(right); ++a)
148 for (
int b = ceil(bottom); b <= floor(top); ++b)
151 if (a < image.width() && b < image.height())
154 color += Vector4i(image(b, a)[0], image(b, a)[1], image(b, a)[2], image(b, a)[3]);
159 color = color / num_texels;
163 const int source_x = round(
static_cast<float>(w) / scaling_width);
164 const int source_y = round(
static_cast<float>(h) / scaling_height);
166 if (source_y < image.height() && source_x < image.width())
168 color = Vector4i(image(source_y, source_x)[0], image(source_y, source_x)[1],
169 image(source_y, source_x)[2], image(source_y, source_x)[3]);
173 resized_image(h, w) = {
174 static_cast<std::uint8_t
>(round(color[0])),
static_cast<std::uint8_t
>(round(color[1])),
175 static_cast<std::uint8_t
>(round(color[2])),
static_cast<std::uint8_t
>(round(color[3]))};
179 return resized_image;
Class to represent images.
Definition: Image.hpp:44
Namespace containing all of eos's 3D model fitting functionality.