From d00f0a1ccd2a9b1c332bbf7754f291dd61dee14f Mon Sep 17 00:00:00 2001
From: Joseph Redmon <pjreddie@gmail.com>
Date: Tue, 21 Jul 2015 23:09:33 +0000
Subject: [PATCH] Changes to make routing work better
---
src/image.c | 45 +++++++++++++++++++++++++++++++++++++--------
1 files changed, 37 insertions(+), 8 deletions(-)
diff --git a/src/image.c b/src/image.c
index 046de0c..ae8ca0a 100644
--- a/src/image.c
+++ b/src/image.c
@@ -332,7 +332,7 @@
for(x = 0; x < im.w; ++x){
float rx = cos(rad)*(x-cx) - sin(rad)*(y-cy) + cx;
float ry = sin(rad)*(x-cx) + cos(rad)*(y-cy) + cy;
- float val = billinear_interpolate(im, rx, ry, c);
+ float val = bilinear_interpolate(im, rx, ry, c);
set_pixel(rot, x, y, c, val);
}
}
@@ -549,7 +549,7 @@
}
*/
-float billinear_interpolate(image im, float x, float y, int c)
+float bilinear_interpolate(image im, float x, float y, int c)
{
int ix = (int) floorf(x);
int iy = (int) floorf(y);
@@ -564,23 +564,47 @@
return val;
}
-// #wikipedia
image resize_image(image im, int w, int h)
{
image resized = make_image(w, h, im.c);
+ image part = make_image(w, im.h, im.c);
int r, c, k;
float w_scale = (float)(im.w - 1) / (w - 1);
float h_scale = (float)(im.h - 1) / (h - 1);
for(k = 0; k < im.c; ++k){
- for(r = 0; r < h; ++r){
+ for(r = 0; r < im.h; ++r){
for(c = 0; c < w; ++c){
- float sx = c*w_scale;
- float sy = r*h_scale;
- float val = billinear_interpolate(im, sx, sy, k);
- set_pixel(resized, c, r, k, val);
+ float val = 0;
+ if(c == w-1){
+ val = get_pixel(im, im.w-1, r, k);
+ } else {
+ float sx = c*w_scale;
+ int ix = (int) sx;
+ float dx = sx - ix;
+ val = (1 - dx) * get_pixel(im, ix, r, k) + dx * get_pixel(im, ix+1, r, k);
+ }
+ set_pixel(part, c, r, k, val);
}
}
}
+ for(k = 0; k < im.c; ++k){
+ for(r = 0; r < h; ++r){
+ float sy = r*h_scale;
+ int iy = (int) sy;
+ float dy = sy - iy;
+ for(c = 0; c < w; ++c){
+ float val = (1-dy) * get_pixel(part, c, iy, k);
+ set_pixel(resized, c, r, k, val);
+ }
+ if(r == h-1) continue;
+ for(c = 0; c < w; ++c){
+ float val = dy * get_pixel(part, c, iy+1, k);
+ add_pixel(resized, c, r, k, val);
+ }
+ }
+ }
+
+ free_image(part);
return resized;
}
@@ -728,6 +752,11 @@
assert(x < m.w && y < m.h && c < m.c);
m.data[c*m.h*m.w + y*m.w + x] = val;
}
+void add_pixel(image m, int x, int y, int c, float val)
+{
+ assert(x < m.w && y < m.h && c < m.c);
+ m.data[c*m.h*m.w + y*m.w + x] += val;
+}
void print_image(image m)
{
--
Gitblit v1.10.0