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 24th August 2011, 19:12   #21  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,685
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.
johnmeyer is offline   Reply With Quote
Old 24th August 2011, 21:20   #22  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
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
javlak is offline   Reply With Quote
Old 24th August 2011, 21:42   #23  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,685
Quote:
Originally Posted by javlak View Post
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!

Last edited by johnmeyer; 25th August 2011 at 15:44. Reason: corrected spelling error
johnmeyer is offline   Reply With Quote
Old 25th August 2011, 10:11   #24  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 138
Quote:
Originally Posted by johnmeyer View Post
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

Last edited by travolter; 25th August 2011 at 10:15.
travolter is offline   Reply With Quote
Old 25th August 2011, 17:04   #25  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
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
}
javlak is offline   Reply With Quote
Old 25th August 2011, 17:52   #26  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,685
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)

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):



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):
Code:
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."

Last edited by johnmeyer; 25th August 2011 at 17:54. Reason: Changed the order to two sentences for clarification
johnmeyer is offline   Reply With Quote
Old 26th August 2011, 11:03   #27  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 138
@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)


@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)

Last edited by travolter; 26th August 2011 at 11:07.
travolter is offline   Reply With Quote
Old 26th August 2011, 22:48   #28  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 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:

Code:
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

Last edited by javlak; 26th August 2011 at 22:58.
javlak is offline   Reply With Quote
Old 27th August 2011, 17:39   #29  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 138
Quote:
Originally Posted by javlak View Post
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)





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!!!

Last edited by travolter; 27th August 2011 at 17:49.
travolter is offline   Reply With Quote
Old 3rd September 2011, 10:50   #30  |  Link
javlak
Registered User
 
Join Date: Mar 2011
Posts: 48
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.

Code:
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
}
javlak is offline   Reply With Quote
Old 3rd September 2011, 15:56   #31  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 138
@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).


Thanks again for your support and I hope that this thread will be useful to people trying to create HDR videos.

Last edited by travolter; 3rd September 2011 at 16:03.
travolter is offline   Reply With Quote
Old 3rd September 2011, 16:18   #32  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,685
Quote:
Originally Posted by javlak View Post
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.
johnmeyer is offline   Reply With Quote
Old 23rd December 2011, 01:06   #33  |  Link
Yellow_
Registered User
 
Join Date: Sep 2009
Posts: 378
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?
Yellow_ is offline   Reply With Quote
Old 30th January 2012, 00:23   #34  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Same here

Quote:
Originally Posted by johnmeyer View Post
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.
lisztfr9 is offline   Reply With Quote
Old 30th January 2012, 00:52   #35  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by lisztfr9 View Post
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 30th January 2012, 12:28   #36  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
last

Quote:
Originally Posted by Gavino View Post
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()
lisztfr9 is offline   Reply With Quote
Old 30th January 2012, 12:37   #37  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
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.)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 30th January 2012, 14:11   #38  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Ok !

Quote:
Originally Posted by Gavino View Post
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
lisztfr9 is offline   Reply With Quote
Old 30th January 2012, 15:59   #39  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Something to play with - the "nonlinear" sharpening from SeeSaw, just with a wide-range gaussian instead of a small-range kernel.

Code:
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)
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 30th January 2012, 17:16   #40  |  Link
lisztfr9
Registered User
 
Join Date: Apr 2010
Posts: 175
Seesaw

Thanks, i will give it a try

Before i forget :

http://www.ericjoisel.com/gallery.html
lisztfr9 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 12:00.


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