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:
authorRonan Collobert <ronan@collobert.com>2015-10-15 00:38:38 +0300
committerRonan Collobert <ronan@collobert.com>2015-10-15 00:38:38 +0300
commitd53ac745e159424b432c97f06c9b2dda644f7fd9 (patch)
tree5efcf09f81982229294f738ee82a1bc14d9f4e24
parent975f497f8199a6ad50877cec15fb855fec96778d (diff)
fix corner-case issues when rescalingrescaling
-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