diff options
author | Soumith Chintala <soumith@gmail.com> | 2015-10-15 01:28:47 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2015-10-15 01:28:47 +0300 |
commit | 37772b2174da15bed036ab5f69514872e22de788 (patch) | |
tree | c45cf9c34af947fe166fd8f923b1dc4f6796d0c6 | |
parent | a69bf9b3b107a7a8e9a785d26d76184e4cfc1abe (diff) | |
parent | d53ac745e159424b432c97f06c9b2dda644f7fd9 (diff) |
Merge pull request #109 from torch/rescaling
fix corner-case issues when rescaling
-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 |