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. |
|
|
#1 | Link |
|
Movie buff & shine
Join Date: Jan 2004
Location: Logan, the only hole above ground.
Posts: 257
|
New!! - Bleach Bypass filter
Inspired by my attempts to create a glow/bloom filter, and stumbling upon a tutorial about imitating a bleach bypass in AfterEffects, I decided to take a shot at creating the filter in AVISynth...
Previews can be found here.... http://actionman133.isa-geek.net/.../bleachbypass.html I should give credit Didée for writing FastGaussBlur (), which is used to provide a mask for some subtle blooming.... The settings are as follows: BleachBypass (clip, output, preview) output determines which image comes out. 0 returns the source image 1 returns the draft bleach bypass, no bloom applied 2 returns the full bypass, with blooming incorporated (default) preview will compare the original frame to the filtered frame. 0 returns the fully filtered frame (default) 1 returns half the image as the source, the other half as filtered. 2 presents all the used images for debugging purposes
__________________
I'm a boxer who can Bob () & Weave (). I like to Overlay () punches and Blur () his vision to ShowFiveVersions (). My KO punch will always Pulldown ().TimeStretch () and all he will hear is Tone (). |
|
|
|
|
|
#2 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
An old post I know, but anyone know where I might find this 'Bleach Bypass' filter (the above link is dead) ?
I'm not so much interested in the bloom/glow aspect, more in acheiving that 'dramatic-earthy-almost metallic/pewter' type effect.
__________________
Nostalgia's not what it used to be Last edited by WorBry; 24th March 2010 at 15:22. |
|
|
|
|
|
#3 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
OK, no takers, and I see Actionman133 hasnt been around the forum for a while.
So I'm putting together a method based on bits and pieces from the 'film-look' thread (I know, film-look....yawn, ho-hum) and various After Effects/PS/Gimp recipes. I'm want to process entirely in YV12 and found this (MaskTools based) YV12Overlay function in the 'film look' thread, which in part meets my needs: http://forum.doom9.org/showthread.ph...432#post641432 Adapted it like so: Code:
function yv12overlay(clip a,clip b,float "luma_opacity", float "chroma_desat")
{
yExpr="x "+string(luma_opacity)+" * y 1 "+string(luma_opacity)+" - * +"
uvExpr="x "+string(chroma_desat)+" * y 1 "+string(chroma_desat)+" - * +"
return mt_lutxy(a,b,yexpr=yExpr, uexpr=uvExpr, vexpr=uvExpr, Y=3, U=3, V=3)
}
Clip a = original source clip (Pal DV 25p progressive anamorphic) Clip b = greyscale of source clip to which has been applied a 'filmic' S-curve (luma only), using the Levels > Curve function in FFDShow (encoded HuffYuv-YV12). In this way I can vary both the degree of contrast modulation (introduced by the overlayed luma S-curve) and chroma desaturation. I know there are other things to consider, like simulated film-grain, glow, tint (maybe) etc, which I might look at later, but as a basic method I'm quite pleased with the results. This said, several of the AE/PS/Gimp recipes that I've come across recommend using a 'multiply' mode for merging the layered clips/images, which really gives a better representation of the contrast 'look' I am after. I can do this in AVISynth using the (internal core) Layer filter, but that means converting to YUY2. I'm sure the same can be done in YV12 with Masktools. Could anyone advise how I might modify the mt_Lutxy expressions in above YV12Overlay to acheive this, or else suggest an alternative....maybe mt_merge with an appropriate mask? Many thanks.
__________________
Nostalgia's not what it used to be Last edited by WorBry; 28th March 2010 at 05:10. |
|
|
|
|
|
#4 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
If anyone is interested
, actually now that I've examined the 'multiply' blending approach (using Layer filter in YUY2) with a wider range of clips, I realize that it's best suited for well and evenly exposed shots (outdoors on sunny days etc), that in, any case, could benefit from some darkening. For indoor and other unevenly lit shots, I find it over-darkens and loses detail in shadows rather too much. Maybe for digitized film images and professional-level digital camcorders and still cameras with a wide dynamic range, its a different story. But generally, with my consumer level DV camcorder (Panasonic GS400) I find that I can get more acceptable results by adjusting the overlayed luma S-curve at the lower end. So, I'll stick with my existing YV12Overlay method for now. This said, it would be nice to have a YV12 overlay function that incorporates the various layer blending modes (merge operations) commonly found in imaging software. The AVSynth core Overlay filter can do all of them, and Layer has some. Again, I'm sure all of this is possible in YV12 with Mask Tools. I'd have a go at putting one together myself if someone could help with the respective mt_lut expression calcs. Nuff said. One other thing, I've based my workflow on the assumption that the Levels>Curves function in FFDShow can work with YV12 without changing the color format - is this so, or does it convert to RGB and back?
__________________
Nostalgia's not what it used to be Last edited by WorBry; 29th March 2010 at 03:50. |
|
|
|
|
|
#5 | Link |
|
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,406
|
Oh well, the frame contrast issue, once more ...
A maybe-interesting reading reading as of recent: this thread, with emphasisis on this post. For what it's worth, here's three simple MaskTools functions: Multiply, inverse Multiply, and "128-centered Contrast Multiply" Code:
function mt_layer_mul(clip c1, clip c2)
{ mt_lutxy(c1,c2,"x y * 255 /",U=2,V=2) }
function mt_layer_invmul(clip c1, clip c2)
{ mt_lutxy(c1,c2,"256 256 x - 256 y - * 256 / -",U=2,V=2) }
function mt_layer_centermul(clip c1, clip c2)
{ mt_lutxy(c1,c2,"y 128 < x y * 128 / y 128 > 256 256 x - 128 y 128 - - abs * 128 / - x ? ?",U=2,V=2) }
__________________
- We´re at the beginning of the end of mankind´s childhood - My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!) |
|
|
|
|
|
#6 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
Thanks Obi-Wan. "Much to learn, I still have"
So, would I be right in concluding that the Inverse Multiply function corresponds to, what is commonly referred to as 'screen' mode blending in AE/PS and the like? And is the '128-centred-multiply' function essentially the same as 'overlay' mode, where 'multiply' is applied to values <128 and 'screen' to values >128 (cant get my head around the reverse polish syntax for the calc) ? If not, what would that mt_lutxy expression be? Why 255 for the 'multiply' but 256 for the other two? Edit: Tried 'overlay' blend mode in Gimp 2 with a frame grab. Rather different result to '128-centred multiply' - darkened shadows, lightened highlights. Actually, with lightly reduced opacity it gives a quite decent 'bleach by-pass' effect (at least in terms of what I am looking for), without resorting to pre/post curve adjustment. Makes sense, since it effectively amounts to an S-curve.
__________________
Nostalgia's not what it used to be Last edited by WorBry; 29th March 2010 at 19:47. |
|
|
|
|
|
#7 | Link | ||||
|
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,406
|
Quote:
Quote:
Quote:
Quote:
__________________
- We´re at the beginning of the end of mankind´s childhood - My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!) |
||||
|
|
|
|
|
#8 | Link | |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
Quote:
Thanks.
__________________
Nostalgia's not what it used to be Last edited by WorBry; 29th March 2010 at 20:40. |
|
|
|
|
|
|
#9 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
@Didee,
I've been experimenting with a few other 'blend modes'. 'Hardlight', as I understand, is simply a reversal (with respect to layers) of '128-centred multiply' (aka "Overlay"): Code:
function mt_layer_hardlight(clip c1, clip c2) # commuted 128_Centred Multiply
{ return mt_lutxy(c1,c2,"x 128 < y x * 128 / x 128 > 256 256 y - 128 x 128 - - abs * 128 / - y ? ?",U=2,V=2) }
"Soft light" appears to be a milder form of "Overlay", but I'm struggling to find a suitable formula, or at least one that easily translates to reverse polish. Furthermore, the various imaging suites appear to approach 'soft light' in different ways. For example, I found this set of blend formulae for Photoshop: http://www.nathanm.com/photoshop-blending-math/ But an attempt to translate 'Soft Light' formula using mt_polish gave just " y 128 < 2 x", which is clearly nonsense. Any chance you could help me out (again) with a suitable mt_lutxy expression ? ![]() Edit: Came across this earlier post of yours on 'Hardlight': http://forum.doom9.org/showthread.ph...132#post703132 Well that kinda blows my notion of 'Hard Light' being a simple layer reversal of 'Overlay' out of the water. BTW - in those 4 YV12Hardlight variants what is function of the 3-tiered (HL1) lut expressions? Is it to create an internal gradation of the effect, maybe to avoid discontinuance?
__________________
Nostalgia's not what it used to be Last edited by WorBry; 6th April 2010 at 18:42. |
|
|
|
|
|
#10 | Link | |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
Quote:
Adding opacity to the Multiply and Inverse Multiply (Screen) expressions is straightforward enough, but the 128-centred Multiply (Overlay) has me befuddled. I reckon it should be: Code:
clp = last Opac=1.0 #(0.0 - 1.0) OL = " y 128 < x y 128 / "+String(Opac)+" * x 1 "+String(Opac)+" - * + " OL = OL + " y 128 > 256 256 x - 128 y 128 - - abs * 128 / - "+String(Opac)+" * x 1 "+String(Opac)+" - * + " OL = OL + "x ? ?" Return mt_lutxy(clp,clp, OL, U=2,V=2) I could resort to: Code:
Clp=last Opac=1.0 # (0.0 - 1.0) Over=mt_lutxy(Clp,Clp, "y 128 < x y * 128 / y 128 > 256 256 x - 128 y 128 - - abs * 128 / - x ? ?",U=2,V=2) Expr = "y "+string(Opac)+" * x 1 "+string(Opac)+" - * +" return mt_lutxy(Clp ,Over, Expr, U=2, V=2)
__________________
Nostalgia's not what it used to be |
|
|
|
|
|
|
#11 | Link | ||
|
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,442
|
Quote:
Code:
OL = " y 128 < x y * 128 / "+String(Opac)+" * x 1 "+String(Opac)+" - * + " Quote:
|
||
|
|
|
|
|
#12 | Link | |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
Quote:
![]() Needless to say, thanks. I'm working on routines for simulating 'film-looks', 'bleach-bypass' being one, and avoiding, as far as possible color space conversions and multi-stage layering (hence the SelSah 'selective saturation/hue' function that you helped me on).
__________________
Nostalgia's not what it used to be Last edited by WorBry; 21st April 2010 at 18:17. |
|
|
|
|
|
|
#13 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
Just realized, another benefit of including opacity in the Overlay mt_lutxy expression is that allows opacity to be separately adjusted for luma values below and above 128, whilst keeping the curve 128-centred. As a result, it is possible to alter the shape of the S-curve so that the effect is applied more strongly in the lighter areas than the darker areas, and visa-versa. That is very useful.
Check this: Code:
colorbars().converttoyv12().mt_lutspa(relative=true,expr="x 255 *").greyscale()
clp=last
Opac1 = 1.0 # 0.0 - 1.00 Opacity (and so magnitude) of Overlay curve < 128
Opac2 = 1.0 # 0.0 - 1.00 Opacity (and so magnitude) of Overlay curve > 128
OL = " y 128 < x y * 128 / "+String(Opac1)+" * x 1 "+String(Opac1)+" - * + "
OL = OL + " y 128 > 256 256 x - 128 y 128 - - abs * 128 / - "+String(Opac2)+" * x 1 "+String(Opac2)+" - * + "
OL = OL + "x ? ?"
Over = mt_lutxy(clp,clp, OL, U=2,V=2)
clps = clp.Subtitle("Original").LanczosResize(640,360)
Overs = Over.Subtitle("Overlay (128-Centred Contrast Multiply)").LanczosResize(640,360)
StackVertical(clps,Overs)
__________________
Nostalgia's not what it used to be Last edited by WorBry; 22nd April 2010 at 20:39. |
|
|
|
|
|
#14 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
Didee,
Sorry to pester you again, but you really are the one to consult on such matters. Your mt_lutxy computation for ‘128-Centred Contrast Multiply’ is somewhat aligned with the Photoshop formula for ‘Overlay’, except that the Photoshop model is not truly 128-centred. Both respect the top clip (c2) as the reference for deciding whether to ‘multiply’ (y <128 ) or ‘screen’ (y > 128). In this case, ‘Hardlight’, as per the Photoshop formula, should just be a simple question of swapping x and y in the ‘128-Centred Contrast Multiply’ computation , or else, swapping the clips themselves (which is effectively what Photoshop does with the layer channels) i.e. Code:
#function mt_layer_hardlight(clip c1, clip c2) # commuted 128-Centred Contrast Multiply (Hardlight)
#{ return mt_lutxy(c2,c1,"y 128 < x y * 128 / y 128 > 256 256 x - 128 y 128 - - abs * 128 / - x ? ?",U=2,V=2) }
Code:
#function mt_layer_hardlight1(clip c1, clip c2) # based on Didee’s Hardlight-1
#{ return mt_lutxy(c1,c2,"y 128 < x x 128 / 128 y – abs * - x 255 x – 128 / 128 y – abs * + ?",U=2,V=2) }
http://www.pegtop.net/delphi/article.../hardlight.htm In fact, they propose that the terms Overlay and Hardlight, as they are applied in Photoshop, should be swapped to be more logical. Which I guess means respecting the terms as they apply to their photographic applications. Yet this is from a widely-webbed explanation of Photoshop blendmodes: "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 mixed with the blend color to reflect the lightness or darkness of the original color". "Hard Light multiplies or screens the colors, depending on the blend color. The effect is similar to shining a harsh spotlight on the image. If the blend color (light source) is lighter than 50% gray, the image is lightened, as if it were screened. This is useful for adding highlights to an image. If the blend color is darker than 50% gray, the image is darkened, as if it were multiplied. This is useful for adding shadows to an image. Pure black or white results in pure black or white." Again Overlay, by this definition, seems to respect the base layer (Clp c1) and HardLight the blend layer (Clp c2). Confusing. Of course, if the clips are identical, it really shouldn’t make any difference. Even so, really would value your opinion on this. In essence, if '128-centred Contrast Multiply' is tantamount to 'Overlay', what then is 128-centred Hardlight, or visa versa? Cheers. Edit: Aha, so these are the Photoshop formulae from the horses mouth: http://www.adobe.com/devnet/pdf/pdfs/blend_modes.pdf Quote: HardLight: Multiplies or screens the colors, depending on the source color (Cs) value. The effect is similar to shining a harsh spotlight on the backdrop (Cb). B(Cb, Cs) = Multiply(Cb, 2 × Cs) if Cs ≤ 0.5 Screen (Cb, 2 x Cs -1) if Cs > 0.5 Overlay: Multiplies or screens the colors, depending on the backdrop color value. Source colors overlay the backdrop while preserving its highlights and shadows. The backdrop color is not replaced but is mixed with the source color to reflect the lightness or darkness of the backdrop. B(Cb, Cs) = HardLight(Cs, Cb) Where (as I interpret it) Cb = "Backdrop color", is equivalent to the 'base' layer (= Clp c1) Cs = "Source color", is equivalent to the top (blend) layer (= Clp c2) So, again this indicates that Hardlight respects the top clip values in deciding to Multiply (y <= 128) or Screen (y > 128), and that Overlay (being a layer reversal of Hardlight) respects the base clip (x) values. On that basis, this interpretation of the Photoshop formulae, which I took to be de facto, is not actually the case: http://www.nathanm.com/photoshop-blending-math/ Your "Contrast Multiply'" formula has the advantage of being 128 anchored, so avoiding potential 'luma to chroma' spill, but I'm still left wondering whether it should respect the c1 (x) values, rather the c2 (y) values, to be 'Overlay', in the Photoshop 'sense'. I know there is the view that just because Adobe say 'this is the way it is' doesn't necessarily make it 'correct'. I'm just trying to find some consistency in the terminology as it applies to the desired/implied result. Why, one might say, if it does the job ("A Rose by any other name...etc")? Because in seeking to replicate effects based on Photoshop/AE recipes, it is important to be clear what a particular action does.
__________________
Nostalgia's not what it used to be Last edited by WorBry; 30th April 2010 at 17:04. |
|
|
|
|
|
#15 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
Just did some tests with overlayed greyscale gradient patterns.
The '128-Centred Contrast Multiply' and "HardLight1" functions give indistinguishable patterns. The reasonable conclusion is that the former is actually a '128-Centred Hardlight', not Overlay, as such.
__________________
Nostalgia's not what it used to be |
|
|
|
|
|
#16 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
I know my ramblings on this out-of-vogue topic are about as exciting as Stephen Hawkings belated caution about the dangers of contacting extra-terrestrial life forms.
And I know that anyone stumbling upon this thread will likely be disappointed, as I was, that there is actually no ‘Bleach Bypass’ script to be found. I will be posting my offering shortly. Just tweaking the motion-compensated, super-resolution part . In fact, my intent is to transmit it into deep outer space with the hope that any marauding nomads are turned back shrieking “Oh, no....Movie 300....way too much contrast’ Meanwhile, if there are any AVI-Synthesizing life forms tuned in, perhaps one might explain; on switching the Multiply and Inverse Multiply (Screen) functions to chroma mode (u=v=3), I wasn’t too surprised get a chroma shifted image; (minus shift) green-cast with Multiply and a (positive shift) mauve-cast with Screen (probably normal images for the average alien). What surprised me though is that the ‘128-Centred Contrast Multiply’ function does appear produce a valid image in which color saturation is somewhat increased or decreased in parallel with the luma contrast. I suspect that has something to do with the fact that zero in YUV chroma scaling is 128 and that 128-CCM applies separate equations for y < and > 128.....'suspect' of course meaning that I havent got a clue. I wonder if is possible though to modify the Multiply and Screen functions so that they produce a valid chroma result...obviously without recourse to RGB ? Edit: Forget the second part of that question. It wouldnt be of much value anyway. I'm just interested in understanding why 128-CCM actually gives a valid 'chroma mode' result when Multiply and Screen dont. Edit2: Actually, now I've looked at the Histogram levels, it appears that what looked like a 'saturation' effect, is actually a broadening of the U and V profiles, so it's really more of a 'hue' effect, which figures because the multiply component will move some U and V values more into the negative and the screen component will move other values more into the positive, creating a balanced but broader mix of hues. That explains it. Quite an interesting effect, bordering almost on technicolor.
__________________
Nostalgia's not what it used to be Last edited by WorBry; 3rd May 2010 at 05:48. |
|
|
|
|
|
#17 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
OK, here’s my offering. Not exactly ‘Movie 300’, but more or less the ‘look’ I was aiming for. For my taste, I’d probably drop the pre-blur and post-sharpen. All processing is in YV12.
Code:
'Bleach Bypass' (Silver Retention)-like script clpo = last # Assumes source is progressive/deinterlaced. # Apply light Gauss blur to luma (maybe...me prefer not). Clp2 = clpo.BinomialBlur(vary=2) # From tsp's VariableBlur filter # Apply contrast S-curve to luma; slight bias to 'mid-to-highlights': Blend_MT_alpha(Clpo, clp2=clp2, BLMode="Overlay", Opac1=0.7, Opac2=0.8) # Desaturate (50%, across the scale in this case); shift hue a tad to reduce impact of tint on bright reds (see sample below) SelSah_V2(0.5, -10, clp2=clpo) # Apply tint (Sienna or whatever) favouring mid-tones. Stint_v1($8E6B23, 0.35, 140, 180, 0, 210, clp2=clpo) # And/or apply copperish tint to edges - gives metals 'antique' look (like Knights armour in below sample) #Stint_v1($B87333, 0.3, EdgeM=true) # Sharpen to taste (maybe....me prefer not) LSFMod(smode=3,strength=90) # Add Grain to taste..if you want. I know there's a GrainFactory_MT2 version. GrainFactory3(g1str=2,g2str=3,g3str=5) # Brighten if necssary (Maybe should incorporate in Blend_MT). Ylevels(Gamma=1.05) # Voila!! "Beach Bus-Pass"-like. http://forum.doom9.org/showthread.php?t=108814 As for the Blend_MT_alpha, SelSah_v2 and Stint_v1 functions. Here they be: Blend_MT_alpha (....very alpha, but it does the job). Edit: Use Blend_MT_Alpha3 now: http://forum.doom9.org/showpost.php?...4&postcount=42 Code:
function Blend_MT_alpha(clip clp1 ,clip "clp2", string "BLMode", int "LMode", int "CMode", float "Opac", float "Opac1", float "Opac2",
\ bool "BL2", string "BLMode2", float "SOpac", float "SOpac1", float "SOpac2", bool "Preview", bool "GSGrad")
{
# Assembled by WorBry. Thanks to Didee for the Multiply, Screen and '128-Centred Contrast Multiply' computations.
# DESCRIPTION:
# Blend_MT aims to emulate a number of the blend modes available in commercial imaging software (After Effects etc). Whilst
# the existing core filters, Layer and Overlay, incorporate some of these modes, both require color space conversion to process
# YV12 sources; Overlay accepts YV12 input, but internally converts to YUV 4:4:4 for processing. Blend_MT uses MaskTools v2
# only and so allows processing exclusively in YV12. The function was created as one of set of routines to assist in the
# simulation of certain "filmic looks", but perhaps has general application.
# Requires YV12 input, assumes full (pc) range 0-255 and assumes that the source is progressive (native or deinterlaced).
# Requires MaskTools v2 only.
# PARAMETER DEFINITIONS:
#
#Clp1 - Input clip that serves as the lower (base) clip in the specified blend operation.
#Clp2 - Input clip that serves as the upper (overlay) clip in the specified blend operation. If not defined, clp2
# defaults to clp1
#BLMode - The specific blend operation that will be applied to the clips. At default, the operation is applied to the
# luma plane only; chroma is retaind from Clp1. The currently available modes are:
# Blend - Simple merge operation. Note that several other so-called 'blend modes' may be acheived simply by modulating
# the LMode, CMode and Opacity settings (see below). Thus:
# 'Luminosity' mode retains the luma from clp2 and chroma from clp1. Blend mode, at default settings (LMode=3,
# Cmode=2, Opacity = 1.0), or otherwise LMode=4 and CMode=2, correspond to this.
# 'Chroma' or 'Color' mode retains the luma from clp1 and the chroma from clp2. LMode=2 and CMode=3 at full
# opacity (1.0), or LMode=2 and CMode=4, correspond to this.
# 'Average' mode is equivalent to 0.5 (50%) opacity.
#
# Multiply - Multiplies the corresponding pixel values of the two input clips and divides the result by 255. The outcome
# is always a darker composite image. If the input clips are identical, the transformation corresponds to an
# exponential curve.
#
# Screen - Has the opposite effect to Multiply. It multiples the inverted (complement) values. The outcome is always
# a lighter composite image.
#
# Hardlight - (128-Centred Contrast Multiply) Multiplies or screens the pixel values, depending on top clip (Clp2) values.
# The effect is likened to shining a harsh spotlight (as if Clp2) on the image (Clp1), hence the name. For Clp2
# values > 128 (50% grey) the image is screened, and so lightened; useful for adding highlights. For Clp2
# values < 128, the image is multiplied,and so darkened; useful for adding shadows. Pure black or white results
# in pure black or white. The computation differs from that used in After Effects and Photoshop, in that it is
# 128-centred; this avoids luma overflow. If Clp2 and Clp1 have identical pixel values, the result corresponds
# to a symetrical S-curve. This is useful for creating high contrast images characteristic of certain 'film looks'.
#
# Overlay - (128-Centred Contrast Multiply commuted). Multiplies or screens the pixel values, depending on the base clip
# values. For Clp1 pixel values > 128 the image is screened and for Clp1 values < 128 the image is multiplied.
# In this way patterns overlay the existing pixels while preserving the highlights and shadows of the base clip.
# The formulation, like Hardlight, is 128-centered. It follows that if Clp1 and Clp2 have identical pixel values,
# Overlay and Hardlight will produce the same result.
# Reflect - Gives the appearance of adding shiny objects. See the Greyscale gradient curve (GSGrad below) to see why. Use
# with caution and always wear sun glasses. Reduced opacity is recommended.
# Glow - The opposite of Reflect, but the same cautions apply.
#
# SoftLight - N/A YET-STILL WORKING ON A SUITABLE FORMULA. Darkens or lightens the colors, depending on top (Clp2) values.
# The effect is likened to shining a diffused spotlight (as if Clp2) on the image (Clp1). For clp2 values >128,
# the image is lightened as if it were 'dodged'. For Clp2 values <128 the image is darkened as if it were 'burned-in'.
# Pure black or white results in distinctly darker or lighter area but does not result in pure black or white.
#
# Darken - Takes the darkest pixel value from either clip. If the input clips have identical values, there is no change.
#
# Lighten - Takes the lightest pixel value from either clip. If the input clips have identical values, there is no change.
#
#LMode - Determines whether the luma plane (Y) will be processed by the blend operation (3) or retained from Clp1 (2)
# or Clp2 (4). Default is LMode=3.
#CMode - (2,3,4 or 0). Determines whether the chroma planes (U,V) will be processed by the blend operation (3), retained
# from Clp1 (2) retained Clp2 (4), or excluded i.e. greyscale (0). Note, aside from 'Blend' mode, Cmode=3 has
# limited application since the transformations result marked U and V shifts with undesirable color casts.
# However, when applied to the 'contrast' modes (HardLight, Overlay), with identical source clips, CMode=3 may
# produce an acceptable image in which the U and V profiles are broadened to create a richer mix of like hues.
# Depending on the source, this can take on a 'technicolor' film like appearance.
#BL2 - True/False. Whilst the strength of the BLMode operation can be somewhat regulated by opacity adjustment, it may
# be desirable to apply a second blend operation to the first. True, activates this option. Default is, False.
#BL2Mode - Selects the second blend mode operation. All of the blend modes available in BLMode are available in BL2Mode.
# The BLMode2 operation is applied with Clp1 as the base clp and the product of the first BLMode operation as the
# top clip. For simplicity, the LMode and CMode settings are kept the same as for BLMode.
#Opac - Sets the opacity of the BLMode product relative to Clp1. Range 0.0 - 1.0. At 1.0 (default) all of the blend
# product is represented.
#Opac1, Opac2 - Apply only to Overlay and HardLight. Opac1 sets the opacity of the BLMode product for Clp2 pixel values <128
# and Opac2 sets the opacity for Clp2 values >128. This makes it possible to alter, in some way, the vertical
# symetry of the S-curve. Range 0.0 - 1.0. If not separately defined, defaults to Opac value.
#SOpac - Sets the opacity of the BLMode2 product relative to Clp1. Range 0.0 - 1.0. At 1.0 (default) all of the blend
# product is represented.
#SOpac1, SOpac2- Apply to Hardlight and Overlay, SOpac1 sets the opacity of the BLMode2 product for BLMode pixel values <128
# and SOpac2 sets the opacity for Clp2 values >128. In this way it is possible to further manipulate the shape of
# the final curve. Range 0.0 - 1.0. If not separately defined, default to SOpac value.
#Preview - True/False. True gives a composite view of the input clips and final output. Default is False.
#GSGrad - True/False. True demonstrates the effect of the blend operation as applied to a greyscale gradient; histogram
# reveals the luma curve. Default is False.
#
#Defaults:
#clp2 = default(clp2, clp1)
BLMode = default(BLMode, "Blend")
LMode = default(LMode, 3)
CMode = default(Cmode, 2 )
Opac = default(Opac, 1.0)
Opac1 = default(Opac1, Opac)
Opac2 = default(Opac2, Opac)
BL2 = default(BL2, False)
BLMode2 = default(BLMode2, "Blend")
SOpac = default(SOpac, 1.0)
SOpac1 = default(SOpac1, SOpac)
SOpac2 = default(SOpac2, SOpac)
Preview = default(Preview, False)
GSGrad = default(GSGrad, False)
#
#Limits:
Opac = Opac <0.0 ? 0.0 : Opac >1.0 ? 1.0 : Opac
Opac1 = Opac1 <0.0 ? 0.0 : Opac1 >1.0 ? 1.0 : Opac1
Opac2 = Opac2 <0.0 ? 0.0 : Opac2 >1.0 ? 1.0 : Opac2
SOpac = SOpac <0.0 ? 0.0 : SOpac >1.0 ? 1.0 : SOpac
SOpac1 = SOpac1 <0.0 ? 0.0 : SOpac1 >1.0 ? 1.0 : SOpac1
SOpac2 = SOpac2 <0.0 ? 0.0 : SOpac2 >1.0 ? 1.0 : SOpac2
#Switch for CMode=0 greyscale:
CMode = (Cmode == 0) ? 128 : CMode
#Create greyscale gradients for GSGrad:
GSG = colorbars().converttoyv12().mt_lutspa(relative=true,expr="x 255 *").greyscale()
GSG = GSG.TurnLeft().LanczosResize(640,360)
Clp1 = (GSGrad == False) ? Clp1 : GSG
clp2 = default(clp2, clp1)
Clp2 = (GSGrad == False) ? Clp2 : GSG
# Create mt_lutxy expressions for the blend modes:
# Didee's '128-Centred Contrast Multiply' (HardLight):
HDL = " y 128 < x y * 128 / "+String(Opac1)+" * x 1 "+String(Opac1)+" - * + "
HDL = HDL + " y 128 > 256 256 x - 128 y 128 - - abs * 128 / - "+String(Opac2)+" * x 1 "+String(Opac2)+" - * + "
HDL = HDL + "x ? ?"
HDL2 = " y 128 < x y * 128 / "+String(SOpac1)+" * x 1 "+String(SOpac1)+" - * + "
HDL2 = HDL2 + " y 128 > 256 256 x - 128 y 128 - - abs * 128 / - "+String(SOpac2)+" * x 1 "+String(SOpac2)+" - * + "
HDL2 = HDL2 + "x ? ?"
#Didee's '128-centred contrast multiply' commuted (Overlay):
OVE = " x 128 < y x * 128 / "+String(Opac1)+" * x 1 "+String(Opac1)+" - * + "
OVE = OVE + " x 128 > 256 256 y - 128 x 128 - - abs * 128 / - "+String(Opac2)+" * x 1 "+String(Opac2)+" - * + "
OVE = OVE + "y ? ?"
OVE2 = " x 128 < y x * 128 / "+String(SOpac1)+" * x 1 "+String(SOpac1)+" - * + "
OVE2 = OVE2 + " x 128 > 256 256 y - 128 x 128 - - abs * 128 / - "+String(SOpac2)+" * x 1 "+String(SOpac2)+" - * + "
OVE2 = OVE2 + "y ? ?"
#Glow
GLO = "x 255 == x "+String(Opac)+" * x 1 "+String(Opac)+" - * + "
GLO = GLO + " 255 y y * 255 x - / min "+String(Opac)+" * x 1 "+String(Opac)+" - * + "
GLO = GLO + "?"
GLO2 = "x 255 == x "+String(SOpac)+" * x 1 "+String(SOpac)+" - * + "
GLO2 = GLO2 + " 255 y y * 255 x - / min "+String(SOpac)+" * x 1 "+String(SOpac)+" - * + "
GLO2 = GLO2 + "?"
#Reflect
REF = "y 255 == y "+String(Opac)+" * x 1 "+String(Opac)+" - * + "
REF = REF + " 255 x x * 255 y - / min "+String(Opac)+" * x 1 "+String(Opac)+" - * + "
REF = REF + "?"
REF2 = "y 255 == y "+String(SOpac)+" * x 1 "+String(SOpac)+" - * + "
REF2 = REF2 + " 255 x x * 255 y - / min "+String(SOpac)+" * x 1 "+String(SOpac)+" - * + "
REF2 = REF2 + "?"
#
Bl1Expr= (BLMode=="Blend") ? "y "+string(Opac)+" * x 1 "+string(Opac)+" - * +"
\ : (BLMode=="Multiply") ? "x y * 255 / "+String(Opac)+" * x 1 "+String(Opac)+" - * +"
\ : (BLMode=="Screen") ? "256 256 x - 256 y - * 256 / - "+String(Opac)+" * x 1 "+String(Opac)+" - * + "
\ : (BLMode=="Hardlight") ? HDL
\ : (BLMode=="Overlay") ? OVE
\ : (BLMode=="Glow") ? GLO
\ : (BLMode=="Reflect") ? REF
\ : (BLMode=="Lighten") ? "x y > x y "+String(Opac)+" * x 1 "+String(Opac)+" - * + ? "
\ : (BLMode=="Darken") ? "x y < x y "+String(Opac)+" * x 1 "+String(Opac)+" - * + ? "
\ : Bl1Expr
#
Bl2Expr= (BLMode2=="Blend") ? "y "+string(SOpac)+" * x 1 "+string(SOpac)+" - * +"
\ : (BLMode2=="Multiply") ? "x y * 255 / "+String(SOpac)+" * x 1 "+String(SOpac)+" - * + "
\ : (BLMode2=="Screen") ? "256 256 x - 256 y - * 256 / - "+String(SOpac)+" * x 1 "+String(SOpac)+" - * + "
\ : (BLMode2=="HardLight") ? HDL2
\ : (BLMode2=="Overlay") ? OVE2
\ : (BLMode2=="Glow") ? GLO2
\ : (BLMode2=="Reflect") ? REF2
\ : (BLMode2=="Lighten") ? "x y > x y "+String(SOpac)+" * x 1 "+String(SOpac)+" - * + ? "
\ : (BLMode2=="Darken") ? "x y < x y "+String(SOpac)+" * x 1 "+String(SOpac)+" - * + ? "
\ : Bl2Expr
#Apply blend operation:
BLOut = mt_lutxy(clp1,clp2, Bl1Expr, Y=LMode, U=CMode, V=CMode)
Output = (BL2 == False) ? BLOut : mt_lutxy(Clp1, BLOut, Bl2Expr, Y=LMode, U=CMode, V=CMode)
#Preview set-up:
Clp1s = Clp1.LanczosResize(640,360).Subtitle("Clp1 (Base)", size=14)
Clp2s = Clp2.LanczosResize(640,360).Subtitle("Clp2 (Top)", size=14)
Outs = Output.LanczosResize(640,360).Subtitle("Output", size=14)
Outgs = Output.Greyscale().LanczosResize(640,360).Subtitle("Output (Greyscale)", size=14)
Clpsv = StackVertical(Clp2s, Clp1s)
Outsv = StackVertical(Outs, Outgs)
Prev = StackHorizontal(Clpsv, Outsv)
#GSGrad view set-up:
GSGH = GSG.Histogram().Subtitle("Original")
GSGoH = Output.LanczosResize(640,360).Histogram().Subtitle("Blend operation applied")
GSGout = StackVertical(GSGH, GSGoH)
#Output
Final = (Preview == False && GSGrad == False) ? Output
\ : Preview ? Prev : GSGout
#
Return Final
}
Edit: Fixed BLMode2 bug
__________________
Nostalgia's not what it used to be Last edited by WorBry; 17th May 2010 at 14:47. |
|
|
|
|
|
#18 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
.....and, SelSah_V2
Code:
Function SelSah_v2 (clip clp, float "Sat", float "Hue", int "Luma_Low", int "Luma_High", int "Low_OS", int "High_OS",
\ clip "clp2", bool "Exclude", bool "Preview")
{
#Description:
# Extends Tweak to allow selective control of saturation and hue over a defined luma range.
# Assembled by WorBry. MaskTools computations kindly provided by Didee. Thanks to Gavino for advice on script syntax.
# Requires YV12 clp input and assumes full (pc) luma range 0-255.
# Requires MaskTools v2.
#
# Parameters:
# Clp - Is the input clip that will be processed.
# Clp2 - Provides option to use a second clip with different luma curve for the saturation/hue control.
# Sat - Saturation. (As per Tweak) Desaturation 0.0 < 1.0 > Increased saturation
# Hue - Hue. (As per Tweak) Range -180 to +180
# Luma_Low - Lower luma range point. Range 0 - 255 *
# Luma_High - Upper luma range point. Range 0 - 255 *
# Low_OS - Lower over-shoot point. Provides soft roll-off at lower range boundary. Range 0 - 255 *
# High_OS - Upper over-shoot point. Provides soft roll-off at upper range boundary. Range 0 - 255 *
# Exclude True/False. True excludes the range selected by the luma set points. False (default)
# includes the selected range.
# Preview - True/False. True provides preview of original clip, output and luma masks with original
# and output chroma.
#*Note: the luma set points are limited with respect to each other to ensure correct orientation and avoid overlap.
#Defaults:
Sat = default(Sat, 1.0)
Hue = default(Hue, 0.0)
Exclude = default(Exclude, False)
Luma_Low = default(Luma_Low, 0.0)
Luma_High = default(Luma_High, 255)
Low_OS = Exclude ? default(Low_OS, Luma_Low + 20)
\ : default(Low_OS, Luma_Low - 20)
High_OS = Exclude ? default(High_OS, Luma_High - 20)
\ : default(High_OS, Luma_High + 20)
clp2 = default(clp2, clp)
Preview = default(Preview, False)
#
#Limits:
Sat = Sat <0.0 ? 0.0 : Sat
Hue = Hue <-180 ? -180 : Hue > 180 ? 180 : Hue
Luma_Low = Luma_Low <0.0 ? 0.0 : Luma_Low >255 ? 255 : Luma_Low
Luma_High = Luma_High <0.0 ? 0.0 : Luma_High >255 ? 255 : Luma_High
Low_OS = Exclude && Low_OS <Luma_Low ? Luma_Low
\ : Exclude && Low_OS > High_OS ? ((Luma_Low + Luma_High)/2)
\ : Low_OS <0.0 ? 0.0 : Low_OS >Luma_Low ? Luma_Low : Low_OS
High_OS = Exclude && High_OS >Luma_High ? Luma_High
\ : Exclude && High_OS < Low_OS ? ((Luma_Low + Luma_High + 2)/2)
\ : High_OS <Luma_High ? Luma_High : High_OS >255 ? 255 : High_OS
#
#Create Saturation and Hue control clip:
twclp = clp2.tweak(sat=Sat, hue=Hue, coring=false)
#
#Create luma mask with low/high range points and roll-off gradient at boundaries:
#"Include" [0]<-black->[Low_OS]<-gradient->[Luma_Low]<-white->[Luma_High]<-gradient->[High_OS]<-black->[255]
#"Exclude" [0]<-white->[Luma_Low]<-gradient->[Low_OS]<-black->[High_OS]<-gradient->[Luma_High]<-white->[255]
#
Low_OS = string(Low_OS) Luma_Low = String(Luma_Low)
Luma_High = String(Luma_High) High_OS = String(High_OS)
#Create "Include" range expression for mask:
blkI = "x "+Low_OS+" < x "+High_OS+" > | 0 "
whtI = "x "+Luma_Low+" >= x "+Luma_High+" <= & 255 "
grLI = "x "+Luma_Low+" < 255 x "+Low_OS+" - "+Luma_Low+" "+Low_OS+" - / * "
grHI = "x "+Luma_High+" > 255 1 x "+Luma_High+" - "+High_OS+" "+Luma_High+" - / - * "
exprI = blkI + whtI + grLI + grHI + "x ? ? ? ?"
#Create "Exclude" range expression for mask:
blkE = "x "+Low_OS+" >= x "+High_OS+" <= & 0 "
whtE = "x "+Luma_Low+" < x "+Luma_High+" > | 255 "
grLE = "x "+Low_OS+" <= 255 x "+Low_OS+" - "+Luma_Low+" "+Low_OS+" - / * "
grHE = "x "+Luma_High+" < 255 x "+High_OS+" - "+Luma_High+" "+High_OS+" - / * "
exprE = blkE + whtE + grLE + grHE + "x ? ? ? ?"
#Luma Mask (greyscale for output):
lmask = twclp.mt_lut(expr = (Exclude ? ExprE : ExprI))
lmaskg = lmask.Greyscale()
# Apply luma mask:
Output = mt_merge(clp,twclp,lmaskg,luma=true,Y=2,U=3,V=3)
#
#PREVIEW set-up
clps =clp.Subtitle("Original Clip").LanczosResize(640,360)
outs =output.Subtitle("Final Output").LanczosResize(640,360)
#Luma Mask with chroma from tweaked clp
lmcts = lmask.Subtitle("Luma mask + Tweaked Chroma").LanczosResize(640,360)
#Luma Mask with chroma from original clp
lmcc = Exclude ? clp2.mt_lut(expr=ExprE) : clp2.mt_lut(expr=exprI)
lmccs = lmcc.Subtitle("Luma Mask + Original Chroma").LanczosResize(640,360)
#Create composite view
Clpout = StackVertical(clps,outs)
Masks = StackVertical(lmccs, lmcts)
Prev = StackHorizontal(Clpout,Masks)
#
Final = Preview ? Prev : Output
#
Return(Final)
}
Code:
Function Stint_v1 (clip clp, int color, float "Sat", int "Luma_Low", int "Luma_High", int "Low_OS", int "High_OS",
\ bool "Exclude", clip "clp2", bool "Blr", string "Blr_Type", float "Blr_rad",
\ bool "EdgeM", string "EMode", float "EThY1", float "EthY2",
\ bool "Grey", bool "Preview")
{
#
# Description:
#
# Based on the original 'Tint' function by actionman133. Modified by WorBry to use MaskTools v2 and provide a
# greater level of control. The input clip chroma is converted to luma and a luma mask is used to apply the desired
# color tint. The original Tint function was intended to favour the mid-tones. This updated version allows the tint
# to be applied to a defined 'luma range'. It is also possible to apply a (pre)blur and edge mask. These can assist
# in creating localized hues, characteristic of some 'film looks' e.g. "Bleach Bypass' (Silver Retention).
# The function Requires YV12 input and assumes and processes at full (pc) range (0-255); if input clip is 16-235
# (tv) range, pre-scale accordingly with scaling filter of choice (ColorYUV, Levels, YLevels, SmoothLevels etc).
# Requires MaskTools v2 and tsp's VariableBlur and MedianBlur.
#
# Parameters:
# Clp - Input clip to which the tint will be applied.
# Color - The chosen tint color. Uses hexadecimal color codes, preceded by $. Default is Sepia.
# Sat - Strength (saturation) of the tint. Range 0.0 - 1.0. Default 0.3
# Luma_Low - Lower luma range point. Range 0 - 255 *
# Luma_High - Upper luma range point. Range 0 - 255 *
# Low_OS - Lower over-shoot point. Provides soft roll-off at lower range boundary. Range 0 - 255 *
# High_OS - Upper over-shoot point. Provides soft roll-off at upper range boundary. Range 0 - 255 *
# Exclude - True/False. True excludes the selected range. Default is False.
# Clp2 - Option to use a second clip for creation of the luma mask. Useful for applying other
# pre-treatments that may influence the tint pattern - sharpening, altered luma curve etc.
# Blr - True/False. True applies a blur of a selected type. Default is False. The blur is applied
# prior to creation of the luma range control mask or edge mask.
# Blr_type - Blur type. The provided options are "binomial", "gauss", "average" (from VariableBlur) and
# "median". Default is "binomial".
# Blr_rad - Blur strength, as defined by the blur luma (y) radius (variance). Default is 3.0.
# EdgeM - True/False. True applies a luma edge mask (mt_edge). This replaces the luma range
# control mask, so range control is not available in this mode; the range is fixed at 0-255.
# Default is False.
# EMode - Edge mask Mode (3x3 convolution kernel). Default is "sobel". "min/max" can be useful for
# creating a more diffuse hue (halo) around edges, especially in combination with a (pre) blur.
# For other available modes, see MaskTools v2 documentation.
# EthY1 - Edge mask low luma threshold. Below this value, pixel is set to 0. Default is 10
# EthY2 - Edge mask upper luma threshold. Above this value, pixel is set to 255. Default is 10
# Grey - True/False. True applies the tint to the fully desaturated (greyscale) clip. Default is False.
# Preview - True/False. True provides a preview of the input clip, final output, greyscale clp with
# applied tint and mask. Default is False.
#
#*Note: the luma set points are limited with respect to each other to ensure correct orientation and avoid overlap.
#
Color = Default(Color, $5E2612) # Sepia
Sat = Default(Sat, 0.3)
Exclude = default(Exclude, False)
Luma_Low = default(Luma_Low, 0.0)
Luma_High = default(Luma_High, 255)
Low_OS = Exclude ? default(Low_OS, Luma_Low + 20)
\ : default(Low_OS, Luma_Low - 20)
High_OS = Exclude ? default(High_OS, Luma_High - 20)
\ : default(High_OS, Luma_High + 20)
clp2 = Default(clp2, clp)
EdgeM = Default(EdgeM, false)
EMode = Default(EMode, "sobel")
EthY1 = default(EthY1, 10)
EthY2 = default(EthY2, 10)
Blr = default(Blr, false)
Blr_type = default(Blr_type, "binomial")
Blr_rad = default(Blr_rad, 3.0)
Grey = default(Grey, false)
Preview = default(Preview, false)
#
#Limits:
Sat = Sat <0.0 ? 0.0 : Sat >1.0 ? 1.0 : Sat
Luma_Low = Luma_Low <0.0 ? 0.0 : Luma_Low >255 ? 255 : Luma_Low
Luma_High = Luma_High <0.0 ? 0.0 : Luma_High >255 ? 255 : Luma_High
Low_OS = Exclude && Low_OS < Luma_Low ? Luma_Low
\ : Exclude && Low_OS > High_OS ? ((Luma_Low + Luma_High)/2)
\ : Low_OS <0.0 ? 0.0 : Low_OS >Luma_Low ? Luma_Low : Low_OS
High_OS = Exclude && High_OS >Luma_High ? Luma_High
\ : Exclude && High_OS < Low_OS ? ((Luma_Low + Luma_High + 2)/2)
\ : High_OS <Luma_High ? Luma_High : High_OS >255 ? 255 : High_OS
#
#Create blankclip with chosen color
colbc = BlankClip (clp, color=color, pixel_type = "YV12")
#Create greyscale clp, if 'Grey" requested
clp = Grey? clp.greyscale() : clp
#Convert chroma from clp and blankclip to luma. Resulting images are half-size & greyscale.
clpu = clp.UtoY ()
clpv = clp.VtoY ()
colbcu = colbc.UtoY ()
colbcv = colbc.VtoY ()
#Create greyscale clip for luma mask; uses clp2 if defined, or clp by default
clp2g = clp2.Greyscale()
#Apply blur, if requested.
clp2gb = (Blr == False) ? clp2g
\ : (Blr_type == "binomial") ? clp2g.binomialblur(vary=Blr_rad)
\ : (Blr_type == "gauss") ? clp2g.gaussianblur(vary=Blr_rad)
\ : (Blr_type == "median") ? clp2g.MedianBlur(radiusy=Blr_rad)
\ : (Blr_type == "average") ? clp2g.averageblur(rady=Blr_rad)
\ : clp2g
#Apply edge mask, if requested (will replace the luma range control mask)
clp2em = (EdgeM == false) ? clp2gb
\ : clp2gb.mt_edge(mode=EMode, thy1=EthY1, thy2=EthY2, y=3, u=2, v=2)
#Prepare luma range control mask:
#"Include" mode [0]<-black->[Low_OS]<-gradient->[Low]<-white->[High]<-gradient->[High_OS]<-black->[255]
#"Exclude" mode [0]<-white->[Low]<-gradient->[Low_OS]<-black->[High_OS]<-gradient->[High]<-white->[255]
Low_OS = string(Low_OS)
Luma_Low = string(Luma_Low)
Luma_High = string(Luma_High)
High_OS = string(High_OS)
Sat = string(Sat)
#Create Include mode lut expression for mask:
blkI = "x "+Low_OS+" < x "+High_OS+" > | 0 "
whtI = "x "+Luma_Low+" >= x "+Luma_High+" <= & 255 "
grLI = "x "+Luma_Low+" < 255 x "+Low_OS+" - "+Luma_Low+" "+Low_OS+" - / * "
grHI = "x "+Luma_High+" > 255 1 x "+Luma_High+" - "+High_OS+" "+Luma_High+" - / - * "
exprI = blkI + whtI + grLI + grHI + "x ? ? ? ?"
#Create Exclude mode lut expression for mask:
blkE = "x "+Low_OS+" >= x "+High_OS+" <= & 0 "
whtE = "x "+Luma_Low+" < x "+Luma_High+" > | 255 "
grLE = "x "+Low_OS+" <= 255 x "+Low_OS+" - "+Luma_Low+" "+Low_OS+" - / * "
grHE = "x "+Luma_High+" < 255 x "+High_OS+" - "+Luma_High+" "+High_OS+" - / * "
exprE = blkE + whtE + grLE + grHE + "x ? ? ? ?"
#Create luma range control mask (or use edge mask, if requested)
LMask = (EdgeM == False) ? clp2em.mt_lut(expr = (Exclude ? ExprE : ExprI))
\ : clp2em
#Modify mask for tint strength scaling and resize to match chroma
LMask = LMask.mt_lut("255 x 255 / 1 "+Sat+" - - * ", y=3).Reduceby2()
# Apply color tint with mask; convert luma back to chroma and restore luma from original clp
clput = mt_merge (clpu, colbcu, LMask, Y=3, U=2, V=2)
clpvt = mt_merge (clpv, colbcv, LMask, Y=3, U=2, V=2)
Output = YtoUV (clput, clpvt, clp)
#
#Set-up Preview:
clps = clp.LanczosResize(640,360).Subtitle("Original Clip", Size=14)
outs = output.LanczosResize(640,360).Subtitle("Final Output", Size=14)
LMasks = LMask.LanczosResize(640,360).Subtitle("Luma Mask", Size=14)
#Tint applied to greyscale clp
clpgu = clp.Greyscale().UtoY ()
clpgv = clp.Greyscale().VtoY ()
clpgut = mt_merge (clpgu, colbcu, LMask, Y=3, U=2, V=2)
clpgvt = mt_merge (clpgv, colbcv, LMask, Y=3, U=2, V=2)
GsTin = YtoUV (clpgut, clpgvt, clp)
GsTins = GsTin.LanczosResize(640,360).Subtitle("Tint on Greyscale", Size=14)
#Create composite view
Clpout = StackVertical(clps,outs)
Mskgs = StackVertical(LMasks, GsTins)
Prev = StackHorizontal(Clpout,Mskgs)
#
Final = Preview ? Prev : Output
#
Return(Final)
}
Source clip: http://www.mediafire.com/file/zztwyy...50p%20YV12.avi Frame shots: Original: http://www.mediafire.com/file/lz2lnn...20Original.png http://www.mediafire.com/file/nwhgum...20Original.png Processed: http://www.mediafire.com/file/jhzyjn...h%20Bypass.png http://www.mediafire.com/file/yel2t2...e%20tinted.png http://www.mediafire.com/file/ekdtmm...h%20Bypass.png
__________________
Nostalgia's not what it used to be Last edited by WorBry; 4th May 2010 at 15:31. |
|
|
|
|
|
#19 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
Actually, applying the pre-blur through an mt_edge mask improves the result. Dont really want to add another 'step' with more rounding errors. Maybe I can work it into the Blend_MT function.
__________________
Nostalgia's not what it used to be |
|
|
|
|
|
#20 | Link |
|
Registered User
Join Date: Jan 2004
Location: Here, there and everywhere
Posts: 1,197
|
I'm still trying to derive a suitable mt_lutyxy expression for 'Soft Light'
Reading around, the general consensus seems to be that the formula is a combination of "burn" and "dodge": Softlight(x,y) = (((255 - x) * Rm) + (x * Rs))/255 Where: Rm = x * y /255 # i.e. Multiply Rs = (255 - ((255 - x) * (255 -y)))/255 # i.e. Inverse Multiply (Screen) I've tried every which way to get a result (with a self blended greyscale gradient), but always end up with a total black or half white/half black image. Anyone (more mathematically inclined) know how to resolve this, and the resulting (about) half-equations for y < 128 and 'else' (y => 128) ?
__________________
Nostalgia's not what it used to be |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|