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 9th May 2014, 20:36   #1  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 240
MaskTools2 problem

Hello,
I try to write a script to tune one filter strenght inside differents luma tones. I have no problem with stenght tune, but i have tones mask problem.

I want to work with 8 luma tones or 3 luma tones. Thus, with MaskTools2 MT_lut function, i make 8 or 3 masks.

This little script, with red overlayed color and ColorYuv like filter is a problem's demo. Red overlayed color is here only to have a coloryuv autowhite big action.

Code:
AviSource = ......

LoadPlugin("C:\.....\masktools-v2.0a48\mt_masktools-25.dll")

Overlay(last,BlankClip(last , color=$FF0000), opacity=1.0, mode="chroma") # Overlay function is to hightlight the problem

height_masks =      [<"height masks no (0) - yes (1)", 0, 1, 1>]
height_masks = (height_masks == 0) ? false : true

#---------------------------------------------  height masks ----------------------------------------    

very_dark=MT_Lut("x 32 <= 255 0 ?", y=3, u=1, v=1)
dark=MT_Lut("x 64 <= x 32 > & 255 0 ?", y=3, u=1, v=1)
dark_midtones=MT_Lut("x 96 <= x 64 > & 255 0 ?", y=3, u=1, v=1)
midtones =MT_Lut("x 128 <= x 96 > & 255 0 ?", y=3, u=1, v=1)
light_midtones=MT_Lut("x 160 <= x 128 > & 255 0 ?", y=3, u=1, v=1)
light=MT_Lut("x 192 <= x 160 > & 255 0 ?", y=3, u=1, v=1)
very_light=MT_Lut("x 224 <= x 192 > & 255 0 ?", y=3, u=1, v=1)
hyper_light=MT_Lut("x 224 > 255 0 ?", y=3, u=1, v=1)

#-------------------------------------------------- three masks----------------------------------------

dark_3=MT_Lut("x 64 <= x 255 0 ?", y=3,u=1, v=1)
midtones_3=MT_Lut("x 160 <= x 64 > & 255 0 ?", y=3,u=1, v=1)
light_3=MT_Lut("x 160 > 255 0 ?", y=3,u=1, v=1)

#---------------------------------------------- filter process

filter = coloryuv(autowhite=true)
filter_mod = (height_masks == true) ? Overlay(filter,mask=very_dark, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask=dark, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask=dark_midtones, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask=midtones, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask=light_midtones, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask=light, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask = very_light, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask = hyper_light, opacity=1.0, mode="chroma")
                          \ :
                          \ Overlay(filter, mask=dark_3, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask=midtones_3, opacity=1.0, mode="chroma")
                          \.Overlay(filter, mask=light_3, opacity=1.0, mode="chroma")
                          

StackHorizontal(last.Subtitle("input clip", align=2),filter.coloryuv(analyze=true).Subtitle("Auto White Balance without luma tones", align=2),
\filter_mod.coloryuv(analyze=true).Subtitle("Auto White Balance with luma tones", align=2))
With 3 masks, the filter ouputs with and without masks process are the sames. With 8 masks, the filter output with maks process is a little different from filter output without masks process.
The difference is very small, almost of time only video datas difference not visual difference, but when the filter has a big action, a visual difference appears (picture in attachment).

The problem is on luma tones boundaries, but i do not understand why it is bad with 8 maks and good with 3 masks. Perhaps it is a little bug in Masktools2 or it is calculation limit.
Have somebody an ideas ?

Thanks
Attached Images
 
Bernardd is offline   Reply With Quote
Old 9th May 2014, 21:51   #2  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,420
Quote:
Originally Posted by Bernardd View Post
Code:
dark_3=MT_Lut("x 64 <= x 255 0 ?", y=3,u=1, v=1)
That second x should not be there.
The expression is syntactically incorrect, but I think the effect here is that the mask will be set to 255 except where luma is zero.

That doesn't fully explain your results, but I think it explains why the 3 mask version behaves differently.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 9th May 2014, 22:59   #3  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 240
You have right, my expression is syntactically incorrect. I apologize, i have cut and paste too fast when i have written.
But your observe is good, with this syntactically incorrect expression the result with three or height masks is good, with correct expression the result is bad.
Hard to understand !
Thanks
Bernardd is offline   Reply With Quote
Old 10th May 2014, 08:37   #4  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,420
I think what you are seeing is a result of the way Overlay works internally.
For each Overlay, the inputs are converted to an internal 4:4:4 format (equivalent to YV24), processing is done and the result is converted back to the original format.
By doing your overlay in 3 or 8 stages, you are getting repeated chroma upsampling and downsampling. On downsampling, some of the new gray pixels (previously red) get merged with neighbouring still-red ones leaving red in the final result.

Try using mt_merge() instead of Overlay():
Code:
mt_merge(filter,mask=..., y=2, u=3, v=3, luma=true)
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 10th May 2014, 09:19   #5  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 240
Gavino, your first explanation is good. After night, i modify the incorrect expression like this

very_dark=MT_Lut("x 32 <= & x 0 >= 255 0 ?", y=3, u=1, v=1)
dark_3=MT_Lut("x 64 <= & x 0 >= 255 0 ?", y=3,u=1, v=1)

Now result is good for me. But i shall try Mt_merge.
Thanks
Bernardd is offline   Reply With Quote
Old 10th May 2014, 10:03   #6  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,420
Quote:
Originally Posted by Bernardd View Post
Gavino, your first explanation is good. After night, i modify the incorrect expression like this

very_dark=MT_Lut("x 32 <= & x 0 >= 255 0 ?", y=3, u=1, v=1)
dark_3=MT_Lut("x 64 <= & x 0 >= 255 0 ?", y=3,u=1, v=1)

Now result is good for me.
You have the &'s in the wrong place. It should be
Code:
very_dark=MT_Lut("x 32 <= x 0 >= & 255 0 ?", y=3, u=1, v=1)
dark_3=MT_Lut("x 64 <= x 0 >= & 255 0 ?", y=3,u=1, v=1)
I think again the result will be a mask of 255 for all pixels, making the script appear to work, but it's not really doing what you want.

However, it should not be necessary to put x >= 0 in the condition anyway, since the value is always in the range 0-255.

EDIT: Actually, I had the mt_merge syntax wrong; mask is not a named parameter, so it should be
mt_merge(filter,very_dark, y=2, u=3, v=3, luma=true). etc

However, I just tried it myself and the same problem occurs, with residual red pixels. I think this is because for luma=true it has to downsize the mask to apply it to the chroma, so the mask gets blurred on edges.

I then tried instead converting the input clip to YV24 at the start of the script (now using Overlay again) and this worked, for both 3 and 8 masks. So I think that solves your problem.

(mt_merge is generally better than Overlay, but it does not support luma=true for YV24.)
__________________
GScript and GRunT - complex Avisynth scripting made easier

Last edited by Gavino; 10th May 2014 at 10:52.
Gavino is offline   Reply With Quote
Old 10th May 2014, 14:34   #7  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 240
I appologize for my incorrect expressions which seem to give good result.

I have tried : dark_3= MT_Binarize(threshold = 64, y=3,u=1, v=1, upper = true). Residual red pixels are always.
Bernardd is offline   Reply With Quote
Old 10th May 2014, 15:34   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,420
Quote:
Originally Posted by Bernardd View Post
I have tried : dark_3= MT_Binarize(threshold = 64, y=3,u=1, v=1, upper = true). Residual red pixels are always.
The mask itself is correct, but the problem is the way the masks are used when the source is YV12.

Did you see my edit above?
If you convert your source clip to YV24 at the start, it should work properly.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 10th May 2014, 21:47   #9  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 240
Gavino, well done !

Yes, the script work properly when source clip is converted to YV24. Thus i find difference between mt_masktools-25.dll and mt_masktools-26.dll, working with Avisynth 2.6 i have to update mt_masktools-25.dll in mt_masktools-26.dll.

Convert to YV24 is a more smart issue than incorrect expression use.
Thanks
Bernardd is offline   Reply With Quote
Old 12th May 2014, 23:15   #10  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 240
Gavino,
Thanks, with your answers i have been able to write this function script for adjust strength of one filter in each luma tones.
In end of script, after __End__ i have put his function call script which use Avspmod Users Sliders and Section toogle tags for process with 8 or 3 luma tones masks.
Code:
function Luma_tones_filter_adjust (clip clip, clip "filter", bool "eight_masks", bool "original_vs_filter", bool "compare_mode",
                                                 \ bool "show_tune_help", bool "show_masks", bool "show_datas",
                                                 \ float "strength_very_dark", float "strength_dark",
                                                 \ float "strength_dark_midtones", float "strength_midtones", float "strength_light_midtones", 
                                                 \ float "strength_light", float "strength_very_light", float "strength_hyper_light") 
{

Assert(clip.IsYUV, "Source to be YUV")
ver = VersionNumber()
Assert(ver == 2.6, "Avisynth Version 2.6 need")

clip = ConvertToYV24(clip)
filter = ConvertToYV24(filter)

eight_masks = Default(eight_masks,false) # default three luma tones work only

#---------------------------------------------  Eight masks making ----------------------------------------    

very_dark=MT_Lut(clip,"x 32 <= 255 0 ?", y=3, u=1, v=1)
dark=MT_Lut(clip,"x 64 <= x 32 > & 255 0 ?", y=3, u=1, v=1)
dark_midtones=MT_Lut(clip,"x 96 <= x 64 > & 255 0 ?", y=3, u=1, v=1)
midtones =MT_Lut(clip,"x 128 <= x 96 > & 255 0 ?", y=3, u=1, v=1)
light_midtones=MT_Lut(clip,"x 160 <= x 128 > & 255 0 ?", y=3, u=1, v=1)
light=MT_Lut(clip,"x 192 <= x 160 > & 255 0 ?", y=3, u=1, v=1)
very_light=MT_Lut(clip,"x 224 <= x 192 > & 255 0 ?", y=3, u=1, v=1)
hyper_light=MT_Lut(clip,"x 224 > 255 0 ?", y=3, u=1, v=1)

#-------------------------------------------------- Three masks making----------------------------------------


dark_3=MT_Lut(clip,"x 64 <= 255 0 ?", y=3,u=1, v=1)
midtones_3=MT_Lut(clip,"x 160 <= x 64 > & 255 0 ?", y=3,u=1, v=1)
light_3=MT_Lut(clip,"x 160 > 255 0 ?", y=3,u=1, v=1)


the_masks = (eight_masks == true) ? StackHorizontal(very_dark.Subtitle("very dark tones"), dark.Subtitle("dark tones"), 
         \ dark_midtones.Subtitle("dark midtones"), midtones .Subtitle("midtones"), light_midtones.Subtitle("light midtones"),
         \ light.Subtitle("light tones"), very_light.Subtitle("very light tones"), hyper_light.Subtitle("hyper light tones"))
         \ :
         \ StackHorizontal(dark_3.Subtitle("dark tones"), midtones_3.Subtitle("midtones"), light_3.Subtitle("light tones"))
         
#---------------------------------------------- Filter strength on each luma tones                                                       
                
strength_very_dark = Default(strength_very_dark, 0.0) # filter strength on very dark tones, between 0.0 and 1.0, default 0.0
strength_dark = Default(strength_dark, 0.0) # filter strength on dark tones, between 0.0 and 1.0, default 0.0
strength_dark_midtones = Default(strength_dark_midtones, 0.0) # filter strength on dark midtones, between 0.0 and 1.0, default 0.0
strength_midtones = Default(strength_midtones, 0.0) # filter strength on midtones, between 0.0 and 1.0, default 0.0
strength_light_midtones= Default(strength_light_midtones, 0.0) # filter strength on light midtones, between 0.0 and 1.0, default 0.0
strength_light = Default(strength_light, 0.0) # filter strength on light tones, between 0.0 and 1.0, default 0.0
strength_very_light = Default(strength_very_light, 0.0) # filter strength on very light tones, between 0.0 and 1.0, default 0.0
strength_hyper_light = Default(strength_hyper_light, 0.0) # filter strength on very light tones, between 0.0 and 1.0, default 0.0                                                        
                                                        
filter_very_dark=Overlay(clip,filter, opacity=strength_very_dark, mode="blend")
filter_dark=Overlay(clip,filter, opacity=strength_dark, mode="blend")
filter_dark_midtones=Overlay(clip,filter, opacity=strength_dark_midtones, mode="blend")
filter_midtones=Overlay(clip,filter, opacity=strength_midtones, mode="blend")
filter_light_midtones=Overlay(clip,filter, opacity=strength_light_midtones, mode="blend")
filter_light=Overlay(clip,filter, opacity=strength_light, mode="blend")
filter_very_light=Overlay(clip,filter, opacity=strength_very_light, mode="blend")
filter_hyper_light=Overlay(clip,filter, opacity=strength_hyper_light, mode="blend")

#---------------------------------------------- Tone masks use

filter_mod = (eight_masks == true) ? clip.Overlay(filter_very_dark,mask=very_dark, opacity=1.0, mode="blend")
                          \.Overlay(filter_dark, mask=dark, opacity=1.0, mode="blend")
                          \.Overlay(filter_dark_midtones, mask=dark_midtones, opacity=1.0, mode="blend")
                          \.Overlay(filter_midtones, mask=midtones, opacity=1.0, mode="blend")
                          \.Overlay(filter_light_midtones, mask=light_midtones, opacity=1.0, mode="blend")
                          \.Overlay(filter_light, mask=light, opacity=1.0, mode="blend")
                          \.Overlay(filter_very_light, mask = very_light, opacity=1.0, mode="blend")
                          \.Overlay(filter_hyper_light, mask = hyper_light, opacity=1.0, mode="blend")
                          \ :
                          \ clip.Overlay(filter_dark, mask=dark_3, opacity=1.0, mode="blend")
                          \.Overlay(filter_midtones, mask=midtones_3, opacity=1.0, mode="blend")
                          \.Overlay(filter_light, mask=light_3, opacity=1.0, mode="blend")
                          
#---------------------------------------------- Results

original_vs_filter = Default(original_vs_filter,false) # false filtered output, true original video vs filtered output
compare_mode = Default(compare_mode,false) # false stackhorizontal, true interleave
show_tune_help = Default(show_tune_help,false)
show_masks = Default(show_masks,false)
show_datas  = Default(show_datas,true) # false chroma datas, true luma datas

(original_vs_filter == true) ?
\((show_tune_help == true) ? 
   \ ((show_masks == true) ? the_masks :
    \ (((show_datas == false) ? StackHorizontal(clip.Info_Chroma.Subtitle("original"),filter.Info_Chroma.Subtitle("all in one piece filtered"),filter_mod.Info_Chroma.Subtitle("by tones filtered")) : 
    \ StackHorizontal(clip.Info_Luma.Subtitle("original"),filter.Info_Luma.Subtitle("all in one piece filtered"),filter_mod.Info_Luma.Subtitle("by tones filtered"))))) :
\((compare_mode == false) ? StackHorizontal(clip.Subtitle("stackhorizontal comparison \n original", lsp=20),filter_mod.Subtitle("stackhorizontal comparison \n filtered", lsp=20)) : 
    \                                             Interleave(clip.Subtitle("interleave comparison \n original", lsp=20),filter_mod.Subtitle("interleave comparison \n filtered", lsp=20)))) :
\ filter_mod 

ConvertToYV12()

return last

}

function Info_chroma(clip c)
{
c.ScriptClip("""
    acu = AverageChromaU()
    acv = AverageChromaV()
    Subtitle("127 - moyenne de U = " + String(127-acu),y=20)    
    Subtitle("127 - moyenne de V = " + String(127-acv),y=40)
   
    Subtitle("moyenne de U et V = " + String((acu+acv)/2),y=60)
""")
return last
} 

function Info_luma(clip c)
{
c.ScriptClip("""
    aly = AverageLuma()
    Subtitle("AverageLuma = " + String(aly),y=40)
""")
return last
}

__End__

LoadPlugin("C:\...\masktools-v2.0a48\mt_masktools-26.dll")
ori=last
Import("C:\....\Luma_tones_filter_adjust.avs")

filter = ColorYUv(Autowhite=true) # here, your filter, for example ColorYuv(autowhite = true)

[<separator="Output choice : filtered - original vs fitered comparison - help display">]

original_filter =      [<"Filtered output or original vs filtered comparison", 0, 1, 1>]
mode_compar =    [<"----Stackhorizontal comparison or interleave", 0, 1, 1>]
aide_reglage =      [<"----Show tune help", 0, 1, 1>]
compare_masque=[<"-----------Show maks tones", 0, 1, 0>]
compare_info=      [<"-----------Show chroma or luma datas", 0, 1, 1>]

original_vs_filter = (original_filter == 1) ? true : false
compare_mode = (mode_compar == 1) ? true : false
show_tune_help = (aide_reglage == 1) ? true : false
show_masks = (compare_masque == 1) ? true : false 
show_datas = (compare_info == 1) ? true : false

[<separator="Luma tones tune sliders">]

eight_masks = false

        [eight luma tones process=0]
                eight_masks = true
        [/eight luma tones process]

        [eight luma tones process=0]
                strength_very_dark = [<"filter strength  on very dark tones", 0.0, 1.0, 1.0>] # filter strength on very dark, between 0.0 and 1.0, default 0.0
        [/eight luma tones process]
strength_dark = [<"filter strength on dark tones", 0.0, 1.0, 1.0>] # filter strength on dark, between 0.0 and 1.0, default 0.0
        [eight luma tones process=0]
                strength_dark_midtones = [<"filter strength on dark midtones", 0.0, 1.0, 1.0>] # filter strength on dark midtones, between 0.0 and 1.0, default 0.0
        [/eight luma tones process]
strength_midtones= [<"filter strength on midtones", 0.0, 1.0, 1.0>] # filter strength on midtones, between 0.0 and 1.0, default 0.0
        [eight luma tones process=0]
                strength_light_midtones = [<"filter strength on light midtones", 0.0, 1.0, 1.0>] # filter strength on light midtones, between 0.0 and 1.0, default 0.0
        [/eight luma tones process]
strength_light = [<"filter strength on light  tones", 0.0, 1.0, 1.0>] # filter strength on light, between 0.0 and 1.0, default 0.0
        [eight luma tones process=0]
                strength_very_light = [<"filter strength on very light tones", 0.0, 1.0, 1.0>] # filter strength on very light, between 0.0 and 1.0, default 0.0
                strength_hyper_light = [<"filter strength on hyper light tones", 0.0, 1.0, 1.0>] # filter strength on hyper light, between 0.0 and 1.0, default 0.0
        [/eight luma tones process]

(eight_masks == true) ?   
\ Luma_tones_filter_adjust (filter = filter, eight_masks = eight_masks, original_vs_filter = original_vs_filter, compare_mode = compare_mode,
                                                    \show_tune_help = show_tune_help, show_masks = show_masks, show_datas = show_datas,
                                                    \ strength_very_dark = strength_very_dark, strength_dark = strength_dark,
                                                    \ strength_dark_midtones = strength_dark_midtones, strength_midtones = strength_midtones, strength_light_midtones = strength_light_midtones, 
                                                    \ strength_light = strength_light, strength_very_light = strength_very_light, strength_hyper_light = strength_hyper_light)
\ :                           
\Luma_tones_filter_adjust (filter = filter, original_vs_filter = original_vs_filter, compare_mode = compare_mode,
                                                   \show_tune_help = show_tune_help, show_masks = show_masks, show_datas = show_datas,
                                                    \ strength_dark = strength_dark, strength_midtones = strength_midtones, strength_light = strength_light)
Thanks once again.
Bernardd is offline   Reply With Quote
Old 13th May 2014, 00:56   #11  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
Dear lord, that is quite the mess. Why use thirty lines when three suffice? (Not counting the argument handling, of course.)

Code:
function luma_tones_filter_adjust_eight(clip source, clip filtered, \
                                        float "strength_very_dark", float "strength_dark", \
                                        float "strength_dark_midtones", float "strength_midtones", \
                                        float "strength_light_midtones", float "strength_light", \
                                        float "strength_very_light", float "strength_hyper_light")
{
	s0 = String(Default(strength_very_dark, 0.0))
	s1 = String(Default(strength_dark, 0.0))
	s2 = String(Default(strength_dark_midtones, 0.0))
	s3 = String(Default(strength_midtones, 0.0))
	s4 = String(Default(strength_light_midtones, 0.0))
	s5 = String(Default(strength_light, 0.0))
	s6 = String(Default(strength_very_light, 0.0))
	s7 = String(Default(strength_hyper_light, 0.0))
	band = source.mt_lut("x 32 / floor") # or "x 1 - 32 / floor"
	strengthmask = band.mt_lut("x 0 == " + s0 + \
	                          " x 1 == " + s1 + \
	                          " x 2 == " + s2 + \
	                          " x 3 == " + s3 + \
	                          " x 4 == " + s4 + \
	                          " x 5 == " + s5 + \
	                          " x 6 == " + s6 + \
	                          " " + s7 + " ? ? ? ? ? ? ? 255 *")
	return mt_merge(source, filtered, strengthmask, luma=true)
}

function luma_tones_filter_adjust_three(clip source, clip filtered, \
                                        float "strength_dark", float "strength_midtones", float "strength_light")
{
	return luma_tones_filter_adjust_eight(source, filtered, \
	                                      strength_dark, strength_dark, \
	                                      strength_midtones, strength_midtones, strength_midtones, \
	                                      strength_light, strength_light, strength_light)
}
As a bonus, no colourspace conversion is necessary, it's easier to modify it to add filtering to the strength mask (which is recommended to avoid sudden jumps in filtering strength across, say, a smooth gradient), and it should be much faster.

Last edited by colours; 13th May 2014 at 00:59. Reason: oops, line breaks
colours is offline   Reply With Quote
Old 14th May 2014, 18:39   #12  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 240
Hello Colours,
I am very impressed.
I have appreciated your knowledge :
- use of operaror "floor",
- reverse polish notation for 7 conditionnal rules
- space need around comparisons
- and his end not " x 7 == " but only " "
I have appreciated the smart mask making and application.
Thousand thanks.

I have studied your script and tried to write a RGB correction in YUV with your lesson, but with eight masks is too slow and with three masks is slow.
Do you think it is possible to improve this :
Code:
source=AVISource("C:\.....avi")

LoadPlugin("C:\.......\masktools-v2.0a48\mt_masktools-26.dll")

eight_masks = false
                [eight luma tones process=1]
                eight_masks = true
                [/eight luma tones process]

                [eight luma tones process=1]
                [<separator="Very dark tones sliders">]
                red_or_inv_very_dark = [<"red or invert on very dark tones", 0.0, 1.0, 0.0>]
                red_strength_very_dark = [<"red strength on very dark tones", 0.0, 1.0, 0.0>] # red strength on very dark, between 0.0 and 1.0, default 0.0
                green_or_inv_very_dark = [<"green or invert on very dark tones", 0.0, 1.0, 0.0>]
                green_strength_very_dark = [<"green strength on very dark tones", 0.0, 1.0, 0.0>] # green strength on very dark, between 0.0 and 1.0, default 0.0
                blue_or_inv_very_dark = [<"blue or invert on very dark tones", 0.0, 1.0, 0.0>]
                blue_strength_very_dark = [<"blue strength on very dark tones", 0.0, 1.0, 0.0>] # blue strength on very dark, between 0.0 and 1.0, default 0.0
                [/eight luma tones process]               
[<separator="Dark tones sliders">]
red_or_inv_dark = [<"red or invert on dark tones", 0.0, 1.0, 0.0>]                       
red_strength_dark = [<"red strength on dark tones", 0.0, 1.0, 0.0>] # red strength on dark, between 0.0 and 1.0, default 0.0
green_or_inv_dark = [<"green or invert on dark tones", 0.0, 1.0, 0.0>]                       
green_strength_dark = [<"green strength on dark tones", 0.0, 1.0, 0.0>] # green strength on dark, between 0.0 and 1.0, default 0.0
blue_or_inv_dark = [<"blue or invert on dark tones", 0.0, 1.0, 0.0>]                       
blue_strength_dark = [<"blue strength on dark tones", 0.0, 1.0, 0.0>] # blue strength on dark, between 0.0 and 1.0, default 0.0
                [eight luma tones process=1]
                [<separator="Dark_midtones ton sliders">]
                red_or_inv_dark_midtones = [<"red or invert on dark midtones", 0.0, 1.0, 0.0>]
                red_strength_dark_midtones = [<"red strength on dark midtones", 0.0, 1.0, 0.0>] # red strength on dark midtones, between 0.0 and 1.0, default 0.0
                green_or_inv_dark_midtones = [<"green or invert on dark midtones", 0.0, 1.0, 0.0>]
                green_strength_dark_midtones = [<"green strength on dark midtones", 0.0, 1.0, 0.0>] # green strength on dark midtones, between 0.0 and 1.0, default 0.0
                blue_or_inv_dark_midtones = [<"blue or invert on dark midtones", 0.0, 1.0, 0.0>]
                blue_strength_dark_midtones = [<"blue strength on dark midtones", 0.0, 1.0, 0.0>] # blue strength on dark midtones, between 0.0 and 1.0, default 0.0
                [/eight luma tones process]
[<separator="Midtones sliders">]
red_or_inv_midtones = [<"red or invert on midtones", 0.0, 1.0, 0.0>]                        
red_strength_midtones= [<"red strength on midtones", 0.0, 1.0, 0.0>] # red strength on midtones, between 0.0 and 1.0, default 0.0
green_or_inv_midtones = [<"green or invert on midtones", 0.0, 1.0, 0.0>]                        
green_strength_midtones= [<"green strength on midtones", 0.0, 1.0, 0.0>] # green strength on midtones, between 0.0 and 1.0, default 0.0
blue_or_inv_midtones = [<"blue or invert on midtones", 0.0, 1.0, 0.0>]                        
blue_strength_midtones= [<"blue strength on midtones", 0.0, 1.0, 0.0>] # blue strength on midtones, between 0.0 and 1.0, default 0.0
                [eight luma tones process=1]
                [<separator="light midtones sliders">]
                red_or_inv_light_midtones = [<"red or invert on light midtones", 0.0, 1.0, 0.0>]       
                red_strength_light_midtones = [<"red strength on light midtones", 0.0, 1.0, 0.0>] # red strength on light midtones, between 0.0 and 1.0, default 0.0
                green_or_inv_light_midtones = [<"green or invert on light midtones", 0.0, 1.0, 0.0>]       
                green_strength_light_midtones = [<"green strength on light midtones", 0.0, 1.0, 0.0>] # green strength on light midtones, between 0.0 and 1.0, default 0.0
                blue_or_inv_light_midtones = [<"blue or invert on light midtones", 0.0, 1.0, 0.0>]       
                blue_strength_light_midtones = [<"blue strength on light midtones", 0.0, 1.0, 0.0>] # blue strength on light midtones, between 0.0 and 1.0, default 0.0
                [/eight luma tones process]
[<separator="Light tones sliders">]
red_or_inv_light = [<"red or invert on light tones", 0.0, 1.0, 0.0>]                        
red_strength_light = [<"red strength on light  tones", 0.0, 1.0, 0.0>] # red strength on light, between 0.0 and 1.0, default 0.0
green_or_inv_light = [<"green or invert on light tones", 0.0, 1.0, 0.0>]                        
green_strength_light = [<"green strength on light  tones", 0.0, 1.0, 0.0>] # green strength on light, between 0.0 and 1.0, default 0.0
blue_or_inv_light = [<"blue or invert on light tones", 0.0, 1.0, 0.0>]                        
blue_strength_light = [<"blue strength on light  tones", 0.0, 1.0, 0.0>] # blue strength on light, between 0.0 and 1.0, default 0.0
                [eight luma tones process=1]
                [<separator="Very light tones sliders">]
                red_or_inv_very_light = [<"red or invert on very light tones", 0.0, 1.0, 0.0>]         
                red_strength_very_light = [<"red strength on very light tones", 0.0, 1.0, 0.0>] # red strength on very light, between 0.0 and 1.0, default 0.0
                green_or_inv_very_light = [<"green or invert on very light tones", 0.0, 1.0, 0.0>]         
                green_strength_very_light = [<"green strength on very light tones", 0.0, 1.0, 0.0>] # green strength on very light, between 0.0 and 1.0, default 0.0
                blue_or_inv_very_light = [<"blue or invert on very light tones", 0.0, 1.0, 0.0>]         
                blue_strength_very_light = [<"blue strength on very light tones", 0.0, 1.0, 0.0>] # blue strength on very light, between 0.0 and 1.0, default 0.0
                [<separator="Hyper light tones sliders">]
                red_or_inv_hyper_light = [<"red or invert on hyper light tones", 0.0, 1.0, 0.0>] 
                red_strength_hyper_light = [<"red strength on hyper light tones", 0.0, 1.0, 0.0>] # red strength on hyper light, between 0.0 and 1.0, default 0.0
                green_or_inv_hyper_light = [<"green or invert on hyper light tones", 0.0, 1.0, 0.0>] 
                green_strength_hyper_light = [<"green strength on hyper light tones", 0.0, 1.0, 0.0>] # green strength on hyper light, between 0.0 and 1.0, default 0.0
                blue_or_inv_hyper_light = [<"blue or invert on hyper light tones", 0.0, 1.0, 0.0>] 
                blue_strength_hyper_light = [<"blue strength on hyper light tones", 0.0, 1.0, 0.0>] # blue strength on hyper light, between 0.0 and 1.0, default 0.0
                [/eight luma tones process]

                [eight luma tones process=1]
                RGB_correction_very_dark = RGB_correction(source,
                \ red_or_inv = red_or_inv_very_dark, red_strength = red_strength_very_dark, green_or_inv = green_or_inv_very_dark, green_strength = green_strength_very_dark,
                \ blue_or_inv = blue_or_inv_very_dark, blue_strength = blue_strength_very_dark)
                [/eight luma tones process]
RGB_correction_dark = RGB_correction(source,
\ red_or_inv = red_or_inv_dark, red_strength = red_strength_dark, green_or_inv = green_or_inv_dark, green_strength = green_strength_dark, blue_or_inv = blue_or_inv_dark,
\ blue_strength = blue_strength_dark)
                [eight luma tones process=1]
                RGB_correction_dark_midtones = RGB_correction(source,
                \ red_or_inv = red_or_inv_dark_midtones, red_strength = red_strength_dark_midtones, green_or_inv = green_or_inv_dark_midtones,
                \ green_strength =green_strength_dark_midtones, blue_or_inv = blue_or_inv_dark_midtones, blue_strength = blue_strength_dark_midtones)
                [/eight luma tones process]
RGB_correction_midtones = RGB_correction(source,
\ red_or_inv = red_or_inv_midtones, red_strength = red_strength_midtones, green_or_inv = green_or_inv_midtones, green_strength = green_strength_midtones,
\ blue_or_inv = blue_or_inv_midtones, blue_strength = blue_strength_midtones)
                [eight luma tones process=1]
                RGB_correction_light_midtones = RGB_correction(source,
                \ red_or_inv = red_or_inv_light_midtones, red_strength = red_strength_light_midtones, green_or_inv = green_or_inv_light_midtones,
                \ green_strength = green_strength_light_midtones, blue_or_inv = blue_or_inv_light_midtones, blue_strength = blue_strength_light_midtones)
                [/eight luma tones process]
RGB_correction_light = RGB_correction(source,
\ red_or_inv = red_or_inv_light, red_strength = red_strength_light, green_or_inv = green_or_inv_light, green_strength = green_strength_light, blue_or_inv = blue_or_inv_light,
\ blue_strength = blue_strength_light)
                [eight luma tones process=1]
                RGB_correction_very_light = RGB_correction(source,
                \ red_or_inv = red_or_inv_very_light, red_strength = red_strength_very_light, green_or_inv = green_or_inv_very_light, green_strength = green_strength_very_light,
                \ blue_or_inv = blue_or_inv_very_light, blue_strength = blue_strength_very_light)
                RGB_correction_hyper_light = RGB_correction(source,
                \ red_or_inv = red_or_inv_hyper_light, red_strength = red_strength_hyper_light, green_or_inv = green_or_inv_hyper_light,
                \ green_strength = green_strength_hyper_light, blue_or_inv = blue_or_inv_hyper_light, blue_strength = blue_strength_hyper_light)
                [/eight luma tones process]

(eight_masks == true) ?
\luma_tones_filter_adjust_eight(source, RGB_correction_very_dark, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
\             .luma_tones_filter_adjust_eight( RGB_correction_dark, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
\.luma_tones_filter_adjust_eight( RGB_correction_dark_midtones, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0)
\       .luma_tones_filter_adjust_eight( RGB_correction_midtones, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0)
\.luma_tones_filter_adjust_eight( RGB_correction_light_midtones, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0)
\             .luma_tones_filter_adjust_eight( RGB_correction_light, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0)
\      .luma_tones_filter_adjust_eight( RGB_correction_very_light, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
\     .luma_tones_filter_adjust_eight( RGB_correction_hyper_light, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0)
\ :
\luma_tones_filter_adjust_eight(source, RGB_correction_dark, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
\       .luma_tones_filter_adjust_eight( RGB_correction_midtones, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0)
\             .luma_tones_filter_adjust_eight( RGB_correction_light, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0)

function RGB_correction(clip source,
\ float "red_or_inv", float "red_strength", float "green_or_inv", float "green_strength", float "blue_or_inv", float "blue_strength")

{

red_or_inv = Default(red_or_inv, 0.0)
red_strength = Default(red_strength, 0.0)
green_or_inv = Default(green_or_inv, 0.0)
green_strength = Default(green_strength, 0.0)
blue_or_inv = Default(blue_or_inv, 0.0)
blue_strength = Default(blue_strength, 0.0)

red=BlankClip(source , color=$FF0000)
red_invert = Mt_Invert(red, y = 3,u = 3, v =3)
red_or_inv_s = String(red_or_inv)
red_mask=red.mt_lut(red_or_inv_s +" 255 *",y = 3,u = 3, v =3)
red_adjust = MT_Merge(red,red_invert,red_mask,luma=true)
red_strength_s = String(red_strength)
red_strength_mask=red.mt_lut(red_strength_s +" 255 *",y = 3,u = 3, v =3)

green=BlankClip(source , color=$00FF00)
green_invert = Mt_Invert(green, y = 3,u = 3, v =3)
green_or_inv_s = String(green_or_inv)
green_mask=green.mt_lut(green_or_inv_s +" 255 *",y = 3,u = 3, v =3)
green_adjust = MT_Merge(green,green_invert,green_mask,luma=true)
green_strength_s = String(green_strength)
green_strength_mask=green.mt_lut(green_strength_s +" 255 *",y = 3,u = 3, v =3)

blue=BlankClip(source , color=$0000FF)
blue_invert = Mt_Invert(blue, y = 3,u = 3, v =3)
blue_or_inv_s = String(blue_or_inv)
blue_mask=blue.mt_lut(blue_or_inv_s +" 255 *",y = 3,u = 3, v =3)
blue_adjust = MT_Merge(blue,blue_invert,blue_mask,luma=true)
blue_strength_s = String(blue_strength)
blue_strength_mask=blue.mt_lut(blue_strength_s +" 255 *",y = 3,u = 3, v =3)

return  mt_merge(source, red_adjust, red_strength_mask, luma=true,y = 1,u = 3, v =3).mt_merge(green_adjust, green_strength_mask, luma=true,y = 1,u = 3, v =3)
            \ .mt_merge(blue_adjust, blue_strength_mask, luma=true,y = 1,u = 3, v =3)
}


function luma_tones_filter_adjust_eight(clip source, clip "filtered", \
                                        float "strength_very_dark", float "strength_dark", \
                                        float "strength_dark_midtones", float "strength_midtones", \
                                        float "strength_light_midtones", float "strength_light", \
                                        float "strength_very_light", float "strength_hyper_light")
{
	s0 = String(Default(strength_very_dark, 0.0))
	s1 = String(Default(strength_dark, 0.0))
	s2 = String(Default(strength_dark_midtones, 0.0))
	s3 = String(Default(strength_midtones, 0.0))
	s4 = String(Default(strength_light_midtones, 0.0))
	s5 = String(Default(strength_light, 0.0))
	s6 = String(Default(strength_very_light, 0.0))
	s7 = String(Default(strength_hyper_light, 0.0))
	band = source.mt_lut("x 32 / floor") # or "x 1 - 32 / floor"
	strengthmask = band.mt_lut("x 0 == " + s0 + \
	                          " x 1 == " + s1 + \
	                          " x 2 == " + s2 + \
	                          " x 3 == " + s3 + \
	                          " x 4 == " + s4 + \
	                          " x 5 == " + s5 + \
	                          " x 6 == " + s6 + \
	                          " " + s7 + " ? ? ? ? ? ? ? 255 *")
	return mt_merge(source, filtered, strengthmask, luma=true)
}
Thanks

Last edited by Bernardd; 14th May 2014 at 18:41.
Bernardd is offline   Reply With Quote
Old 14th May 2014, 20:56   #13  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
I'm not entirely sure what you're trying to accomplish with your script, to be honest.

If you want RGB processing, just convert to RGB first, separate the colour channels into three clips, process them however you like, merge them back (MergeRGB), and convert back to YV12.

Code:
source
ConvertToRGB32(matrix="rec601") # replace with the correct colour matrix if your source has a different one
red = ShowRed("y8")
green = ShowGreen("y8")
blue = ShowBlue("y8")
red_processed = filter(red, ...)
green_processed = filter(green, ...)
blue_processed = filter(blue, ...)
MergeRGB(red_processed, green_processed, blue_processed)
ConvertToYV12(matrix="rec601") # use the same matrix as earlier
colours is offline   Reply With Quote
Old 14th May 2014, 23:22   #14  |  Link
Bernardd
Registered User
 
Join Date: Jan 2012
Location: Toulon France
Posts: 240
I hate manual color corrections with his lot of tuning datas like RGBAdjust or with no eyes sense for me like U and V datas in ColorYUV.
When i look a picture, i can easy say to me, there are too red, too green, too blue, i must put invert red, invert green, invert blue.
Thus i want write a script to overlay some of percentage of red or invert red (or and green and blue). But the differents scripts, that i have written
are slow, very slow.

Your little script with a filter like ColorYUV and action on "off_y" and or "gamma_y" process like i search.

Thanks
Bernardd 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 17:55.


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