Fanrestore - Fan Restoration Forum

Full Version: Deblur (A Simple Sharpening Script)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
DEBLUR
Quick and dirty sharpening.
REQUIREMENTS
fft3dfilter
arearesize
-------------------------------

I wanted to write something that could "fix" blurry encodes. It works fairly well, as long as your source isn't fubar to begin with.

I just posted a few images that should show what can be done with the default settings followed by a bit of denoising (fft3dfilter(sigma=8) for these).

Anyways hope you enjoy the script!

----------------------------------

Code:
function deblur2(clip v,float "blend",bool "clean",int "bsize", bool "show")
{
blend=Default(blend,.75)
clean=default(clean,true)
show=default(show,false)
bsize=default(bsize,4)
osize=bsize/2
v=v.converttoyv12()
v
fft3dfilter(16,bw=bsize,bh=bsize,ow=osize,oh=osize)
Subtract(last,v)
Subtract(v,last)
a=last
a.arearesize(width(v)/2,height(v)/2)
fft3dfilter(16,bw=bsize,bh=bsize,ow=osize,oh=osize)
gaussresize(width(a),height(a),p=1)
Subtract(last,a)
Subtract(a,last)
b=last
b
fft3dfilter(16,bw=bsize,bh=bsize,ow=osize,oh=osize)
Subtract(last,b)
Subtract(b,last)
fft3dfilter(sharpen=4)
(clean==true) ? last.fft3dfilter(16,bw=32,bh=32,ow=16,oh=16) : last
merge(v,last,blend)
x=last
(show==true) ? StackHorizontal(v,x) : x
return last
}

And here are a few images. Left is original, center is blurred, right is the result at the default strength with a block size of 48 (deblur2(bsize=48)).

[Image: 0J8QYZe.png]
[Image: pilb4xO.png]
Wow! That's impressive. Those "post" pictures look like they came from a higher resolution source, instead of being "recovered" from the low-res source.

How well would this work with VHS captures?
(2018-04-11, 04:32 AM)jerryshadoe Wrote: [ -> ]Wow! That's impressive. Those "post" pictures look like they came from a higher resolution source, instead of being "recovered" from the low-res source.

I'm not impressed with myself here. What's happened is I've put the denoiser after that stackhorizontal. I'd like to remove the images, and I apologize for them. Sad
(2018-04-11, 10:56 AM)MWilson Wrote: [ -> ]I'm not impressed with myself here. What's happened is I've put the denoiser after that stackhorizontal. I'd like to remove the images, and I apologize for them. Sad

Just redo the comparisons, and replace the old ones with the new ones!
spoRv, I can't seem to edit the post.

Code:
function deblur1(clip v,float "blend",bool "clean", bool "show")
{
blend=Default(blend,.75)
clean=default(clean,true)
show=default(show,false)
v=v.converttoyv12()
v
fft3dfilter(16)
Subtract(last,v)
Subtract(v,last)
a=last
a.arearesize(width(v)/2,height(v)/2)
fft3dfilter(16)
gaussresize(width(a),height(a),p=1)
Subtract(last,a)
Subtract(a,last)
b=last
b
fft3dfilter(16)
Subtract(last,b)
Subtract(b,last)
fft3dfilter(sharpen=4)
(clean==true) ? last.fft3dfilter(48) : last
merge(v,last,blend)
x=last
(show==true) ? StackHorizontal(v,x) : x
return last
}


[Image: ei5Zl7Z.png]
[Image: jawTMR7.png]

These are actual comparisons. On the left is the untouched image, center has been blurred, right is the result of the above script called as deblur1(1) on the blurred (center) image.
That's strange... there should be an "Edit" button on bottom of the post...

Well, the deblur results are too... deblurred! Big Grin

May you post one setting (and related screenshots) where the deblurred version is as close as possible to the untouched version? Thanks!
(2018-04-11, 02:20 PM)spoRv Wrote: [ -> ]That's strange... there should be an "Edit" button on bottom of the post...

Well, the deblur results are too... deblurred! Big Grin

May you post one setting (and related screenshots) where the deblurred version is as close as possible to the untouched version? Thanks!

No problem! I ran these through a gaussianblur(3) call (center) and then ran this script as deblur1(.75) (so defaults).
The only change made to the script was reducing the amount of denoising on the clean line.


[Image: pilb4xO.png]
[Image: 0J8QYZe.png]

Code:
function deblur1(clip v,float "blend",bool "clean", bool "show")
{
blend=Default(blend,.75)
clean=default(clean,true)
show=default(show,false)
v=v.converttoyv12()
v
fft3dfilter(16)
Subtract(last,v)
Subtract(v,last)
a=last
a.arearesize(width(v)/2,height(v)/2)
fft3dfilter(16)
gaussresize(width(a),height(a),p=1)
Subtract(last,a)
Subtract(a,last)
b=last
b
fft3dfilter(16)
Subtract(last,b)
Subtract(b,last)
fft3dfilter(sharpen=4)
(clean==true) ? last.fft3dfilter(16,bw=32,bh=32,ow=16,oh=16) : last
merge(v,last,blend)
x=last
(show==true) ? StackHorizontal(v,x) : x
return last
}
Edit: here's a version where you can set the block size. I've set the default to 4 (the original was 48). Other than that it's exactly the same as above.
Code:
function deblur2(clip v,float "blend",bool "clean",int "bsize", bool "show")
{
blend=Default(blend,.75)
clean=default(clean,true)
show=default(show,false)
bsize=default(bsize,4)
osize=bsize/2
v=v.converttoyv12()
v
fft3dfilter(16,bw=bsize,bh=bsize,ow=osize,oh=osize)
Subtract(last,v)
Subtract(v,last)
a=last
a.arearesize(width(v)/2,height(v)/2)
fft3dfilter(16,bw=bsize,bh=bsize,ow=osize,oh=osize)
gaussresize(width(a),height(a),p=1)
Subtract(last,a)
Subtract(a,last)
b=last
b
fft3dfilter(16,bw=bsize,bh=bsize,ow=osize,oh=osize)
Subtract(last,b)
Subtract(b,last)
fft3dfilter(sharpen=4)
(clean==true) ? last.fft3dfilter(16,bw=32,bh=32,ow=16,oh=16) : last
merge(v,last,blend)
x=last
(show==true) ? StackHorizontal(v,x) : x
return last
}