Add resize_blur parameter
latest graphicsmagick is required
This commit is contained in:
parent
145b47dbf5
commit
7814691cbf
|
@ -48,7 +48,7 @@ function iproc.float2byte(src)
|
|||
end
|
||||
return dest, conversion
|
||||
end
|
||||
function iproc.scale(src, width, height, filter)
|
||||
function iproc.scale(src, width, height, filter, blur)
|
||||
local conversion, color
|
||||
src, conversion = iproc.byte2float(src)
|
||||
filter = filter or "Box"
|
||||
|
@ -58,20 +58,20 @@ function iproc.scale(src, width, height, filter)
|
|||
color = "I"
|
||||
end
|
||||
local im = gm.Image(src, color, "DHW")
|
||||
im:size(math.ceil(width), math.ceil(height), filter)
|
||||
im:size(math.ceil(width), math.ceil(height), filter, blur)
|
||||
local dest = im:toTensor("float", color, "DHW")
|
||||
if conversion then
|
||||
dest = iproc.float2byte(dest)
|
||||
end
|
||||
return dest
|
||||
end
|
||||
function iproc.scale_with_gamma22(src, width, height, filter)
|
||||
function iproc.scale_with_gamma22(src, width, height, filter, blur)
|
||||
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):
|
||||
size(math.ceil(width), math.ceil(height), filter, blur):
|
||||
gammaCorrection(2.2)
|
||||
local dest = im:toTensor("float", "RGB", "DHW"):clamp(0.0, 1.0)
|
||||
if conversion then
|
||||
|
|
|
@ -6,13 +6,14 @@ function pairwise_transform.scale(src, scale, size, offset, n, options)
|
|||
local filters = options.downsampling_filters
|
||||
local unstable_region_offset = 8
|
||||
local downsampling_filter = filters[torch.random(1, #filters)]
|
||||
local blur = torch.uniform(options.resize_blur_min, options.resize_blur_max)
|
||||
local y = pairwise_utils.preprocess(src, size, options)
|
||||
assert(y:size(2) % 4 == 0 and y:size(3) % 4 == 0)
|
||||
local down_scale = 1.0 / scale
|
||||
local x
|
||||
if options.gamma_correction then
|
||||
local small = iproc.scale_with_gamma22(y, y:size(3) * down_scale,
|
||||
y:size(2) * down_scale, downsampling_filter)
|
||||
y:size(2) * down_scale, downsampling_filter, blur)
|
||||
if options.x_upsampling then
|
||||
x = iproc.scale(small, y:size(3), y:size(2), options.upsampling_filter)
|
||||
else
|
||||
|
@ -20,7 +21,7 @@ function pairwise_transform.scale(src, scale, size, offset, n, options)
|
|||
end
|
||||
else
|
||||
local small = iproc.scale(y, y:size(3) * down_scale,
|
||||
y:size(2) * down_scale, downsampling_filter)
|
||||
y:size(2) * down_scale, downsampling_filter, blur)
|
||||
if options.x_upsampling then
|
||||
x = iproc.scale(small, y:size(3), y:size(2), options.upsampling_filter)
|
||||
else
|
||||
|
|
|
@ -54,6 +54,8 @@ cmd:option("-gamma_correction", 0, 'Resizing with colorspace correction(sRGB:gam
|
|||
cmd:option("-upsampling_filter", "Box", 'upsampling filter for 2x scale training (dev)')
|
||||
cmd:option("-max_training_image_size", -1, 'if training image is larger than N, image will be crop randomly when data converting')
|
||||
cmd:option("-use_transparent_png", 0, 'use transparent png (0|1)')
|
||||
cmd:option("-resize_blur_min", 0.85, 'min blur parameter for ResizeImage')
|
||||
cmd:option("-resize_blur_max", 1.05, 'max blur parameter for ResizeImage')
|
||||
|
||||
local function to_bool(settings, name)
|
||||
if settings[name] == 1 then
|
||||
|
|
|
@ -149,7 +149,9 @@ local function transformer(model, x, is_validation, n, offset)
|
|||
active_cropping_tries = active_cropping_tries,
|
||||
rgb = (settings.color == "rgb"),
|
||||
gamma_correction = settings.gamma_correction,
|
||||
x_upsampling = not reconstruct.has_resize(model)
|
||||
x_upsampling = not reconstruct.has_resize(model),
|
||||
resize_blur_min = settings.resize_blur_min,
|
||||
resize_blur_max = settings.resize_blur_max,
|
||||
})
|
||||
elseif settings.method == "noise" then
|
||||
return pairwise_transform.jpeg(x,
|
||||
|
|
Loading…
Reference in a new issue