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
parent37772b2174da15bed036ab5f69514872e22de788 (diff)
image.scale: remove rational dependency and support "*SC" and "*SCn/SCd"scalefactor
-rw-r--r--doc/simpletransform.md13
-rw-r--r--image-1.1.alpha-0.rockspec3
-rw-r--r--init.lua61
3 files changed, 49 insertions, 28 deletions
diff --git a/doc/simpletransform.md b/doc/simpletransform.md
index 5b713c7..8c0cfb0 100644
--- a/doc/simpletransform.md
+++ b/doc/simpletransform.md
@@ -25,12 +25,13 @@ type of interpolation to be used. Valid values include
or *simple* interpolation. Returns a new `res` Tensor.
### [res] image.scale(src, size, [mode]) ###
-Rescale the height and width of image `src`.
-Variable `size` is a number or a string specifying the
-size of the result image. When `size` is a number, it specifies the
-maximum height or width of the output. When it is a string like
-*WxH* or *MAX* or *^MIN*, it specifies the `height x width`, maximum, or minimum height or
-width of the output, respectively.
+Rescale the height and width of image `src`. Variable `size` is a number
+or a string specifying the size of the result image. When `size` is a
+number, it specifies the maximum height or width of the output. When it is
+a string like `WxH` or `MAX` or `^MIN`, `*SC` or `*SCn/SCd` it specifies
+the `height x width`, maximum height or width of the output, minimum height
+or width of the output, scaling factor (number), or fractional scaling
+factor (int/int), respectively.
### [res] image.scale(dst, src, [mode]) ###
Rescale the height and width of image `src` to fit the dimensions of
diff --git a/image-1.1.alpha-0.rockspec b/image-1.1.alpha-0.rockspec
index d0f3e5f..2c498db 100644
--- a/image-1.1.alpha-0.rockspec
+++ b/image-1.1.alpha-0.rockspec
@@ -19,8 +19,7 @@ using Torch's Tensor data structure.
dependencies = {
"torch >= 7.0",
"sys >= 1.0",
- "xlua >= 1.0",
- "rational >= 1.0"
+ "xlua >= 1.0"
}
build = {
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