Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th October 2014, 08:23   #1  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
New approach to fine detail sharpening without edge halos. Very fast, HD also.

Hi,

this message has been edited to point your attention to ready to go solution of how you can

1. fine-sharpen your Full-HD material
2. without edge halos or pushed up contrast of mid-detail
3. with optional and highly effective temporal degraining and denoising

Look at post #62 of page 4 in this thread.

---- Old discussion
I have had so much benefit from this forum in search of "my" sharpening solution. It seems Ive got it now and would like to share it with you.

The Full-HD videos of my Nikon D5300 Camera are best with defensive internal sharpening and sharpening in post. Due to agressive noise-reduction out-of camera fine detail is somewhat underdeveloped. So a detail-sharpener is needed which emphasizes fine contrast without pushing overall contrast of mid-detail and without ugly edge haloing. After WEEKS of research I came back to this 10-year old avisynth code:

http://forum.doom9.org/archive/index.php/t-76257.htm.

This is a fast and simple yet very effective unsharp mask with edge limiting. Thanks to who ever wrote this!

If you set strength (s) to 40 and small edge mask width (w) to 1-5, you will get a fine detail emphasizing effect without new edge halos. There are only two remaining issues: Deliberatly soft structures like clouds tend to form colour blocks and may get sharp edges where there are none. Second, already EXISTING edge halos (due to in-camera presharping) will get emphasized too. So I added/changed the following:

I replaced the old simple blur(1.58) with the more developed binominalBlur() from the variableblur package and the cloud-issue was almost gone (GaussianBlur did not show better results but only slowed down performance heavily). Second I applied DeHalo_alpha() to reduce remaining edge halos.

This is now my favourite sharpening solution among those I tried out. Consider that you have to balance detail sharpening and noise enhancement using the "s" and "w" parameters.

Feel free to try out this code with your high-definition footage. Your comments and suggestions are most welcome.

#################
# Sharpening (unsharp masking) of fine details avoiding edge halos or harsh contrast (by Hotte).
#
# Make sure you installed external filters "variableblur" and "DeHalo_alpha" with dependant filters
# Load source and convert. Binominal blur needs YV12.

x=avisource("blabla.avi").convertToYV12

# Set unsharp-mask parameters.
# s=strength of sharpening, 1 to 40=subtle, 70=significant, 100=strong (few artefacts), 127=maximum (strong artefacts)
# w=width of mask, 1-5=very fine detail only (almost no halos), 12=overall (some stronger halos)

s=40
w=5

# perform unsharp masking (see link above): fine blur, subtract negative, subtract whole mask from original

i=x.binomialBlur(varY=0.5, varC=0, Y=3, U=2, V=2, useMMX=true)
j=subtract(i,x).levels(0+s,1,255-s,0,255)
w=w*(128/s)
k=j.levels(127-w,1,128+w,127-w,128+w)
subtract(x,k)

# A subtle dehalo of large sharpening edges. highsens limits edgemask to larger edges rather than fine ones.
# DeHaloAlpha reduces sharpening a tiny bit. Increase width of sharpening mask by 1 or 2 for compensation.
# If you like geometrical structures being less aliased turn ss to 1.5, but it will reduce speed to 40%.

DeHalo_alpha(highsens=100,ss=1.0)
#################

In my environment this code runs multithreaded without issues if you put the following statements on top. This way I am getting crazy 35fps and 'round 80% CPU usage on an elderly i7 Quadcore (supersampling switched off (ss=1.0)):

SetMemoryMax(1024)
SetMTMode (4,4) # announce multithreading Mode 4, use 4 cpu-cores

Last edited by Hotte; 18th November 2014 at 21:52.
Hotte is offline   Reply With Quote
Old 25th October 2014, 09:48   #2  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
Function SharpLimit16 (clip input, clip "sharp", float "str", bool "tv_range")
{
sharp = Default (sharp, UnDefined ())
str = Default (str, 1.00)
tv_range = Default (tv_range, True)

Sharpdif = Dither_sub16 (sharp, input, dif=True, y=3, u=3, v=3)
Dif = Dither_lut16 (Sharpdif, "x 256 / 128 - abs 4 / 1 4 / ^ 4 * "+String (str)+" * x 256 / 128 - x 256 / 128 - abs 1.001 + / * 128 + 256 *", y=3, u=3, v=3)

output = input.Dither_add16 (Dif, dif=True, y=3, u=3, v=3)

return output
}

pass ur source clip and regularly sharpened clip to the function above, the output clip would be free of artifacts
feisty2 is offline   Reply With Quote
Old 25th October 2014, 10:18   #3  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
Hi feisty2,

thanks. Is this suggestion intended to be a replacement for dehalo_alpha or another suggestion for sharpening ?

I was trying to replace dehalo_alpha but in my code like this:

....y=subtract(x,k)

#DeHalo_alpha(highsens=100,ss=1.0)
z=SharpLimit16(x,y)
return(z)

where x represents the original and y the sharpended clip. However it returns Undefined() to be an undefined function. I do not know how to manage this. Could you help ?

Hotte
Hotte is offline   Reply With Quote
Old 25th October 2014, 10:23   #4  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
it's a simple function, it does a nonlinear limit to ur sharpened clip so the artifacts will be gone
very easy to use
a=last
b=a.#any sharp filter#
a.sharplimit16 (b)
* both source clip and sharpened clip gotta be stacked 16 bpc format
feisty2 is offline   Reply With Quote
Old 25th October 2014, 14:49   #5  |  Link
creaothceann
Registered User
 
Join Date: Jul 2010
Location: Germany
Posts: 360
[code]
creaothceann is offline   Reply With Quote
Old 28th October 2014, 17:52   #6  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
Hi feisty2,

I was trying to use your function as a replacment for dehalo_alpha like this:

....
b=subtract(x,k) # final step of my sharpen code applied to input clip x
x.sharplimit16(b) # call your function to remove sharpening artefacts

This throws: there is no function named "UnDefined""

If ignore the "sharp = ...."-line in your code it throws: "there is no function named "Dither_sub16""

I could not find a plugin that contains "Dither_sub16".

What's wrong ? Thanks.
Hotte is offline   Reply With Quote
Old 29th October 2014, 00:54   #7  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,356
Quote:
Originally Posted by Hotte View Post
If ignore the "sharp = ...."-line in your code it throws: "there is no function named "Dither_sub16""

I could not find a plugin that contains "Dither_sub16".
Dither plugin. It needs its own wiki page at some point.
__________________
There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order. ~ Ed Howdershelt
foxyshadis is offline   Reply With Quote
Old 1st November 2014, 11:22   #8  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
Thanks foxyshadis for this hint. I managed to install dither, but it was difficult since there where two syntax errors in the linked version of dither.avsi which where very difficult to find. Very strange.

Anyway after all that I did not get any satisfying result from feisty2's receipe. Instead some heavy white snow-like artifacts where added to the video.

I would like to come back to my original script. Any feedback on sharpness out there ?

Still there are things to improve, e.g.

1. Any ideas how to control a bit the fine grainy flickering that could show up, when fine detail sharpening is pushed up to heavily (I do not mean classical sensor noise here)

2. Is there a basic approach e.g. with dither to reduce color banding. I find dither very, very promising, but is difficult to understand, maybe there is some out of the box recommendation to try out for 8-bit fHD input resolution ?

3. Any suggestions to improve edge halo suppression even more than with (my parameters of) dehalo_alpha ?
Hotte is offline   Reply With Quote
Old 1st November 2014, 12:05   #9  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
dats because ur doin it wrong
I'll show u a more detailed example of how to use it
Code:
a=last.Dither_convert_8_to_16 ()
b=last.binomialBlur(varY=0.5, varC=0, Y=3, U=2, V=2, useMMX=true).Dither_convert_8_to_16 ()
sharp=dither_add16 (a,dither_sub16 (a,b,dif=true),dif=true)
a.sharplimit16 (sharp)
ditherpost (mode=6)
edit: u need avs 2.6 or avs+ to use this function

Last edited by feisty2; 1st November 2014 at 12:13.
feisty2 is offline   Reply With Quote
Old 1st November 2014, 21:47   #10  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
Hi feisty2,

thank you. This time your code worked immediately. Indeed it does fine sharpening pretty much the way my code does, so I had a very close comparative look.

Sharpening results are almost exactly the same if I apply s=40 and w=1 to my code (my code finesharpens a tiny, tiny bit more). There is no visible difference in artefacts of whatever kind, even if you zoom in 300%. Your code also benefits a lot if I add dehalo_alpha (like in my code) to get rid of existing edge halos. Your code runs some 30% slower both solo or with setmtmode(4,4).

What do I learn ? Two methods - same result. It seems that weve reached the feasible limits in detail sharpening.

Being an obvious expert in handling the complex dither-tool, I would love if you could answer the following questions:

1. How can I influence the strength of sharpening with your code ?
2. There is a very, very tiny flair of color shifting e.g. with clouds to pink (looks a bit like chromatic abberation) which is typical for unsharp mask processes - in both approaches. Do you know how to limit this ?
2. I've got some temporal color-banding in blue skies. Is there something in dither I could do against ?
3. Is there something in dither to calm the grainy flickering (I do not mean sensor noise) that my arise with strong detail sharpening ?

Thanks!
Hotte is offline   Reply With Quote
Old 2nd November 2014, 01:34   #11  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
1 "str" controls the strength, or sometimes u can just repeat the code several times if you want extra strong sharpening
2 use an internal resizer or dither_resize16(nr) on chroma planes, adjust src_left and src_top parameters to shift the chroma a little bit left(or right), a little bit up (or down), till theres no visible chroma shift
2 as the dither document says, "gradfun3" can remove bandings
3 search "motion compensated sharp" on forum, temporal processing is mvtools job, not dithers, there re 2 ways to limit sharp result temporally, the motion block average method (mdegrain) and the domain limit method (mcompensate+mt_clamp)
feisty2 is offline   Reply With Quote
Old 2nd November 2014, 23:02   #12  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
Now it is getting really interesting. Modfying "str" scales detail sharpening indeed very effectively. Compared to my approach, dither performs somewhat better with very high values like 3 or 4 since it creates less artefacts. This is useful when temporal denoise gets in. It took me quite a while to understand the principles of motion-compensated MDegrain but thanks to example scripts in this forum I finally got there.

Also I experimented with GradFun3 to smoothen a bit the blockyness of colour which may arise whilst sharpening.

Bottom line is that improvements in both calming down the grain and colour blocks/bands are only subtle but maybe worth the price for the significant performance decrease.

I will soon be coming up with a full script

Thanks feisty2 for your hints! There is only one thing I was not able to manage: Chroma shifting. I simply was not able to shift the chroma plains. Could you give me an example ? (You really have to have to intensively study these matters to put things into something that works).
But I think chroma shifting is maybe not the right approach. The problem is, that after sharpening if you have a very close look a clear blue sky will have many blocks in it with a magenta tone and light clouds will have blocks with a light yellowish tone. You do not see it at frist glance, but you notice a very slight color change. When you zoom in heavily you see these blocks and bands that were not there before. It's not a big problem and the sharpness benefit counts much more, but I ask you, if there is something we could do against this effect ?
Hotte is offline   Reply With Quote
Old 3rd November 2014, 06:23   #13  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
EDIT:
just checked the code, it doesn't process chroma at all, so, little bit confused about the "color block" u were talkin about, cuz it sounds a lot like a hangover of shitty chroma got sharpened kinda stuff
post a picture maybe?

Last edited by feisty2; 3rd November 2014 at 06:33.
feisty2 is offline   Reply With Quote
Old 3rd November 2014, 13:43   #14  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
Thanks for looking into this. Yes, it's time for pictures now.
I prepared 4 samples, all a bit overdone with sharpening to demonstrate the effect.

No1: Camera .MOV dragged into EDIUS and exported as AVI with Canopus HQ 8-bit intermediate Codec with very high quality settings. AVI back to Edius and shoot.

No2: Like No1 but reimported AVI sharpened with EDIUS's internal sharpener (setting 33).

No3: AVI No1 brought into avisynth and processed with nothing but your dithercode, str=2.0. Detail sharpening appears somehow like EDIUS, but less halos - just nice (dehalo_alpha would make it even nicer).

No4: Same as No3 but with remarks showing the increase of artefacts compared to No2 or No1.

I know we already have a fine solution here, but maybe we can try to get rid of some residual artefacts.

Thanks!
Attached Images
    
Hotte is offline   Reply With Quote
Old 3rd November 2014, 16:14   #15  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
its better to use an online image host site than upload attaches, it would waste the already very limited resources of doom9 forum server and would have to wait for admins approval which is gonna take a long time
anyways, if ur curious if theres somethin even better
I got a "deconvolution" like "magic" sharpen function suite
everything is done under avisynth except the wiener filter part
but its extremely slow, so damn slow you cant even imagine, Id say, 0.001 fps at 720x480 would be the speed of a super nice computer running the script
so, not useful at all, but it produces nice result
a quick preview and comparison, click the thumb to view the full size image




Last edited by feisty2; 3rd November 2014 at 16:19.
feisty2 is offline   Reply With Quote
Old 3rd November 2014, 20:55   #16  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
the "dither" function I wrote above (actually modified from didees script, I didn't invent it) is a part of that veeeeeeeery slow sharpening, it's like a lite version of lsfmod
feisty2 is offline   Reply With Quote
Old 3rd November 2014, 22:52   #17  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
Can you see my pictures (the ruined castle wall) now ? I can.
Yeah the clip with the lady looks nice at first glance - although you would not see artifacts like I found at that size. And I like that face but not on my screen for 1 year to become sharper...

I found out, that these magenta artefacts are exactly the same with my code, because it seems that we have the same unsharp mask approach. Moreover, they where much stronger, before I replaced blur(1.58) with binominal blur.

Somewhere I read, that unsharp masking produces color shifting. But if I use unsharp masks in my photo-raw-editor there is never any chroma shifting...

Anyway some tweaking with dehalo_alpha, mdegrain, gradfun and well balanced sharpening parameters gives excellent results in pretty short time.

Maybe someone out there`s got an idea ?
Hotte is offline   Reply With Quote
Old 3rd November 2014, 23:16   #18  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,460
@Hotte - did you realize you uploaded lossy jpg's ?

Blocking & banding artifacts are in the source image fom the crappy compression from your camera (Those are mostly h264 compression artifacts, not JPEG artifacts). Any sharpening approach will tend to enhance them

Take your original MOV source and use histogram("luma") to visualize them. It's an enhanced luma view
poisondeathray is offline   Reply With Quote
Old 4th November 2014, 00:49   #19  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Los Angeles, California
Posts: 2,119
im on cell now, will check ur pics l8r
are u sure u were seeing my pics at full size which is 720*352
and dont look at her face, take a glance at hair
feisty2 is offline   Reply With Quote
Old 4th November 2014, 00:58   #20  |  Link
Hotte
Registered User
 
Join Date: Oct 2014
Posts: 112
@poisondeathray, yes I know its not free from artefacts - which cam isnt ? (btw jpg-picture compression did not add visible artefacts - it looks at home just like you see it on the web here)

Say you are right then I still do not understand what the trick is with the EDIUS sharpener: It boosts detail the way the unsharp mask does, but there are (almost) no magenta shifts. I cannot explain that from histogram-luma.

Im pretty sure it happens somewhere on the way we do the masking process with avisynth. Maybe it is not trivial.

If you have good quality footage and would like to give it a try, I would be very happy if you could give some feedback.
Hotte is offline   Reply With Quote
Reply

Tags
detail, fine, full-hd, sharpen, unsharp mask

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:38.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.