Hello guest, if you like this forum, why don't you register? https://forum.fanres.com/member.php?action=register (December 14, 2021) x


AviSynth 

Deblur (A Simple Sharpening Script)

6 Replies, 6171 Views

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]
(This post was last modified: 2018-04-11, 06:31 PM by MWilson.)
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
(This post was last modified: 2018-04-11, 10:58 AM by MWilson. Edit Reason: Can't edit first post )
(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!
Sadly my projects are lost due to an HDD crash... Sad
Fundamental Collection | Vimeo channel | My blog
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!
Sadly my projects are lost due to an HDD crash... Sad
Fundamental Collection | Vimeo channel | My blog
(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
}
(This post was last modified: 2018-04-11, 06:23 PM by MWilson. Edit Reason: Added an option to script )

Possibly Related Threads…
Thread Author Replies Views Last Post
  Script to make MKVs importable in Premiere TomArrow 1 635 2021-10-23, 07:36 PM
Last Post: alleycat
  Thumbnail script with scene detection TomArrow 1 1,847 2020-01-04, 04:40 PM
Last Post: TomArrow
  AviSynth Rigby Reardon's Mondo Sync Script for TGtBatU Chewtobacca 0 1,917 2016-11-13, 01:27 AM
Last Post: Chewtobacca
  Script snippets subforum Feallan 3 8,356 2016-11-13, 12:32 AM
Last Post: Feallan



Users browsing this thread: 1 Guest(s)