1
0
Fork 0
mirror of synced 2024-06-13 08:24:30 +12:00

Use gamma 2.2 space when resizing

This commit is contained in:
nagadomi 2015-11-08 20:28:14 +09:00
parent 5ab2c605c8
commit 6e41796328
2 changed files with 18 additions and 4 deletions

View file

@ -57,6 +57,20 @@ function iproc.scale(src, width, height, filter)
im:size(math.ceil(width), math.ceil(height), filter)
return im:toTensor(t, "RGB", "DHW")
end
function iproc.scale_with_gamma22(src, width, height, filter)
local conversion
src, conversion = iproc.byte2float(src)
filter = filter or "Box"
local im = gm.Image(src, "RGB", "DHW")
im:gammaCorrection(1.0 / 2.2):
size(math.ceil(width), math.ceil(height), filter):
gammaCorrection(2.2)
local dest = im:toTensor("float", "RGB", "DHW")
if conversion then
dest = iproc.float2byte(dest)
end
return dest
end
function iproc.padding(img, w1, w2, h1, h2)
local dst_height = img:size(2) + h1 + h2
local dst_width = img:size(3) + w1 + w2

View file

@ -163,10 +163,10 @@ function APIHandler:post()
x = convert(x, {method = "scale", style = style, prefix = style .. "_scale_" .. hash})
end
if scale == 1 then
x = iproc.scale(x,
math.floor(x:size(3) * (1.6 / 2.0) + 0.5),
math.floor(x:size(2) * (1.6 / 2.0) + 0.5),
"Jinc")
x = iproc.scale_with_gamma22(x,
math.floor(x:size(3) * (1.6 / 2.0) + 0.5),
math.floor(x:size(2) * (1.6 / 2.0) + 0.5),
"Jinc")
end
end
end