View Full Version : Local Contrast Enhancement
Yellow_
21st July 2011, 13:44
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.
javlak
21st July 2011, 19:16
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/tutorials/local-contrast-enhancement.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
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/processing-photos/advanced-editing/contrast-masking/
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
Yellow_
21st July 2011, 19:50
ok, super, looking forward to giving it ago, thanks for posting work so far.
javlak
21st July 2011, 20:26
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.
Mounir
21st July 2011, 22:45
it would be interesting to see the differences (with pictures) between LCE and traditional unsharpmask imo.
javlak
22nd July 2011, 19:18
I have posted version 1.0 of both functions, I hope you enjoy.
Here's two screenshots for comparison:
Original:
http://s2.postimage.org/em7ur1lp9/original.png (http://www.postimage.org/)
LCE mode=1, contrast=2.0:
http://s2.postimage.org/wc9uwuer5/LCE_mode1_2.png (http://www.postimage.org/)
More screenshot comparisons including the Contrast Mask at:
http://screenshotcomparison.com/comparison/68449
travolter
25th July 2011, 22:44
@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?
javlak
26th July 2011, 11:27
@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.
travolter
26th July 2011, 14:44
Its working now!!! thanks for your support.
the problem was my fftw3 version that was not compatible with variableblur as you said.
SSH4
26th July 2011, 23:44
why just not use UnsharpMask filter on Avisinth?
it have similar with Photoshop settings.
or mergeluma(last,UnsharpMask(*,*,*))
javlak
27th July 2011, 13:44
why just not use UnsharpMask filter on Avisinth?
it have similar with Photoshop settings.
or mergeluma(last,UnsharpMask(*,*,*))
.....
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.
travolter
1st August 2011, 00:01
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.
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
javlak
1st August 2011, 18:01
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.
travolter
22nd August 2011, 09:52
Im looking a way to "Darken the highlights"
I was reading this manual http://www.pronaturephotographer.com/2011/01/how-to-darken-a-light-area-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
javlak
23rd August 2011, 13:57
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 (http://forum.doom9.org/showthread.php?t=128585&page=5) find it useful?
travolter
24th August 2011, 14:14
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
http://thumbnails25.imagebam.com/14647/d060e1146464115.jpg (http://www.imagebam.com/image/d060e1146464115) http://thumbnails35.imagebam.com/14647/3dc9bd146464210.jpg (http://www.imagebam.com/image/3dc9bd146464210) http://thumbnails49.imagebam.com/14647/8f288d146464340.jpg (http://www.imagebam.com/image/8f288d146464340)
http://thumbnails54.imagebam.com/14647/1792c5146464474.jpg (http://www.imagebam.com/image/1792c5146464474) http://thumbnails27.imagebam.com/14647/f94183146464604.jpg (http://www.imagebam.com/image/f94183146464604) http://thumbnails44.imagebam.com/14647/5ff407146464778.jpg (http://www.imagebam.com/image/5ff407146464778)
http://thumbnails49.imagebam.com/14647/583ef4146464923.jpg (http://www.imagebam.com/image/583ef4146464923) http://thumbnails47.imagebam.com/14647/e4c271146465011.jpg (http://www.imagebam.com/image/e4c271146465011) http://thumbnails47.imagebam.com/14647/ea5ced146465157.jpg (http://www.imagebam.com/image/ea5ced146465157)
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?
johnmeyer
24th August 2011, 17:31
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.
travolter
24th August 2011, 17:48
I had fftw3 problem too.. download the one from avisynth plugins directory
http://avisynth.org/warpenterprises/files/fftw3_20040130.zip
johnmeyer
24th August 2011, 18:07
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
24th August 2011, 18:19
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
24th August 2011, 19:12
travolter, what settings are you using for these two functions? The defaults give me very poor results, and even after trying various settings, I can't get anything even close to what you show in your samples above.
javlak
24th August 2011, 21:20
Wow, I have no idea what travolter used to make these photos look so good! Thank you for your kind words too.
Personally, I have these functions in the "work in progress" folder. I hate the way Contrast Mask can introduce a contrast halo around things some times and most of the times I find that the Highlight Limiter introduces banding due to the way it works (hard limiting). Maybe I should also replace the gaussian blur used by variableblur with something else so we don't have people using old dlls (although I use this particular dll with every new function/filter without problems).
I remember Didee saying that he was going to make an HDRAGC replacement ages ago, I have no idea what happened to that project. I'd put my money on his work any day instead of mine!
Also, I must note that between taking care of my baby daughter, my day job and my other projects, I don't have too much time on my hands so if anyone is interested in improving/ maintaining these poor dinosaurs, I wouldn't take offense and they have my full permission to do so :)
johnmeyer
24th August 2011, 21:42
Wow, I have no idea what travolter used to make these photos look so good! Thank you for your kind words too.
Personally, I have these functions in the "work in progress" folder. I hate the way Contrast Mask can introduce a contrast halo around things some times and most of the times I find that the Highlight Limiter introduces banding due to the way it works (hard limiting). ... Thanks for that information. Those are exactly the same two issues I was having, especially the banding with Highlight Limiter. I'll treat the code as you suggest (a "work in progress") and may try to use portions of it in my film restoration work.
Thanks!
travolter
25th August 2011, 10:11
travolter, what settings are you using for these two functions? The defaults give me very poor results, and even after trying various settings, I can't get anything even close to what you show in your samples above.
oh .. my bad.. I did not write exactly the settings that I used because I modified for each picture.. but the chain was:
HighlightLimiter(50, 120, false) (I remember modify a little these values until I removed the banding)
Contrastmask(toy with the values until you get a image with not very tiny halos arround images)
a very important thing is that you need a good video source being shoot with correct white balance. If you use colorized sources the effect is not so clear.. so try to apply a white balance plugin before when needed
@javlak
I was testing replacing gaussianblur with variableblur, but the results are not so good, and sadly I dont see other available gaussian blurs :(
Ill continue using these filters and try to improve if possible. At moment I was tweaking them to use realtime (one thing that was no possible with HDRAGC).
I hope that this HDR proyect continue and we will build a decent HDR plugin ( there are a lot of fans of these images arround ;)
javlak
25th August 2011, 17:04
Hi again.
I decided to change the approach to a more video-oriented style, i.e. replace the multiplication function for brightness. I think you will find that the effect is more subtle with no apparent banding. However, for extreme values I also added a fuzziness mask, whose job is to hopefully smooth out the value differences between areas and thus reduce banding effects, up to a certain degree of course.
I guess we can call this HighlightLimiter v1.00! :)
function HighlightLimiter(clip v, float "gblur", int "threshold", bool "twopass", int "amount", bool "softlimit")
{
gblur = default (gblur,5.0) #The strength of the gaussian blur to apply.
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.
amount = default (amount,10) #The amount of brightness to be reduced
softlimit = default (softlimit,false) #If softlimit is true, then the values around the edges where the pixel value differences occur, will be averaged. Set to true only for extreme amount values, or else this might introduce banding.
amount = (amount>0) ? -amount : amount
darken=v.mt_lut("x "+string(threshold)+" > 255 0 ?").Tweak(sat=0)
blurred=darken.gaussianblur(gblur)
fuzziness_mask=blurred.mt_edge(mode="prewitt").mt_expand(mode="both")
multiply=v.Tweak(bright=amount)
multiply = (twopass==true) ? multiply.SmoothLevels(gamma=0.9,smode=2) : multiply
merged=mt_merge(v,multiply,blurred)
fuzzy= (softlimit==true) ? mt_merge(merged,mt_lutxy(v,merged,"x y + 2 /"),fuzziness_mask) : merged
return fuzzy
}
johnmeyer
25th August 2011, 17:52
This function is a definite improvement, but I still have similar problems. Here is a very small, less than one second, test clip:
Test Clip (Divx) (http://dl.dropbox.com/u/1561578/test%20clip.avi)
of a guy with a white t-shirt walking in front of the on-camera light. As you can see, not surprisingly, the shirt gets overexposed.
For those who don't want to take the time to download the clip, here is a still clip of the original (left side) and the output of the function (right side):
http://i177.photobucket.com/albums/w208/johnmeyer/testclip.jpg
I have tried a fairly large number of settings, including a large value (100) for gblur, but I can't seem to get anything that "fades" the edges properly. For instance, try these settings with this test clip (these are the settings which produced the above result shown in the still clip):
HighlightLimiter(source,threshold=200,amount=20,softlimit=false,gblur=5)
I think the solution is to somehow blend the mask edges. I think this is what the mask blur is supposed to achieve, but the edges still look very much defined, even with large values of gblur. I have never been able to fully understand the masktools functions, so I don't know if this tool is capable of creating a "fade" or true blend around the edges.
Your function is very, very close (tantalizingly close) to be an extremely useful tool. I hope that one of the mask experts can suggest a hint or two that might solve this problem.
In looking at the before/after one more time before posting, perhaps the solution lies in replacing the function which darkens the video with one which does not darken if the video level equals the threshold amount, but then darkens progressively more for the pixels that are further from this boundary, and closer to pure 255 bright. That function would have to be clever because, like audio AGC, you don't want to have every "note" become the same volume. I guess that would be the video equivalent of the Phil Spectre "wall of sound."
travolter
26th August 2011, 11:03
@javlak
hey!! thanks for the update ;) I was testing it and there are improvements ;) I love a lot the new "amount control" so I can add more darkness ;)
I didnt find a correct way to use the "softlimit" control, but sure that its useful in certain situations ;)
At moment the function is pretty nice I love it a lot. I usually get rid of banding lowering the Threhold amount.
I hope that someone could help us to improve these functions, as johnmeyer says.
An example with HighlightLimiter(50,100,false,70)
http://thumbnails54.imagebam.com/14674/e923d9146736173.jpg (http://www.imagebam.com/image/e923d9146736173) http://thumbnails56.imagebam.com/14674/de79b8146736248.jpg (http://www.imagebam.com/image/de79b8146736248)
@johnmeyer
here my approach for your vid, but I cannt apply to much "dark" amount. The overexposed problem is present when I increase the parameters amount.. If you know someone that could help us with your suggestions let him know ;)
HighlightLimiter(50,60,false,20)
http://thumbnails13.imagebam.com/14674/ba01f1146736292.jpg (http://www.imagebam.com/image/ba01f1146736292) http://thumbnails34.imagebam.com/14674/ef907f146736338.jpg (http://www.imagebam.com/image/ef907f146736338)
javlak
26th August 2011, 22:48
Hi again guys. Thank you so much for your input. John, what you describe is a gradient mask with the proper dimensions inside every area that is above the threshold. It can easily be done with static images using Photoshop, GIMP et al, but I know of no way to do that in Avisynth. Therefore we will compromise a tad and do this:
function HighlightLimiter(clip v, float "gblur", bool "gradient", int "threshold", bool "twopass", int "amount", bool "softlimit", int "method")
{
gradient = default (gradient,true) #True uses the gaussian blur to such an extent so as to create an effect similar to a gradient mask being applied to every area that exceeds our threshold.
gblur = (gradient==true) ? default (gblur,100) : default (gblur,5.0) #The strength of the gaussian blur to apply.
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.
amount = default (amount,10) #The amount of brightness to be reduced, only applied to method=2
softlimit = default (softlimit,false) #If softlimit is true, then the values around the edges where the pixel value differences occur, will be averaged.
method = default (method, 1) #Method 1 is multiply, the classic HDR-way. Any other method set triggers a brightness/gamma approach.
amount = (amount>0) ? -amount : amount
darken=v.Tweak(sat=0).mt_lut("x "+string(threshold)+" < 0 x ?")
blurred= (gradient==true) ? darken.gaussianblur(gblur).gaussianblur(gblur+100).gaussianblur(gblur+200) : darken.gaussianblur(gblur)
fuzziness_mask=blurred.mt_edge(mode="prewitt", Y=3, U=2, V=2).mt_expand(mode="both", Y=3, U=2, V=2)
multiply = (method==1) ? mt_lut(v,"x x * 255 /") : v.Tweak(bright=amount)
multiply = (method==1) ? eval("""
(twopass==true) ? mt_lutxy(multiply,v,"x y * 255 /") : multiply""") : eval("""
(twopass==true) ? multiply.SmoothLevels(gamma=0.9,smode=2) : multiply""")
merged=mt_merge(v,multiply,blurred)
fuzzy= (softlimit==true) ? mt_merge(merged,mt_lutxy(v,merged,"x y + 2 /"),fuzziness_mask) : merged
return fuzzy
}
Let me know what you think of this. Hopefully this is better :)
travolter
27th August 2011, 17:39
Let me know what you think of this. Hopefully this is better :)
WOW!!! I have no words... !!! Amazing!!!! all the artifacts/banding/halos/burns etc from previous versions are gone!!!!
Check the examples using new and old version with same settings:
original / (new)HighlightLimiter(70,true,80,false,100) / (old)HighlightLimiter(70,80,false,100)
http://thumbnails51.imagebam.com/14693/6108bf146922658.jpg (http://www.imagebam.com/image/6108bf146922658) http://thumbnails45.imagebam.com/14693/bb48db146922846.jpg (http://www.imagebam.com/image/bb48db146922846) http://thumbnails55.imagebam.com/14693/d7a91e146923103.jpg (http://www.imagebam.com/image/d7a91e146923103)
http://thumbnails49.imagebam.com/14693/98accf146923509.jpg (http://www.imagebam.com/image/98accf146923509) http://thumbnails56.imagebam.com/14693/f1a563146923820.jpg (http://www.imagebam.com/image/f1a563146923820) http://thumbnails27.imagebam.com/14693/92b66f146924138.jpg (http://www.imagebam.com/image/92b66f146924138)
http://thumbnails42.imagebam.com/14693/e822d5146924362.jpg (http://www.imagebam.com/image/e822d5146924362) http://thumbnails52.imagebam.com/14693/bb5d01146924570.jpg (http://www.imagebam.com/image/bb5d01146924570) http://thumbnails39.imagebam.com/14693/40c3d4146924725.jpg (http://www.imagebam.com/image/40c3d4146924725)
I think that you have success totally with this function ;) The HDR is now possible and with very high quality ;)
Now a personal request: could you fix the contrastmask function in the same way as you fixed HighlightLimiter please? The halos are killing me yet. I know that you have few free time.. but I can wait :)
Ill continue testing HighlightLimiter, Im very happy with the quality that you can get now!
Very good job pal!!! :)
javlak
3rd September 2011, 10:50
Hi again and thanks :)
Judging from the fact that johnmeyer hasn't commented yet, I guess the newer version doesn't work for him either? That's strange, as I applied it to his sample video and it looked good. Travolter, since time is limited what I did was just copy/paste most of the stuff from the new HighlightLimiter. Let me know how it works for you.
function Highlighter(clip v, float "gblur", bool "gradient", int "threshold", bool "twopass", int "amount", bool "softlimit", int "method")
{
gradient = default (gradient,true)
gblur = (gradient==true) ? default (gblur,100) : default (gblur,5.0)
threshold = default (threshold,100)
twopass = default (twopass,false)
amount = default (amount,10)
softlimit = default (softlimit,false)
method = default (method, 1)
amount = (amount<0) ? abs(amount) : amount
lighten=v.Tweak(sat=0).mt_lut("x "+string(threshold)+" > 0 x ?")
blurred= (gradient==true) ? lighten.gaussianblur(gblur).gaussianblur(gblur+100).gaussianblur(gblur+200) : lighten.gaussianblur(gblur)
fuzziness_mask=blurred.mt_edge(mode="prewitt", Y=3, U=2, V=2).mt_expand(mode="both", Y=3, U=2, V=2)
photoshop_overlay = (method==1) ? mt_lutxy(v,blurred.invert(),"x 127.5 > y 255 x - 127.5 / * x 255 x - - + y x 127.5 / * ? ") : \
(method==2) ? mt_lut(v,mt_polish("255 255 x - 255 y - * 255 / -")) : v.Tweak(bright=amount)
photoshop_overlay = (twopass==true) ? photoshop_overlay.SmoothLevels(gamma=2.0,smode=2) : photoshop_overlay
merged=mt_merge(v,photoshop_overlay,blurred)
fuzzy= (softlimit==true) ? mt_merge(merged,mt_lutxy(v,merged,"x y + 2 /"),fuzziness_mask) : merged
return fuzzy
}
travolter
3rd September 2011, 15:56
@javlak thanks again for you help. I was trying to fix the contrast mask by my own.. but Im not masks expert like you.
The two functions are really amazing now!!! You have create very good tools. For me this thread have been very productive to make hdr images.
Again, here some examples.. original/Highlighter/Highlighter+contrastmask(new).
http://thumbnails44.imagebam.com/14788/8edced147871598.jpg (http://www.imagebam.com/image/8edced147871598) http://thumbnails55.imagebam.com/14788/2ac5c2147871625.jpg (http://www.imagebam.com/image/2ac5c2147871625) http://thumbnails39.imagebam.com/14788/77ab28147871673.jpg (http://www.imagebam.com/image/77ab28147871673)
Thanks again for your support and I hope that this thread will be useful to people trying to create HDR videos.
johnmeyer
3rd September 2011, 16:18
Judging from the fact that johnmeyer hasn't commented yet, I guess the newer version doesn't work for him either? Sorry, I haven't been able to get to it in the past week. I appreciate your effort and do plan to try it again.
Yellow_
23rd December 2011, 01:06
Digging up an old thread, but with regard to the local contrast enhancement function, which generates a higher contrast image of the original and then merges, if I were to have two images for each frame, one of which is of higher exposure than the other, could the LCE function be adapted to use the high contrast frame with the original in order to merge the two exposures?
lisztfr9
30th January 2012, 00:23
travolter, what settings are you using for these two functions? The defaults give me very poor results, and even after trying various settings, I can't get anything even close to what you show in your samples above.
I can't see any effect but i'm new to Avisynth, i tried on color bar :
colorbars(512,256).ConvertToYUY2
a1 = trim(0,600)
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
}
ContrastMask(a1)
ConvertToRGB(a1)
====================
Thanks, i spent my hole afternoon on trying to figure things out.
mplayer2.exe needs RGB, therefor the color space statement.
Gavino
30th January 2012, 00:52
I can't see any effect
Instead of ConvertToRGB(a1), you should have just ConvertToRGB().
It will then convert the result of the ContrastMask (the 'last' operation), rather than the original video.
lisztfr9
30th January 2012, 12:28
Instead of ConvertToRGB(a1), you should have just ConvertToRGB().
It will then convert the result of the ContrastMask (the 'last' operation), rather than the original video.
Hi,
i just tried it, but then i get the "Assertion Failed!" error from mplayer2...
colorbars(512,256).ConvertToYUY2
a1 = trim(0,600)
/*
a2 = MessageClip("Text clip")
overlay(a1,a2, y = 100, x = 110, mode="subtract", opacity=0, pc_range=true)
ConditionalReader("C:\Program Files\AviSynth 2.5\Examples\opacity.txt", "ol_opacity_offset", false)
ConditionalReader("C:\Program Files\AviSynth 2.5\Examples\xoffset.txt", "ol_x_offset", false)
*/
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
}
ContrastMask(a1)
ConvertToRGB()
Gavino
30th January 2012, 12:37
Ah, I missed that you had another error in your script.
ContrastMask requires YV12, not YUY2.
So change ConvertToYUY2 to ConvertToYV12.
(Or use ColorBars(512,256, pixel_type="YV12") and avoid conversion altogether.)
lisztfr9
30th January 2012, 14:11
Ah, I missed that you had another error in your script.
ContrastMask requires YV12, not YUY2.
So change ConvertToYUY2 to ConvertToYV12.
(Or use ColorBars(512,256, pixel_type="YV12") and avoid conversion altogether.)
Thanks ! Now i see some effect, - but i have to return to RGB.
In fact i need the Local Contrast Enhancement (LCE) to restore a bad VHS with lots of haze, this exist in Gimp (using unsharp mask with huge radius) but doesn't exist in VD. So this thread here is very helpful :)
My test script now looks like this :
colorbars(512,256).ConvertToYV12
a1 = trim(0,600)
/*
a2 = MessageClip("Text clip")
overlay(a1,a2, y = 100, x = 110, mode="subtract", opacity=0, pc_range=true)
ConditionalReader("C:\Program Files\AviSynth 2.5\Examples\opacity.txt", "ol_opacity_offset", false)
ConditionalReader("C:\Program Files\AviSynth 2.5\Examples\xoffset.txt", "ol_x_offset", false)
*/
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
}
ContrastMask(a1).ConvertToRGB
# a1.ConvertToRGB
Didée
30th January 2012, 15:59
Something to play with - the "nonlinear" sharpening from SeeSaw, just with a wide-range gaussian instead of a small-range kernel.
z = 6 # z = zero point
p = 1.6 # p = power
str = 1.0 # str = strength
rad = 9.0 # radius for "gauss"
o = last
g = o.bicubicresize(round(o.width()/rad/4)*4,round(o.height()/rad/4)*4).bicubicresize(o.width(),o.height(),1,0)
mt_lutxy(o,g,"x x y - abs "+string(z)+" / 1 "+string(p)+" / ^ "+string(z)+" * "+string(str)+" * x y - x y - abs 0.001 + / * +",U=2,V=2)
interleave(o,last)
lisztfr9
30th January 2012, 17:16
Thanks, i will give it a try :)
Before i forget :
http://www.ericjoisel.com/gallery.html
lisztfr9
30th January 2012, 21:51
It seems that i have a problem with color space conversion, regarding the LCE function. From YUY2 to RGB, this still creates an error "Assertion failed" in player2.
I installed the Huffyuv (without restart) but the inf file register it...
travolter
31st January 2012, 15:27
Something to play with - the "nonlinear" sharpening from SeeSaw, just with a wide-range gaussian instead of a small-range kernel.
z = 6 # z = zero point
p = 1.6 # p = power
str = 1.0 # str = strength
rad = 9.0 # radius for "gauss"
o = last
g = o.bicubicresize(round(o.width()/rad/4)*4,round(o.height()/rad/4)*4).bicubicresize(o.width(),o.height(),1,0)
mt_lutxy(o,g,"x x y - abs "+string(z)+" / 1 "+string(p)+" / ^ "+string(z)+" * "+string(str)+" * x y - x y - abs 0.001 + / * +",U=2,V=2)
interleave(o,last)
wow Didée!! fantastic!!!!
I was playing with the script.. and it gives very nice results.
1) original
http://thumbnails33.imagebam.com/17254/decf0e172538364.jpg (http://www.imagebam.com/image/decf0e172538364)
2) 0.5/1.0/0.2/120.0
http://thumbnails55.imagebam.com/17254/1de859172538431.jpg (http://www.imagebam.com/image/1de859172538431)
3) 6.0/1.6/1.0/8.0
http://thumbnails49.imagebam.com/17254/ccb170172538526.jpg (http://www.imagebam.com/image/ccb170172538526)
How could I clean these little color blocks/artifacts that appear in the walls of 3rd image?.
I always have the same problem when using contrastmask scripts in HD movies.
A solution is not abuse of the effect.. but I wonder If I can clean the source in certain way to avoid the atifacts
lisztfr9
1st February 2012, 13:18
Hi Didée,
This is a lot to learn as a scripting language (also i can't find some good tutorial...).
I tried this :
function sharpen2(clip)
{
z = 6 # z = zero point
p = 1.6 # p = power
str = 1.0 # str = strength
rad = 9.0 # radius for "gauss"
o = last
g = o.bicubicresize(round(o.width()/rad/4)*4,round(o.height()/rad/4)*4).bicubicresize(o.width(),o.height(),1,0)
mt_lutxy(o,g,"x x y - abs "+string(z)+" / 1 "+string(p)+" / ^ "+string(z)+" * "+string(str)+" * x y - x y - abs 0.001 + / * +",U=2,V=2)
interleave(o,last)
}
sharpen2()
========================
Error on width, - "invalid argument for function width", even if i add width = 5
Avisynth version = 2.58
therefor i choose an old version of mt_masktools2, because the last one needs 2.6
Thanks, L
lisztfr9
1st February 2012, 13:24
Hi
Yes it looks fantastic, but could you help me to get it work ?
thanks so much, this is an amazing function !!
L
Gavino
1st February 2012, 14:09
Didée's fragment is meant to be used in a context where 'last' is defined.
In your function, replace 'o=last' by 'o=clip', or add 'clip' on a line by itself just before that.
Didée
1st February 2012, 14:30
@ travolter
Well, it's tricky. The best way to "not overdo" the effect is .... to not overdo the effect. :)
It could help to use some "parallel-path denoising", see here (http://forum.doom9.org/showthread.php?t=153170). Though, it depends on the temporal characteristic of those unwanted spots. If they are fluctuating, good. If they are persistent/static, bad luck.
It would also help to use stronger low-damping (not parametrized, it's the "0.001 +" term in the lut that would need to be increased). However, while this will reduce emphasizing of unwanted spots, it necessarily will also reduce the emphasizing of spots where the effect is actually welcome. Old story: there is a small pixel variation. Is it noise? Is it detail? Simple algorithms can't tell -- it's just that: a small pixel variation.
@ lisztfr9
function NonlinUSM(clip o, float "z", float "pow", float "str", float "rad", float "ldmp")
{
z = default(z, 6.0) # zero point
pow = default(pow, 1.6) # power
str = default(str, 1.0) # strength
rad = default(rad, 9.0) # radius for "gauss"
ldmp= default(ldmp, 0.001) # damping for verysmall differences
g = o.bicubicresize(round(o.width()/rad/4)*4,round(o.height()/rad/4)*4).bicubicresize(o.width(),o.height(),1,0)
mt_lutxy(o,g,"x x y - abs "+string(z)+" / 1 "+string(pow)+" / ^ "+string(z)+" * "+string(str)+
\ " * x y - 2 ^ x y - 2 ^ "+string(ldmp)+" + / * x y - x y - abs 0.001 + / * +",U=2,V=2)
#interleave(o,last) # just for visualisation, you don't want the function to do this
return(last)
}
Note that I renamed the function to "NonlinUSM" (for "non-linear Unsharp Masking"). The name in itself doesn't matter, you could as well name it MickeyMouse() or BlueElephant() if you wanted. But since the function "sharpen2" is already used in SeeSaw, it seems better to use any other name, in order to avoid possible conflicts.
lisztfr9
1st February 2012, 15:28
I get this now :
http://cjoint.com/12fe/BBbpwQ9ZyDT.htm
there was a small error, by the way,
\ " * x y - 2 ^ x y - 2 ^ "+string(ldmp)+" / * x y - x y - abs 0.001 + / * +",U=2,V=2)
==============================
color-space YV12(), it seems to work :)
L
Didée
1st February 2012, 15:43
Oops, yes, there was a "+" missing. But your fix is also wrong.
My fault " * x y - 2 ^ x y - 2 ^ "+string(ldmp)" + / * x y - x y - abs 0.001 + / * +"
^^
Your fault " * x y - 2 ^ x y - 2 ^ "+string(ldmp)+" / * x y - x y - abs 0.001 + / * +"
^^
Correct " * x y - 2 ^ x y - 2 ^ "+string(ldmp)+" + / * x y - x y - abs 0.001 + / * +"
^^^^
Function in previous post has been corrected.
lisztfr9
1st February 2012, 19:47
I have got it to work on the video i want to convert.
The colors seems more saturated, but in another way that would be provided by colormil (VD), more neutral, and better imho.
This is a Local contrast enhancement filter, witch is very often my preferred image processing method... it should be used with very large radius, like 50 :
http://gimpguru.org/tutorials/removinghaze/
"Set the Radius parameter to a largish, seemingly unreasonable value somewhere between 50 and 100."
lisztfr9
1st February 2012, 22:28
http://cjoint.com/12fe/BBbwsW6v5pi.htm
I would like to remove the dark lines around the white neckties in this movie. Any suggestion ?
I open the video in VD, then frameserve to avisynth, to finally convert in Winff.
So your function Didée does sharpening and Contrast enhancement. So i have this enabled along with cnr2(), and in VD i desinterlace, crop, and reduce a little the high levels... If you have any better idea ?
Sharpening with contrast mask will only underline the neckties and they are already so dam white. Previously i used internal sharpening from VD. Maybe the source is too bad.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.