Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/image.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoumith Chintala <soumith@gmail.com>2015-10-15 01:28:47 +0300
committerSoumith Chintala <soumith@gmail.com>2015-10-15 01:28:47 +0300
commit37772b2174da15bed036ab5f69514872e22de788 (patch)
treec45cf9c34af947fe166fd8f923b1dc4f6796d0c6
parenta69bf9b3b107a7a8e9a785d26d76184e4cfc1abe (diff)
parentd53ac745e159424b432c97f06c9b2dda644f7fd9 (diff)
Merge pull request #109 from torch/rescaling
fix corner-case issues when rescaling
-rw-r--r--image-1.1.alpha-0.rockspec3
-rw-r--r--init.lua14
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 = {
diff --git a/init.lua b/init.lua
index c076399..0fc95ab 100644
--- a/init.lua
+++ b/init.lua
@@ -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