Skip to content

Commit

Permalink
re-format code
Browse files Browse the repository at this point in the history
  • Loading branch information
Dobiasd committed Sep 20, 2023
1 parent 3c31ee9 commit 610d2f9
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions include/fdeep/tensor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,33 +1060,42 @@ inline tensor resize2d_bilinear(const tensor& in_vol, const shape2& target_size)
return out_vol;
}

//just a clamping function, since I don't know if project has one
inline std::size_t clamp(const std::size_t x, const std::size_t min, const std::size_t max) {
inline std::size_t clamp(const std::size_t x, const std::size_t min, const std::size_t max)
{
return fplus::min(fplus::max(x, min), max);
}
//cubic spline interpolation
inline float_type cerp(const float_type* p, const float_type t) {

// cubic spline interpolation
inline float_type cerp(const float_type* p, const float_type t)
{
return p[1] + 0.5f * t * (p[2] - p[0] + t * (2.0f * p[0] - 5.0f * p[1] + 4.0f * p[2] - p[3] + t * (3.0f * (p[1] - p[2]) + p[3] - p[0])));
}
//bicubic interpolation
inline float_type bicerp(const float_type* p, float_type x, float_type y) {

// bicubic interpolation
inline float_type bicerp(const float_type* p, float_type x, float_type y)
{
float_type tmp[4];
tmp[0] = cerp(p, x);
tmp[1] = cerp(p + 4, x);
tmp[2] = cerp(p + 8, x);
tmp[3] = cerp(p + 12, x);
return cerp(tmp, y);
}
inline float_type interpolate_2d_value_bicubicly(const tensor& t, float_type y, float_type x, std::size_t z) {
//Clamping to max size is done in the gathering step

inline float_type interpolate_2d_value_bicubicly(const tensor& t, float_type y, float_type x, std::size_t z)
{
// Clamping to max size is done in the gathering step
y = fplus::max(0, y);
x = fplus::max(0, x);
//Corner coordinates as integers

// Corner coordinates as integers
std::size_t y0 = static_cast<std::size_t>(y);
std::size_t x0 = static_cast<std::size_t>(x);
//Relative position for interpolation

// Relative position for interpolation
float_type vals[16];
//Gather values in area of 4x4 pixels, might want to switch the loop ordering, since idk what is the storage order

// Gather values in area of 4x4 pixels, might want to switch the loop ordering, since idk what is the storage order
for(std::size_t i = 0; i < 4; i++) {
std::size_t pos_y = clamp(y0 + i - 1, 0, t.height() - 1);
for(std::size_t j = 0; j < 4; j++) {
Expand All @@ -1100,7 +1109,7 @@ inline float_type interpolate_2d_value_bicubicly(const tensor& t, float_type y,
}

inline tensor resize2d_bicubic(const tensor& in_vol, const shape2& target_size) {
tensor out_vol(tensor_shape(target_size.height_, target_size.width_, in_vol.shape().depth_), 0);
tensor out_vol(tensor_shape(target_size.height_, target_size.width_, in_vol.shape().depth_), static_cast<float_type>(0));
const float_type scale_y = static_cast<float_type>(target_size.height_) / static_cast<float_type>(in_vol.shape().height_);
const float_type scale_x = static_cast<float_type>(target_size.width_) / static_cast<float_type>(in_vol.shape().width_);
for(std::size_t y = 0; y < out_vol.shape().height_; ++y) {
Expand Down

0 comments on commit 610d2f9

Please sign in to comment.