diff options
-rw-r--r-- | doc/simpletransform.md | 13 | ||||
-rw-r--r-- | image-1.1.alpha-0.rockspec | 3 | ||||
-rw-r--r-- | init.lua | 61 |
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 = { @@ -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 |