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.

poisondeathray
2nd February 2012, 00:46
http://cjoint.com/12fe/BBbwsW6v5pi.htm

I would like to remove the dark lines around the white neckties in this movie. Any suggestion ?

Previously i used internal sharpening from VD


Don't sharpen so much, but you can try dehalo filters e.g. dehalo_alpha

http://avisynth.org/mediawiki/External_filters#Dehaloing

lisztfr9
2nd February 2012, 11:32
Don't sharpen so much, but you can try dehalo filters e.g. dehalo_alpha

http://avisynth.org/mediawiki/External_filters#Dehaloing

Hi,

I agree for reducing the sharpening very often... for example unsharp mask in VD, this creates a lot of artifacts along edges, so i go back to moderated sharpen (internal).

Here is the original :

http://cjoint.com/12fe/BBclwfwaQAR.htm

===============================

I'm trying Dehalo_alpha, it needs the expand function. It is part from mastools, but i have all of them...

Ok, i have them all. This begins to wear my cpu (E8400) :)

At a first glance it's very impressive ! It does something on that nasty artifact, - i would never thought it was possible to reduce them ! Thanks very much for your work guys, and support !

lisztfr9
17th February 2012, 11:46
Now using VirturaldubMod to be able to "play" with the scripts... to fine tune them.

Before i used VD with dmpgdec & Vfapi...

http://www.animemusicvideos.org/guides/avtech/amvappvdubmod.html

http://docs.gimp.org/en/gimp-imaging-photos.html#gimp-using-photography

Equalize does a nice effect.

yup
24th February 2012, 10:13
Hi lisztfr9!
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."
It is can implement with Avisynth

ColorYUV(autogain=true, autowhite=true)
unsharp(varY=15,varC=15,strength=1.0)# tritical variableblur revision

I try with my VHS capture source and see improvements.
yup.

yup
29th February 2012, 06:32
Hi all!
I suggest variance value relative low for this purpose.
I try find relation between radius for Gaussian blur and variance, i find two approaches:
from Gimp
sigma=(radius+1)/sqrt(2*log10(255))
variance=sigma^2=(radius+1)^2/(2*log10(255))
from common knowledge about normal distribution
3*sigma=radius
variance=radius^2/9
Both give higher value variance for local contrast enhancement from 250 to 2000 and for this value I see increase contrast even at strength 0.4.
Please confirm my calculations.
yup.

lisztfr9
16th April 2012, 09:57
(OT)

Hi guys,

I have a video with so many problems (VHS record) :

1) The video jerks vertically. It's unstable vertically
2) There is a echo artifact, in form of a white strip (could be blend out with some alpha blending).
3) There is also some flickering, sometimes : the luminescence quickly changes...

not mention awful chroma noise, etc.

Could the flickering be stabilized with some conditional scripting based on luma ?

Anyway this is OT, i will open new thread for healing this video.

lisztfr9
16th April 2012, 13:19
(OT)

Hi guys,

I have a video with so many problems (VHS record) :

1) The video jerks vertically. It's unstable vertically
2) There is a echo artifact, in form of a white strip (could be blend out with some alpha blending).
3) There is also some flickering, sometimes : the luminescence quickly changes...

not mention awful chroma noise, etc.

Could the flickering be stabilized with some conditional scripting based on luma ?

Anyway this is OT, i will open new thread for healing this video.


Hi all,

I already found some virtualdub filters for healing the flickering and the image shaking, Defliker and deshaker, but remains one nasty artifact, like here :

http://cjoint.com/12av/BDqolUo6ves.htm

How would you handle this ? subtracting a mask from the image, - but any advice would be thankfully taken. Also a good tutorial explaining avisynth scripting...

Maybe building on-the-fly the mask from the black strip donwside...

Thanks, L

lansing
20th April 2012, 04:00
in the HighlightLimiter script in post #28, smode was deleted from the newer version of SmoothLevels

Chainmax
14th May 2012, 16:08
So the current latest version of HighlightLimiter is the one on post 28 and the latest version of ContrastMask is on the OP, right? Also, is ContrastMask supposed to be obsolete with the latest HighlightLimiter?

javlak
16th May 2012, 12:13
Hi everyone,

Unfortunately my time is extremely limited so I don't have too much time to work on these scripts. Please feel free to adjust/develop/change them to fit your needs.

To answer your question Chainmax, ContrastMask has different functionality in the sense that it is purely a contrast mask, while the Highlight/HighlightLimiter functions do things a bit differently. You can see the differences in the posts made by travolter. I guess what I'm trying to say is that if you are looking for a contrast mask to see how it affects your picture, then ContrastMask is what you're looking for. Otherwise you can call it obsolete. These are the versions I have on my PC (and indeed they were written for SmoothLevels 1.x, the smode bit should be removed for SmoothLevels 2.x, but I think the end result might vary a bit so it might need some tweaking in that respect):


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
}



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) #The lower the value, the more sensitive the filter will be.
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_lutxy(v,blurred.invert(),"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
}

Gavino
16th May 2012, 12:40
function Highlighter(...)
{
...
(method==2) ? mt_lut(v,mt_polish("255 255 x - 255 y - * 255 / -")) : v.Tweak(bright=amount)
...
}
:confused:

mt_polish expects an infix (ie 'normal'-type) expression as input.

javlak
16th May 2012, 13:11
:confused:

mt_polish expects an infix (ie 'normal'-type) expression as input.

Corrected the 6-month old error there. Thanks for that Gavino!

Chainmax
6th June 2012, 01:10
I am getting an out-of-bounds memory access error related to fftw3.dll, of which the latest version is installed on my system.The current filterchain HighlightLimiter is on is as follows:

SetMemoryMax(900)

SetMTMode(5,4)

*plugin loading calls*

MPEG2Source("x:\wherever\somesource.d2v")

SetMTMode(2)

QTGMC(Preset="Very Slow", SubPel=4, Blocksize=8, Overlap=4, NNsize=3, NNeurons=4, EdiQual=2, EdiThreads=4)

vinverse()

Levels(10,1,253,16,235)

HighlightLimiter(70,true,80,false,100)

RemoveGrain(mode=5)

Stab()
Crop(2,2,718,574,align=true)
Spline36Resize(720,576)

source=last
preNR=source.RemoveGrain(mode=5)
preNR_super=preNR.MSuper(pel=2, sharp=1)
source_super=source.MSuper(pel=2, sharp=1)
backward_vec3 = MAnalyse(preNR_super,isb = true, delta = 3, overlap=4)
backward_vec2 = MAnalyse(preNR_super,isb = true, delta = 2, overlap=4)
backward_vec1 = MAnalyse(preNR_super,isb = true, delta = 1, overlap=4)
forward_vec1 = MAnalyse(preNR_super,isb = false, delta = 1, overlap=4)
forward_vec2 = MAnalyse(preNR_super,isb = false, delta = 2, overlap=4)
forward_vec3 = MAnalyse(preNR_super,isb = false, delta = 3, overlap=4)
source.MDegrain3(source_super,backward_vec1,forward_vec1,backward_vec2,forward_vec2,backward_vec3,forward_vec3,thSAD=375)

Spline36Resize(800,600)

GradFunkMirror(3.02)

dull=last
sharp=dull.LimitedSharpenFaster(Smode=4,Strength=250)
Soothe(sharp,dull,25)

Tweak(sat=1.4)

AddGrain(5,0.6,0.6)

AddGrain(3,0.2,0.2)

Distributor()

yup
6th June 2012, 06:14
Chainmax!
Try
EdiThreads=1 at QTGMC call.
yup.

Chainmax
6th June 2012, 14:05
Thanks for the suggestion yup, but as expected that didn't work, as the problem is when it uses the fftw3 DLL, likely on the HighlightLimiter call (it never did with DFTTest) and was the reason I upgraded to its latest version.

yup
6th June 2012, 16:10
Chainmax!
I am also update to last version libfftw3f-3.dll and dfttest work without problem.
yup.

Chainmax
9th June 2012, 14:23
Thanks yup, but like I said in the first post I already have the lates version of that DLL.

Chainmax
19th June 2012, 01:21
Anyone else?

matfra
19th June 2012, 14:10
Hello everyone.
This is the kind of script that I was looking for ! im a master of Photoshop and I used this technique a lot.
Can someone post the lastest version of those script please.
There is so mutch update in every pages. Im not sure what is the current version for those script.
Thank !!!

function Highlighter
function HighlightLimiter
function NonlinUSM
function LCE
function ContrastMask

travolter
23rd March 2013, 21:29
I did a mod of the original highlight limiter.
I wonder if its possible fix this highlight limiter version to use less CPU or maybe the effect can be archived easier


v=last
threshold=123
darken=v.Tweak(sat=0).mt_lut("x "+string(threshold)+" < 0 x ?")
rad=64
blurred=darken.bicubicresize(round(v.width()/rad/4)*4,round(v.height()/rad/4)*4).bicubicresize(v.width(),v.height(),1,0)
multiply=mt_lut(v,"x x * 265 /")
mt_merge(v,multiply,blurred)


(For more black .. increase the "265" value)

Blur code comes from Didée... original script posted in this thread

Chainmax
28th April 2013, 18:54
Since HighlightLimiter and dfttest use different FFTW3 versions, is there a way to use both filters in the same script?

javlak
29th April 2013, 11:56
Since HighlightLimiter and dfttest use different FFTW3 versions, is there a way to use both filters in the same script?

Hi,

I use both dfttest and HighlightLimiter in a lot of my scripts without problems. Even though I am not sure of the version of fftw3 I have, do you want me to upload it?

Chainmax
12th May 2013, 15:24
Thanks, but there's no need for that. This is more of a curiosity thing than anything else.

javlak
13th May 2013, 13:47
Well in that case I guess you could write a script that does the HighlightLimiter stuff, then mount it using pismo and avfs and then write another script that uses dfttest to denoise the mounted script as .avi. Never tried that one, but I think it should work.

Mixxen Mach
28th January 2016, 03:58
[QUOTE=javlak;1514814]

[snip]
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)
[snip]


Hi
I came in through the wrong door and I'm finding very useful-looking information here which I still need to fully learn how to apply.
I don't understand the Photoshop reference here--do I need to have Photoshop (I have GIMP) and do I need to create anything with PS here?
I need to be pointed to the introductory articles explaining how to use this information.

(I'm using this script in AvsPmod)

Thanks
MM

`Orum
29th January 2016, 20:40
I don't understand the Photoshop reference here--do I need to have Photoshop (I have GIMP) and do I need to create anything with PS here?

No. This is simply the name given to the variable and has nothing to do with Adobe Photoshop beyond what is in the filter's description.

Mixxen Mach
31st January 2016, 03:28
No. This is simply the name given to the variable and has nothing to do with Adobe Photoshop beyond what is in the filter's description.

Thanks!

LigH
18th August 2017, 10:48
:thanks:

Using ContrastMask to enhance a nightshot of a surveillance camera, trying to identify a number plate thief... Not much time to tune parameters, but defaults already help recognizing the body traits.

fenomeno83
7th October 2017, 13:08
@ 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.

Hi.
I'm using this sharpener and seems works very good.
I use it in photos
My problem is that is heavily dependent by photo resolution.
So the same parameters works too hard for lower resolution photos and good for high resolution photos and vice versa..
is there something to adaptable to photo resolution?

My purpouse is:
if in a a photo with for example resolution 4000x3000 works fine some settings, If I for example scale the same image to 2000x1500 what settings generates a comparable results?
some algorithm/setting indipendent by photo resolution... thanks

StainlessS
7th October 2017, 15:43
No idea, but perhaps below will assist someone else figure it out,


z = default(z, 6.0) # zero point
pow = default(pow, 1.6) # power
str = default(str, 1.0) # strength
ldmp= default(ldmp, 0.001) # damping for verysmall differences


rpn="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 + / * +"


rpn="x x y - abs z / 1 pow / ^ z * str * x y - 2 ^ x y - 2 ^ ldmp + / * x y - x y - abs 0.001 + / * +"

Infix="(
x+(
[ ((((abs(x-y)/z)^(1/pow))*z)*str) * (((x-y)^2) / (((x-y)^2)+ldmp)) ] * [(x-y)/(abs((x-y)) + 0.001)]
)
)"


The 0.001 in Magenta is the Didee mentioned "low-damping (not parametrized, it's the "0.001 +" term"
The red bracketed [] chunk will result, 1.0 + 0.001 if x-y is +ve and -1.0 + 0.001 if -ve.

fenomeno83
7th October 2017, 16:25
Thanks!
these parameters (thanks to raffriff42) works very fine with 15Mpx photos
NonlinUSM(z=3, str=0.5, rad=9, pow=1)...
they apply a little sharpening that removes the little blur effect...
but if I use the same parameters on 5/8MP photos, the effect is stronger...

It would be nice have something normalized, so if I apply a set of parameters because I want I specific power of the filter, they shoud produce the same/similar results independently of photo resolution

StainlessS
7th October 2017, 16:58
OK, where did RaffRiff post those numbers ?

With 5/8MP, maybe try z=1.5 or z=2.0, might also try str=0.25 or str=0.3 or str=0.4.
pow=1.0, switches off that effect [EDIT: z effect].

fenomeno83
7th October 2017, 17:17
I asked him by pm about a good sharpener..but values are just "starting point" (but i like them in 15Mp photos)
They are also here
http://avisynth.nl/index.php/NonlinUSM

Thanks for your suggestion..i'll try.
Should be usefull have a function that starting from parameters/resolution and desidered resolution return new parameters.
Something like parameters1:resolution1=parameters2:resolution2

StainlessS
7th October 2017, 17:30
Thanx for pointing that out on wiki, also nice link pointing here;- https://forum.doom9.org/showthread.php?t=171050&highlight=nonlinusm
for Usage Examples, explains whats happening a bit more (I'm beginning to understand it a lil bit now).

EDIT: Usage examples from above link below

NonlinUSM(pow=4) ## enhance: for low bitrate sources
NonlinUSM(z=3, pow=4.0, str=1, rad=6) ## enhance less
NonlinUSM(z=3, str=0.5, rad=9, pow=1) ## enhance less

NonlinUSM(z=6, str=1.5, rad=0.6).Sharpen(0.3) ## sharpen: for hi-q sources
NonlinUSM(z=3, str=2.5, rad=0.6) ## sharpen: less noise
NonlinUSM(z=6, pow=1.0, str=1, rad=6) ## unsharp

NonlinUSM(pow=1.0, rad=2, str=0.7) ## "smoothen" for noisy sources
NonlinUSM(pow=1.0, rad=18, str=0.5) ## smear: soft glow

NonlinUSM(z=6, pow=4.0, str=1, rad=36) ## local contrast
NonlinUSM(z=6, pow=1.0, str=1, rad=36) ## local contrast
NonlinUSM(z=16, pow=4.0, str=18, rad=6) ## B+W psychedelic
NonlinUSM(z=16, pow=2.0, str=2, rad=36) ## solarized
NonlinUSM(z=16, pow=4.0, str=3, rad=6) ## sepia/artistic

fenomeno83
7th October 2017, 18:12
Thanks! Should be useful create the same function but indipendent by resolution..some coefficient to multiply to different params, based on resolution

StainlessS
7th October 2017, 19:16
Small point, but methinks that rad (ie radius) is actually a diameter, and should perhaps always be odd (integer, 3 or more), maybe wrong, any thoughts ?

EDIT: Not strictly necessary, but rad=9 is sort of diameter = 9, rad = (9-1) / 2.0 == rad 4.0 outside of current pixel.
rad=6 is sort of diameter = 6, rad = (6-1) / 2.0 == rad 2.5 outside of current pixel.

EDIT: I would like some comment from anybody on this.

raffriff42
7th October 2017, 21:18
These are my notes (made a long time ago) on NonlinUSM's arguments ## @ z - default 6 (3 = subtle; 16 = massive)
## @ pow - default 1.6 (1.0 = oversharp; 4.0 = mild)
## @ str - default 1.0 (3 = strong; 18 = massive)
## @ rad - default 9 (0.6 = sharpen; 18 = soft)
## @ ldmp - default 0.001 (block overlap? 0.01 = a little smoother?)
##
function NonlinUSM(clip o, float "z", float "pow",
\ float "str", float "rad", float "ldmp")
...
The arguments are a mystery to me, really.

StainlessS
7th October 2017, 21:37
The arguments are a mystery to me, really.

Me too, but I'm trying (hard) to understand.

If you downsize by eg 3, then upsize (to same size) again, I think that you are using a diameter of 3 and a radius of 1 (outside of current pixel), do that seem at all correct to you ?

EDIT: This is screwing with my head. (It seems easy, then I get into a mode where it gets way complicookered)

raffriff42
7th October 2017, 23:38
The code here (https://forum.doom9.org/showthread.php?p=1555234#post1555234)...g = o.bicubicresize(round(o.width()/rad/4)*4,round(o.height()/rad/4)*4)
\ .bicubicresize(o.width(),o.height(),1,0)
...is a "quick and dirty" version of a proper Gaussian blur. Good enough for purpose, but "rad" does not exactly track (for example) Photoshop's Gaussian blur with the same radius.

"Radius" is used inconsistently by different software. It does not have to be even or even integral. Gaussian blur with radius=0.3 is perfectly usable.

https://dsp.stackexchange.com/questions/10057/gaussian-blur-standard-deviation-radius-and-kernel-size
Blur radius explained :rolleyes:

fenomeno83
8th October 2017, 09:55
Small point, but methinks that rad (ie radius) is actually a diameter, and should perhaps always be odd (integer, 3 or more), maybe wrong, any thoughts ?

EDIT: Not strictly necessary, but rad=9 is sort of diameter = 9, rad = (9-1) / 2.0 == rad 4.0 outside of current pixel.
rad=6 is sort of diameter = 6, rad = (6-1) / 2.0 == rad 2.5 outside of current pixel.

EDIT: I would like some comment from anybody on this.

so, in your opinion I could adapt just "rad" params based on resolution, and keep the others params the same, to get a similar result?

for example:
in 15Mp I use
NonlinUSM(z=3, str=0.5, rad=9, pow=1)
for a smaller resolution I could use
NonlinUSM(z=3, str=0.5, rad=4, pow=1)
??

StainlessS
8th October 2017, 10:29
so, in your opinion ...
Not sure that I have an opinion any more :)

Having looked at Raffs link, have decided to throw all maths out of the window, and choose my own model of what its doing.
In the downsize, it is getting the average local luminance, where each out pixel is average of rad*rad input.
On upsize, is merely tweening the downsized pixels, where result is approx local luminance average.
EDIT: In the downsize, rad is actually a Diameter, which is converted to a radius via the upsize 2D tweening.

If pow=1.0, then I think that z makes no difference


Infix="(
x+(
[ ((((abs(x-y)/z)^(1/pow))*z)*str) * (((x-y)^2) / (((x-y)^2)+ldmp)) ] * [(x-y)/(abs((x-y)) + 0.001)]
)
)"

You're just dividing by z, raising to the power of 1.0 (ie do nothing) and then multiplying by z to bring it back to original value.

I dont know what is best 'normalizer' based on image size, but gut feeling is on rad.
Guess that you just have to do a lot of playing with the numbers to see what seems best to you.
EDIT: I dont have a load of images to test ( and dont want any, thanx :) ).

StainlessS
8th October 2017, 11:39
Is this any kind of improvement (added limiter)

Function Sub(clip c,string Tit,Bool "ShowFrameNo",int "first_frame", int "last_frame",string "font",float "size",int "text_color",
\ int "halo_color",int "align",int "spc",float "font_width",float "font_angle",Int "BackColor") {
/*
Stack Overhead Subtitle Text, with optional FrameNumber shown
http://forum.doom9.org/showthread.php?p=1813402#post1813402
Title bar is Round(size+2) pixels hi (default 20).
Dont use align=4,5,6, better use 1,2,3,7,8,or 9.
*/
ShowFrameNo=Default(ShowFrameNo,False) first_frame=Default(first_frame,0) last_frame=Default(last_frame,c.FrameCount-1)
font=default(font,"Ariel") size=Default(size,18.0) text_color=Default(text_color,$00FFFF00)
halo_color=Default(halo_color,$00000000) align=default(align,7) spc=Default(spc,0)
font_width=Default(font_width,0) font_angle=Default(font_angle,0.0) BackColor=Default(BackColor,$00000000)
c.BlankClip(height=round(size+2.0),Color=BackColor)
(ShowFrameNo)
\ ? ScriptClip("""Subtitle(String(current_frame,"%.0f] ")+"""+Chr(34)+Tit+Chr(34)+String(first_frame,",first_frame=%.0f")+
\ String(last_frame,",last_frame=%.0f,font=")+Chr(34)+font+Chr(34)+String(size,",size=%.3f")+String(text_color,",text_color=%.0f")+
\ String(halo_color,",halo_color=%.0f")+String(align,",align=%.0f")+String(spc,",spc=%.0f")+String(font_width,",font_width=%.3f")+
\ String(font_angle,",font_angle=%.3f)"))
\ : Subtitle(Tit,first_frame=first_frame,last_frame=last_frame,font=font,size=size,text_color=text_color,halo_color=halo_color,align=align,
\ spc=spc,font_width=font_width,font_angle=font_angle)
Return StackVertical(c).AudioDubEx(c)
}


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)

rpn="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 + / * +"
mt_lutxy(o,g,rpn,U=2,V=2)

#interleave(o,last) # just for visualisation, you don't want the function to do this

return(last)
}

Z=6.0 POW=1.6 STR=1.0 RAD=9.0 LDMP=0.001

Imagesource("1.jpg",end=0).ConvertToYV12
O=Last
NonlinUSM(z=Z,pow=POW,rad=RAD)
A=Last
Limiter()
S=String(Z," : Z=%.3f") + String(POW," : POW=%.3f") + String(STR," : STR=%.3f") + String(RAD," : RAD=%.3f") + String(LDMP," : LDMP=%.3f")
StackVertical(A.Histogram(mode="levels").Sub("No Limiter"+S),Last.Histogram(mode="levels").Sub("Limiter"+S))

https://s20.postimg.cc/d5grilc71/karate.jpg (https://postimages.cc/)

EDIT: I guess that it would be no improvement converting to RGB from TV levels, although I'm not sure how YUV->RGB limits
where result is illegal RGB.

EDIT: Original (probably not the best image to try it out on)
https://s20.postimg.cc/n43z6eltp/img_0001.jpg (https://postimages.cc/)

StainlessS
8th October 2017, 12:40
# Generate clip with varying args to NonlinUSM().


# Generate clip with varying args to NonlinUSM().

FN="1.jpg"

Imagesource(FN,end=0)
Crop(0,0,Width/4*4,Height/4*4)
MAT="Rec709"
#MAT="PC.709"
ConvertToYV12(Matrix=MAT)

Global ORG=Last
### CONFIG ###
Global Z_START = 3.0 Global Z_STEP = 0.25
Global POW_START= 1.1 Global POW_STEP = 0.1
Global STR_START= 0.5 Global STR_STEP = 0.05
Global RAD_START= 5.0 Global RAD_STEP = 0.5
Global STEPS = 10
Global STACK = True # Stack Vertical (if true)
Global STKLIM = True # STACK LIMITER rather that ORG clip (if also STACK)
### END OF CONFIG ###
FRAMES=Round(Pow(STEPS,4))
HIT = (Height+20)*(STACK?2:1) # Subtitles add 20 to height
DUMMY=Last.BlankClip(Length=FRAMES,Height=HIT,Width=Width+256) # Histogram adds 256 to width
Global ORG=ORG.Loop(FRAMES) # Make it work with Sub(ShowFrameNo=True)

GScript("""
Function Func(clip c) {
c
n = current_frame
#### Can mod for fastest changing variables by changing line order, Below first one(by default Z) is fastest changing (RAD by default slowest).
q = n % STEPS Z = Z_START + q * Z_STEP n = n / STEPS
q = n % STEPS POW = POW_START + q * POW_STEP n = n / STEPS
q = n % STEPS STR = STR_START + q * STR_STEP n = n / STEPS
q = n % STEPS RAD = RAD_START + q * RAD_STEP n = n / STEPS
####
S=RT_String(" : Z=%.3f : POW=%.3f : STR=%.3f : RAD=%.3f",Z,POW,STR,RAD)
A=ORG.NonlinUSM(z=Z,pow=POW,str=STR,rad=RAD)
B=(STACK) ? (STKLIM ?A.Limiter.Histogram(mode="levels").Sub("Limiter"+S):ORG.Histogram(mode="levels").Sub("Original")) : 0
C1 = A.Histogram(mode="levels").Sub(RT_String("No Limiter %s",S),true)
(STACK) ? StackVertical(C1,B) : C1
}
""")

Return DUMMY.ScriptClip("Func()")


Function Sub(clip c,string Tit,Bool "ShowFrameNo",int "first_frame", int "last_frame",string "font",float "size",int "text_color",
\ int "halo_color",int "align",int "spc",float "font_width",float "font_angle",Int "BackColor") {
/*
Stack Overhead Subtitle Text, with optional FrameNumber shown
http://forum.doom9.org/showthread.php?p=1813402#post1813402
Title bar is Round(size+2) pixels hi (default 20).
Dont use align=4,5,6, better use 1,2,3,7,8,or 9.
*/
ShowFrameNo=Default(ShowFrameNo,False) first_frame=Default(first_frame,0) last_frame=Default(last_frame,c.FrameCount-1)
font=default(font,"Ariel") size=Default(size,18.0) text_color=Default(text_color,$00FFFF00)
halo_color=Default(halo_color,$00000000) align=default(align,7) spc=Default(spc,0)
font_width=Default(font_width,0) font_angle=Default(font_angle,0.0) BackColor=Default(BackColor,$00000000)
c.BlankClip(height=round(size+2.0),Color=BackColor)
(ShowFrameNo)
\ ? ScriptClip("""Subtitle(String(current_frame,"%.0f] ")+"""+Chr(34)+Tit+Chr(34)+String(first_frame,",first_frame=%.0f")+
\ String(last_frame,",last_frame=%.0f,font=")+Chr(34)+font+Chr(34)+String(size,",size=%.3f")+String(text_color,",text_color=%.0f")+
\ String(halo_color,",halo_color=%.0f")+String(align,",align=%.0f")+String(spc,",spc=%.0f")+String(font_width,",font_width=%.3f")+
\ String(font_angle,",font_angle=%.3f)"))
\ : Subtitle(Tit,first_frame=first_frame,last_frame=last_frame,font=font,size=size,text_color=text_color,halo_color=halo_color,align=align,
\ spc=spc,font_width=font_width,font_angle=font_angle)
Return StackVertical(c).AudioDubEx(c)
}


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)

rpn="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 + / * +"
mt_lutxy(o,g,rpn,U=2,V=2)

#interleave(o,last) # just for visualisation, you don't want the function to do this

return(last)
}


EDIT: Optional show Stacked Original or Limited (or neither).

raffriff42
8th October 2017, 13:59
Fooling around with random arguments! That's the ticket, when nothing makes any sense!
Hey, remember when we did that with a Bloom filter (https://forum.doom9.org/showthread.php?p=1642591#post1642591)?

StainlessS
8th October 2017, 15:22
Yep, random is my go-to strategy,

while (bump into wall) { spin around to a random direction, forward };

Works every time, hardly ever get stuck in a loop, for long.

Arh, the Bloom Filter, those woz the daze :)

raffriff42
8th October 2017, 16:21
Brilliant strats. EDIT better than mine:while (wall && skull) { bump into wall; }

StainlessS
9th October 2017, 00:01
Just repaired a broken musvid, just for the hell of it put it through NonlinUSM(z=3, pow=1.1, str=0.33, rad=9), and results quite good (lowish qual source),
Verified that pow=1 and z = 3 or z=12 gave identical results.
Raff, multiple examples of usage show pow=1.0, which switches off z effect, so that part of result depends only upon str.

EDIT: Done another short musvid, source 534x360@25, using my pretty much standard encode script (does as below with used settings).
RoboCrop
AutoContrast
MCDegrainSharp(frames=1)
NNedi3_Rpow2(2)
Spline36Resize(720,576)
ReSampleAudio(44100)
Normalize(0.98)
NonlinUSM(z=3, pow=1.1, str=0.33, rad=9) # additional to standard script
Encode(3:2)

Nice improvement, think I'll stick to roughly those NonlinUSM settings, and add to my standard script (default switched OFF).

EDIT: I dont think you will like pow less than 1.0.

fenomeno83
9th October 2017, 17:00
thanks..my approach will be:
NonlinUSM(z=3, pow=1.1, str=0.33, rad=X), where X depends from resolution..
I'll test for example NonlinUSM(z=3, pow=1.1, str=0.33, rad=startingRadius) in 15Mp photos, and check the rad that generates a similar output when I scale for example the same photo to 5Mp
I'll make several scaling (for example 15Mp--> 13,11,9,5,5,3,1 Mp) and assign to each resolution the rad value that generates a photos similar to the 15MP with startiingRadius photo.
So, I can build a function curve that shows relations between resolution and radius

Than I can repeat test using others startingRadius and others photos and understand if previous function curve is applicable

StainlessS
11th October 2017, 03:04
Added a line to previous posted text ie

Having looked at Raffs link, have decided to throw all maths out of the window, and choose my own model of what its doing.
In the downsize, it is getting the average local luminance, where each out pixel is average of rad*rad input.
On upsize, is merely tweening the downsized pixels, where result is approx local luminance average.
EDIT: In the downsize, rad is actually a Diameter, which is converted to a radius via the upsize 2D tweening.



EDIT: Also note, on the downsize uses BiCubicResize with defaults b=1.0/3,c=1.0/3,
and on the upsize, BiCubicResize with b=1.0,c=0.0, ie max blur, min ringing.

g = o.bicubicresize(round(o.width()/rad/4)*4,round(o.height()/rad/4)*4).bicubicresize(o.width(),o.height(),1,0)

minusthebear
3rd May 2022, 03:08
Hey guys, I can't seem to get ContrastMask to work.

This is the error I get:

"There is no function named gaussianblur"

I've installed mvtool2.dll but still no success.

poisondeathray
3rd May 2022, 05:14
Hey guys, I can't seem to get ContrastMask to work.

This is the error I get:

"There is no function named gaussianblur"

I've installed mvtool2.dll but still no success.

GaussianBlur is included in VariableBlur
http://avisynth.nl/index.php/VariableBlur

LigH
3rd May 2022, 07:24
It appears to be part of the VariableBlur (http://avisynth.nl/index.php/VariableBlur) package.

See the end of the second post of this thread:


Requirements:
Variableblur (also requires fftw version 3)
mt_masktools
autolevels