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 21st July 2011, 13:44   #1  |  Link
Yellow_
Registered User
 
Join Date: Sep 2009
Posts: 378
Local Contrast Enhancement

Could some one point me in the direction of AVISynth plugins that enable fine control of local contrast enhancement, not necessarily the USM approach for sharpening more the control over local areas / bands of shadow & highlight detail to improve visual appearance in those areas.
Yellow_ is offline   Reply With Quote
Old 21st July 2011, 19:16   #2  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
Version 1.1 of both my LCE as well as my Contrast Mask functions:

Hope you enjoy. LCE should be able to produce similar effects as any unsharp mask, with the difference that it offers different variables to experiment with than radius, amount and threshold. So if the user requires it, it can be less subtle.

# Local Contrast Enhancement:
# a) Blur the original and Create a Local Contrast Mask
# b) Create a higher contrast image out of the original
# c) Mask overlay the higher contrast image to the original, using the Local Contrast Mask.

Example: http://www.cambridgeincolour.com/tut...nhancement.htm

# Photoshop Overlay: "Multiplies or screens the colors, depending on the base color. Patterns or colors overlay the existing pixels while preserving the highlights and shadows of the base color. The base color is not replaced but is mixed with the blend color to reflect the lightness or darkness of the original color."

gblur (exists in LCE and ContrastMask both): the amount of gaussian blur to apply
contrast (LCE only): the amount of contrast to apply
brightness (LCE/mode 0 only): Controls the local brightness effect, valid values from 0.0 to 255.
mode (LCE only): Mode 1 is my attempt at the classic local contrast enhancement technique as it can be implemented by someone using photoshop. Mode 0 can give a similar effect, but the user is free to temper with contrast as well as brightness, not only contrast.
correction (LCE only): Whether to perform a histogram auto-correction. This can improve the LCE even further.
enhance (ContrastMask only): It controls the opacity of the final product. Valid values are from 0.0 to 10.0, where 10.0 is the 100% of the contrast mask.

# *Multiply: (x*y)/255 for PC, (((x-16)*(y-16))/219)+16 for TV
# *Screen: 255-[((255-x)*(255-y))/255] for PC, (219-(((219-(x-16))*(219-(y-16)))/219))+16 for TV
# *Photoshop overlay: If Lower Layer Value > 127.5, Overlay = (Upper Layer Value * Value Unit) + Min Value, where
# Value Unit = (255-Lower Layer Value)/127.5 and Min Value = Lower Layer Value - (255-Lower Layer Value)
# If Lower Layer Value < 127.5, Overlay = Upper Layer Value * Value Unit, where
# Value Unit=Lower Layer Value/127.5

Code:
function LCE(clip v, float "gblur", float "contrast", float "brightness", int "mode", bool "correction")
{
# Local Contrast Enhancement:
# a) Blur the original and Create a Local Contrast Mask
# b) Create a higher contrast image out of the original
# c) Mask overlay the higher contrast image to the original, using the Local Contrast Mask.
brightness = default (brightness, 80)
correction = default (correction, false)
gblur = default (gblur,0.1)
mode = default (mode, 1)
contrast = (mode==1) ? default (contrast, 1.5) : default (contrast, 1.1)
v = (correction==true) ? v.autolevels() : v
brightness = (brightness<=255.0 && brightness>=0.0) ? float(-brightness) : -80
v2=v.Tweak(sat=0)
v2=v2.gaussianblur(gblur)
v2=v2.mt_edge(mode="min/max",thY1=0,thY2=255, Y=3, U=2, V=2)
v3 = (mode==1) ? v.Tweak(cont=contrast) : v.Tweak(cont=contrast,bright=brightness)
merged=mt_merge(v,v3,v2)
return merged
}
I was also doing a Contrast Mask so here goes:

# Contrast Masking:
# a) Desaturate and invert the original.
# b) Apply a Gaussian Blur
# c) Overlay.

Example: http://www.digicamhelp.com/processin...trast-masking/

Code:
function ContrastMask(clip v, float "gblur", float "enhance")
{
enhance = default (enhance, 10.0)
tvcolor = default (tvcolor, true)
gblur = default (gblur, 20.0)
enhance = (enhance>=0.0 && enhance<=10.0) ? float(enhance*0.1) : 1.0
v2=v.Tweak(sat=0)
v2=v2.invert()
v2=v2.gaussianblur(50.0,50.0+gblur)
photoshop_overlay=mt_lutxy(v,v2,"x 127.5 > y 255 x - 127.5 / * x 255 x - - + y x 127.5 / * ? ")
merged=overlay(v,photoshop_overlay,opacity=enhance)
return merged
}
Requirements:
Variableblur (also requires fftw version 3)
mt_masktools
autolevels

Last edited by javlak; 23rd July 2011 at 14:20. Reason: Version 1.1 of LCE
javlak is offline   Reply With Quote
Old 21st July 2011, 19:50   #3  |  Link
Yellow_
Registered User
 
Join Date: Sep 2009
Posts: 378
ok, super, looking forward to giving it ago, thanks for posting work so far.
Yellow_ is offline   Reply With Quote
Old 21st July 2011, 20:26   #4  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
Hi again.

As I said, this is a work in progress so it might have a few mistakes. As a matter of a fact, I have now corrected an error in the LCE function so I advise to upgrade to the newer version. Also, I think the default gblur/contrast values might be too low.
javlak is offline   Reply With Quote
Old 21st July 2011, 22:45   #5  |  Link
Mounir
Registered User
 
Join Date: Nov 2006
Posts: 709
it would be interesting to see the differences (with pictures) between LCE and traditional unsharpmask imo.
Mounir is offline   Reply With Quote
Old 22nd July 2011, 19:18   #6  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
I have posted version 1.0 of both functions, I hope you enjoy.

Here's two screenshots for comparison:

Original:

LCE mode=1, contrast=2.0:


More screenshot comparisons including the Contrast Mask at:

http://screenshotcomparison.com/comparison/68449

Last edited by javlak; 22nd July 2011 at 20:01.
javlak is offline   Reply With Quote
Old 25th July 2011, 22:44   #7  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
@javlak

I have little problem using Contrast Masking in my realtime scripts. I get a crash in the videplayer concerning FFTW3 when the video load ( the file FFTW3 is present in my systehm32)

Do you know if there is any problem about using Contrast Masking realtime?
Any possible fix to solve that? or maybe different way to do same thing with other avisynth functions?
travolter is offline   Reply With Quote
Old 26th July 2011, 11:27   #8  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
Quote:
Originally Posted by travolter View Post
@javlak

I have little problem using Contrast Masking in my realtime scripts. I get a crash in the videplayer concerning FFTW3 when the video load ( the file FFTW3 is present in my systehm32)

Do you know if there is any problem about using Contrast Masking realtime?
Any possible fix to solve that? or maybe different way to do same thing with other avisynth functions?
Hi, I run both these functions without problems. Three things that could go wrong I guess is:
- If you have 64-bit Vista or win 7, fftw3 needs to be in the %SYSTEMPATH%\SYSWOW64 directory
- It's been a while so I don't recall exactly, but there's a possibility that you may also need libfftw3f-3.dll, which really is just the fftw3.dll, only it's renamed.
- Perhaps you have a fftw3 version that is not compatible with variableblur? The one in the avisynth plugins directory works just fine iirc.

Last edited by javlak; 26th July 2011 at 11:34.
javlak is offline   Reply With Quote
Old 26th July 2011, 14:44   #9  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
Its working now!!! thanks for your support.

the problem was my fftw3 version that was not compatible with variableblur as you said.

Last edited by travolter; 26th July 2011 at 14:53.
travolter is offline   Reply With Quote
Old 26th July 2011, 23:44   #10  |  Link
SSH4
Registered User
 
Join Date: Nov 2006
Posts: 87
why just not use UnsharpMask filter on Avisinth?
it have similar with Photoshop settings.

or mergeluma(last,UnsharpMask(*,*,*))

Last edited by SSH4; 26th July 2011 at 23:46.
SSH4 is offline   Reply With Quote
Old 27th July 2011, 13:44   #11  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
Quote:
Originally Posted by SSH4 View Post
why just not use UnsharpMask filter on Avisinth?
it have similar with Photoshop settings.

or mergeluma(last,UnsharpMask(*,*,*))
.....

Quote:
Hope you enjoy. LCE should be able to produce similar effects as any unsharp mask, with the difference that it offers different variables to experiment with than radius, amount and threshold. So if the user requires it, it can be less subtle.
javlak is offline   Reply With Quote
Old 1st August 2011, 00:01   #12  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
Im testing ContrastMask and Im very very happy with it. Some vids looks like HDR ones but i have a problem.

I have to disable this line in contrastmask function to work.
Quote:
tvcolor = default (tvcolor, true)
I dont know the purpose of this line. Can I replace it for other command to get the same result?
maybe you forgot to remove it?

About LCE I dont know if Im using wrong settings or the effect is not so strong as ContrastMask.

Plz if you do updates to these functions let me know.. Im huge fan of these HDR techniques applied to videos

Last edited by travolter; 1st August 2011 at 00:17.
travolter is offline   Reply With Quote
Old 1st August 2011, 18:01   #13  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
Hi, the tvcolor variable is a leftover from older code. You can remove it completely. Sorry about that.

About LCE, its use is different than the Contrast Mask. Contrast Masking is used to bring out detail in darker areas, whereas LCE is just local contrast enhancement, which according to your inputs can range from a subtle sharpen effect to a more apparent contrast enhancement in certain areas.

Time on my hands is a bit limited, but when/ if I update the code, I'll post.

Last edited by javlak; 1st August 2011 at 18:10.
javlak is offline   Reply With Quote
Old 22nd August 2011, 09:52   #14  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
Im looking a way to "Darken the highlights"

I was reading this manual http://www.pronaturephotographer.com...-in-photoshop/

and i wonder if its possible to do in avisynth.

Im using contrastmask a lot... I fixed it using two resizes between the gaussian blur to save cpu power and do realtime.. and I wonder if adding a "Darken the highlights" function I could create HDR vids with less cpu power as HDR-AGC

Last edited by travolter; 22nd August 2011 at 10:00.
travolter is offline   Reply With Quote
Old 23rd August 2011, 13:57   #15  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
Hi. Let me know if something like the following can be of use to you:

function HighlightLimiter(clip v, float "gblur", int "threshold", bool "twopass")
{

gblur = default (gblur,5.0) #Low gblur values can introduce color banding, high values reduce accuracy.
threshold = default (threshold,150) #The lower the value, the more sensitive the filter will be.
twopass = default (twopass,false) #Two passes means the area in question gets darkened twice.


darken=v.mt_lut("x "+string(threshold)+" > 255 0 ?").Tweak(sat=0)
blurred=darken.gaussianblur(gblur)
multiply=mt_lut(v,"x x * 255 /")
multiply = (twopass==true) ? mt_lutxy(multiply,v,"x y * 255 /") : multiply
return mt_merge(v,multiply,blurred)
}

Mostly untested, but if it works let me know, maybe the guys from this thread find it useful?
javlak is offline   Reply With Quote
Old 24th August 2011, 14:14   #16  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
Pal!!! the functions that you created are amazing!!!!
Im trying to create HDR videos since years.. and now with your HighlightLimiter & ContrastMask the results are incredible!!!

I uploaded some examples:
ORIGINAL / HIGHLIGHTLIMITER / HIGHLIGHTLIMITER & CONTRASTMASK







Really big thanks for these functions!!! I tried to obtain same result with HDR-AGC but I never got same results as the ones that Im posting

One question: Do you think that HighlightLimiter before ContrastMask is the best chain to create HDR?

Im not sure how is the chain of filters on these HDR image programs... I know that they use 3 image sources. (Its posible to do the same with avisynth?)

I think that having these good results with HighlightLimiter & ContrastMask its the time for you to create the HDR plugin that will replace HDR-AGC


edit.- for realtime usage Im using a resize before and after gaussian blur
biliearresize(320,180).gaussianblur(gblur).spline64resize(1280,720)

I wonder if this is the best way to save CPu cycles in HighlightLimiter & ContrastMask.
When I resize the gaussianblur "mask" change and I have to use different blur settings to obtain same/similar effect as full version (Im not sure if the effect is downgraded with these resizes)

What would be the best way to tweak these HighlightLimiter & ContrastMask using resize for cpu saving?

Last edited by travolter; 24th August 2011 at 16:58.
travolter is offline   Reply With Quote
Old 24th August 2011, 17:31   #17  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,981
I can't get either function to work. I get the following error:

"An out-of-bounds memory access (access violation) occurred in module 'fftw3'"

I traced this to the "gaussianblur" call.

I checked everything, and I have fftw3.dll in my system32 folder (I'm running Win XP Pro 32-bit). It is dated 7/26/2011 (I had an earlier version and had the same error message, so I just updated to this version). This DLL was created by copying the libfftw3f-3.dll and then renaming it. This is supposed to be the version 3 of this DLL. The variableblur.dll is dated 3/14/2011.

I hate DLLs.
johnmeyer is offline   Reply With Quote
Old 24th August 2011, 17:48   #18  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
I had fftw3 problem too.. download the one from avisynth plugins directory
http://avisynth.org/warpenterprises/...3_20040130.zip
travolter is offline   Reply With Quote
Old 24th August 2011, 18:07   #19  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,981
That's the really old (2004) DLL. I saw that link in the variableblur wiki, but it didn't make sense because I thought the readme said it needed version 3. I don't want to break everything else by using an old DLL, so I'll see if I can put everything in a folder, including the fft DLL, and get it to work.

I hate DLLs.
johnmeyer is offline   Reply With Quote
Old 24th August 2011, 18:19   #20  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 1,981
OK, I found the old "loaddll" DLL which lets me locally load (not in system32) the old version of fftw3 without disturbing the newest version in system32. The functions now work. Thanks for the help!
johnmeyer is offline   Reply With Quote
Reply

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 09:42.


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