diff options
author | Ronan Collobert <ronan@collobert.com> | 2015-10-15 00:38:38 +0300 |
---|---|---|
committer | Ronan Collobert <ronan@collobert.com> | 2015-10-15 00:38:38 +0300 |
commit | d53ac745e159424b432c97f06c9b2dda644f7fd9 (patch) | |
tree | 5efcf09f81982229294f738ee82a1bc14d9f4e24 | |
parent | 975f497f8199a6ad50877cec15fb855fec96778d (diff) |
fix corner-case issues when rescalingrescaling
-rw-r--r-- | image-1.1.alpha-0.rockspec | 3 | ||||
-rw-r--r-- | init.lua | 14 |
2 files changed, 11 insertions, 6 deletions
diff --git a/image-1.1.alpha-0.rockspec b/image-1.1.alpha-0.rockspec index 2c498db..d0f3e5f 100644 --- a/image-1.1.alpha-0.rockspec +++ b/image-1.1.alpha-0.rockspec @@ -19,7 +19,8 @@ using Torch's Tensor data structure. dependencies = { "torch >= 7.0", "sys >= 1.0", - "xlua >= 1.0" + "xlua >= 1.0", + "rational >= 1.0" } build = { @@ -35,6 +35,8 @@ require 'xlua' require 'dok' require 'libimage' +local rational = require 'rational' + ---------------------------------------------------------------------- -- types lookups -- @@ -519,16 +521,18 @@ local function scale(...) local imax = math.max(iwidth,iheight) local omax = tonumber(size) if omax then - height = iheight / imax * omax - width = iwidth / imax * omax + local sc = rational(omax, imax) + height = (rational(iheight)*sc)() + width = (rational(iwidth)*sc)() else width,height = size:gfind('(%d*)x(%d*)')() if not width or not height then local imin = math.min(iwidth,iheight) - local omin = size:gfind('%^(%d*)')() + local omin = tonumber(size:gfind('%^(%d*)')()) if omin then - height = iheight / imin * omin - width = iwidth / imin * omin + local sc = rational(omin, imin) + height = (rational(iheight)*sc)() + width = (rational(iwidth)*sc)() end end end |