1
0
Fork 0
mirror of synced 2024-06-23 08:41:01 +12:00

Add -white_noise option

post-processing for anime screencap.
This commit is contained in:
nagadomi 2015-11-11 08:00:50 +09:00
parent 0941d098e1
commit 4a4885c856
6 changed files with 62 additions and 1 deletions

View file

@ -52,6 +52,14 @@
<label><input type="radio" name="scale" value="1"> 1.6x</label>
<label><input type="radio" name="scale" value="2"> 2x</label>
</fieldset>
<fieldset>
<legend>Adding white noise</legend>
<label><input type="radio" name="white_noise" value="0" checked="checked">Off</label>
<label><input type="radio" name="white_noise" value="1">On</label>
<div class="help">
To denoise without unnaturalness in an anime screencap.
</div>
</fieldset>
<input type="submit"/>
</form>
<div class="help">

View file

@ -49,6 +49,14 @@
<label><input type="radio" name="scale" value="1"> 1.6x</label>
<label><input type="radio" name="scale" value="2"> 2x</label>
</fieldset>
<fieldset>
<legend>ホワイトノイズ付加</legend>
<label><input type="radio" name="white_noise" value="0" checked="checked">Off</label>
<label><input type="radio" name="white_noise" value="1">On</label>
<div class="help">
アニメのキャプチャ画像をノイズ除去したときの不自然さを低減します。
</div>
</fieldset>
<input type="submit" value="実行"/>
</form>
<div class="help">

View file

@ -51,6 +51,14 @@
<label><input type="radio" name="scale" value="1"> 1.6x</label>
<label><input type="radio" name="scale" value="2"> 2x</label>
</fieldset>
<fieldset>
<legend>Adding white noise</legend>
<label><input type="radio" name="white_noise" value="0" checked="checked">Off</label>
<label><input type="radio" name="white_noise" value="1">On</label>
<div class="help">
To denoise without unnaturalness in an anime screencap.
</div>
</fieldset>
<input type="submit"/>
</form>
<div class="help">

View file

@ -84,6 +84,30 @@ function iproc.padding(img, w1, w2, h1, h2)
flow[2]:add(-w1)
return image.warp(img, flow, "simple", false, "clamp")
end
function iproc.white_noise(src, std, rgb_weights, gamma)
gamma = gamma or 0.454545
local conversion
src, conversion = iproc.byte2float(src)
std = std or 0.01
local noise = torch.Tensor():resizeAs(src):normal(0, std)
if rgb_weights then
noise[1]:mul(rgb_weights[1])
noise[2]:mul(rgb_weights[2])
noise[3]:mul(rgb_weights[3])
end
local dest
if gamma ~= 0 then
dest = src:clone():pow(gamma):add(noise):pow(1.0 / gamma)
else
dest = src + noise
end
if conversion then
dest = iproc.float2byte(dest)
end
return dest
end
local function test_conversion()
local a = torch.linspace(0, 255, 256):float():div(255.0)

View file

@ -58,6 +58,9 @@ local function convert_image(opt)
else
error("undefined method:" .. opt.method)
end
if opt.white_noise == 1 then
new_x = iproc.white_noise(new_x, opt.white_noise_std, {1.0, 0.8, 1.0})
end
image_loader.save_png(opt.o, new_x, alpha, opt.depth)
print(opt.o .. ": " .. (sys.clock() - t) .. " sec")
end
@ -138,6 +141,10 @@ local function convert_frames(opt)
else
error("undefined method:" .. opt.method)
end
if opt.white_noise == 1 then
new_x = iproc.white_noise(new_x, opt.white_noise_std, {1.0, 0.8, 1.0})
end
local output = nil
if opt.o == "(auto)" then
local name = path.basename(lines[i])
@ -175,6 +182,8 @@ local function waifu2x()
cmd:option("-resume", 0, "skip existing files (0|1)")
cmd:option("-thread", -1, "number of CPU threads")
cmd:option("-tta", 0, '8x slower and slightly high quality (0|1)')
cmd:option("-white_noise", 0, 'adding white noise to output image (0|1)')
cmd:option("-white_noise_std", 0.0055, 'standard division of white noise')
local opt = cmd:parse(arg)
if opt.thread > 0 then

View file

@ -142,6 +142,7 @@ function APIHandler:post()
local x, alpha, blob = get_image(self)
local scale = tonumber(self:get_argument("scale", "0"))
local noise = tonumber(self:get_argument("noise", "0"))
local white_noise = tonumber(self:get_argument("white_noise", "0"))
local style = self:get_argument("style", "art")
if style ~= "art" then
style = "photo" -- style must be art or photo
@ -169,6 +170,9 @@ function APIHandler:post()
"Jinc")
end
end
if white_noise == 1 then
x = iproc.white_noise(x, 0.005, {1.0, 0.8, 1.0})
end
end
local name = uuid() .. ".png"
local blob, len = image_loader.encode_png(x, alpha)
@ -179,7 +183,7 @@ function APIHandler:post()
else
if not x then
self:set_status(400)
self:write("ERROR: unsupported image format.")
self:write("ERROR: An error occurred. (unsupported image format/connection timeout/file is too large)")
else
self:set_status(400)
self:write("ERROR: image size exceeds maximum allowable size.")