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 21:39:08 +0300
committerRonan Collobert <ronan@collobert.com>2015-10-15 21:41:52 +0300
commit9ed98d5bf57ccb6a246215e3f1e4ad85d9df7284 (patch)
treee8f88162af712021f9d89757b1c9916342fe8f4a /init.lua
parent37772b2174da15bed036ab5f69514872e22de788 (diff)
image.scale: remove rational dependency and support "*SC" and "*SCn/SCd"scalefactor
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua61
1 files changed, 41 insertions, 20 deletions
diff --git a/init.lua b/init.lua
index 0fc95ab..5a32f9c 100644
--- a/init.lua
+++ b/init.lua
@@ -35,8 +35,6 @@ require 'xlua'
require 'dok'
require 'libimage'
-local rational = require 'rational'
-
----------------------------------------------------------------------
-- types lookups
--
@@ -503,7 +501,7 @@ local function scale(...)
{type='string', help='mode: bilinear | bicubic |simple', default='bilinear'},
'',
{type='torch.Tensor', help='input image', req=true},
- {type='string | number', help='destination size: "WxH" or "MAX" or "^MIN" or MAX', req=true},
+ {type='string | number', help='destination size: "WxH" or "MAX" or "^MIN" or "*SC" or "*SCd/SCn" or MAX', req=true},
{type='string', help='mode: bilinear | bicubic | simple', default='bilinear'},
'',
{type='torch.Tensor', help='destination image', req=true},
@@ -512,28 +510,51 @@ local function scale(...)
dok.error('incorrect arguments', 'image.scale')
end
if size then
- local iwidth,iheight
+ local iwidth, iheight
if src:nDimension() == 3 then
- iwidth,iheight = src:size(3),src:size(2)
+ iwidth, iheight = src:size(3),src:size(2)
else
- iwidth,iheight = src:size(2),src:size(1)
+ iwidth, iheight = src:size(2),src:size(1)
end
- local imax = math.max(iwidth,iheight)
+
+ -- MAX?
+ local imax = math.max(iwidth, iheight)
local omax = tonumber(size)
if omax then
- 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 = tonumber(size:gfind('%^(%d*)')())
- if omin then
- local sc = rational(omin, imin)
- height = (rational(iheight)*sc)()
- width = (rational(iwidth)*sc)()
- end
+ height = iheight*omax/imax
+ width = iwidth*omax/imax
+ end
+
+ -- WxH?
+ if not width or not height then
+ width, height = size:match('(%d+)x(%d+)')
+ end
+
+ -- ^MIN?
+ if not width or not height then
+ local imin = math.min(iwidth, iheight)
+ local omin = tonumber(size:match('%^(%d+)'))
+ if omin then
+ height = iheight*omin/imin
+ width = iwidth*omin/imin
+ end
+ end
+
+ -- *SCn/SCd?
+ if not width or not height then
+ local scn, scd = size:match('%*(%d+)%/(%d+)')
+ if scn and scd then
+ height = iheight*scn/scd
+ width = iwidth*scn/scd
+ end
+ end
+
+ -- *SC?
+ if not width or not height then
+ local sc = tonumber(size:match('%*(.+)'))
+ if sc then
+ height = iheight*sc
+ width = iwidth*sc
end
end
end