View Single Post
Old 3rd April 2016, 23:42   #1  |  Link
MWilson
Registered User
 
Join Date: Mar 2016
Location: Arkansas
Posts: 95
Automated Colorization Script (Now ChromaJig)

Edit: Updated - See Post # 157

I've written a script that I think is pretty interesting. I should clean this up, but I'm away from my normal computer and I'm very used to using AVSPMod.

Requirements are:
defreq
Masktools2

Code:
Function Cmx7Mod(clip c, Float "Sat",Bool "DownSz",Int "Pad") {    # (c) MWilson, http://forum.doom9.org/showthread.php?t=173364
    # Progressive Only : MUST be MOD 2 Width and Height, Otherwise will crop Mod 2
    Sat    = Default(Sat,0.33)                                                                    # Default 0.33, 0.0 -> 1.0
    DownSz = Default(DownSz,True)                                                                 # Default true, True=Qwiker, False Precise       
    Pad    = (Default(Pad,2)+1)/2*2                                                               # Round up next multiple of 2, Avoid green border.
    c = c.Crop(0,0,c.Width/2*2,c.Height/2*2).ConvertToYV12.GrayScale                              # Mod 2
    smallc = (DownSz) ? c.sincresize((c.Width+3)/4*2,(c.Height+3)/4*2) : c                        # At least half size, Mod 2
    Padc = (Pad>0)  ? smallc.pointresize(smallc.Width+Pad*2,smallc.Height+Pad*2,-Pad,-Pad,smallc.Width+Pad*2,smallc.Height+Pad*2) : smallc    
    r  = Padc.defreq(fy=0,fx=39,sharp=100,dx=50,dy=50,cutx=0,cuty=0).Crop(Pad,Pad,-Pad,-Pad)
    r1 = Padc.defreq(fy=0,fx=47,sharp=100,dx=50,dy=50,cutx=0,cuty=0).Crop(Pad,Pad,-Pad,-Pad)
    g  = Padc.defreq(fy=0,fx=37,sharp=100,dx=50,dy=50,cutx=0,cuty=0).Crop(Pad,Pad,-Pad,-Pad)
    g1 = Padc.defreq(fy=0,fx=85,sharp=100,dx=50,dy=50,cutx=0,cuty=0).Crop(Pad,Pad,-Pad,-Pad)   
    b  = Padc.defreq(fy=0,fx=65,sharp=100,dx=50,dy=50,cutx=0,cuty=0).Crop(Pad,Pad,-Pad,-Pad)   
    b1 = Padc.defreq(fy=0,fx=59,sharp=100,dx=50,dy=50,cutx=0,cuty=0,fx2=100,fy2=0).Crop(Pad,Pad,-Pad,-Pad)       
    x1 = merge(r,r1)
    y1 = merge(smallc.invert(),merge(g,g1))
    z1 = merge(smallc.invert(),merge(b,b1))    
    y2 = overlay(smallc,y1,mode="multiply")
    z2 = overlay(smallc,z1,mode="multiply") 
    x=mt_makediff(smallc,x1,Chroma="-128").converttorgb()                                         # Full range RGB
    y=mt_makediff(smallc,y2,Chroma="-128").converttorgb()       
    z=mt_makediff(smallc,z2,Chroma="-128").converttorgb()       
    mergergb(x,y,z).ConvertToYV12                                                                 # RGB to YV12 TV Levels    
    lanczos4resize(c.Width,c.Height)    
    mergechroma(c,ColorYUV(autowhite=true))    
    return (Sat>0.0) ? mergechroma(c,tweak(sat=7.5,interp=32),Sat) : Last 
}
Thanks to StainlessS for the mod


The latest version:
Code:
function fc1(clip v,float weight)

{# (c) MWilson, http://forum.doom9.org/showthread.php?t=173364

v=v.greyscale().converttoyv12()
af=v.defreq(fy=-.29,fx=.29,sharp=0,dx=.50,dy=.50,fy2=-.88,fx2=.88,dx2=.50,dy2=.50)
av=v.defreq(fy=-29,fx=29,sharp=0,dx=50,dy=50,fy2=-88,fx2=88,dx2=50,dy2=50)
ax=v.defreq(fy2=-88,fx2=88,sharp=0,dx2=50,dy2=50,fy=-58,fx=58,dx=0,dy=50)
a=mt_makediff(merge(af,av),v).converttorgb().converttoyv12()
m1=ytouv(av,a).converttoyv12().sincresize(width(v),height(v))
y2=ytouv(m1.invert(),av).converttoyv12().sincresize(width(v),height(v))
merge(m1,y2,.35)
converttoyv12(last)
coloryuv(autowhite=true)
tweak(sat=5,maxsat=59.5,interp=20)
merge(v.invert().converttoyv12(),last.converttoyv12())
converttorgb()
sb=showblue(last).invert()
sr=showred(last).invert()
sg=showgreen(last).invert()
mergergb(sb,sr,sg)
ConvertToYV12()
sx=last.converttorgb().invert("G").converttoyv12()
sy=last.converttoyv12()
mergechroma(sy,sx,.50).converttoyv12()
merge(last,v.invert().converttoyv12()).invert("UV").swapuv()
tweak(sat=7.5,maxsat=59.5,interp=20)
mergechroma(v.converttoyv12(),last,weight)
coloryuv(autowhite=true)
converttorgb24()

return last

}



function fc2(clip v)

{# (c) MWilson, http://forum.doom9.org/showthread.php?t=173364

v=v.greyscale().converttoyv12()
merge(v.invert().fc1(1).converttoyv12().coloryuv(cont_u=-128,cont_v=-128),v.fc1(1).converttoyv12())
converttoyv12()
tweak(sat=5,interp=32)
mergechroma(v,last.awarpsharp2(depth=48,chroma=4),.333)

return last

}



function chromajig(clip y)

{# (c) MWilson, http://forum.doom9.org/showthread.php?t=173364

y=y.greyscale().converttoyv12()
y1=y.gaussresize(72,48)
y1
fc2()
#hqdn3d(0,28,0,4.5)
gaussresize(width(y),height(y))
subtract(y.fc2(),last)
mergeluma(y)
return last
}


function cjbx(clip v)

{# (c) MWilson, http://forum.doom9.org/showthread.php?t=173364

v=v.converttoyv12().greyscale()
v1=v.spline36resize(240,240)
y=v1.converttorgb()
y.pointresize(8,8)
invert()
pointresize(16,16)
chromajig()
blur(1,1)
invert()
swapuv()
#temporalsoften(10,0,20)
spline36resize(width(y),height(y))

a=last

y.pointresize(32,32)
chromajig()
blur(1,1)
invert()
spline36resize(width(y),height(y))

b=last

y.pointresize(180,180)
chromajig()
blur(1,1)
invert()
swapuv()
spline36resize(width(y),height(y))

c=last

subtract(a,b)
subtract(last,c)
invert()
spline36resize(width(y),height(y))
mergechroma(y.converttoyv12().greyscale(),last,.75)
coloryuv(autowhite=true)
spline36resize(width(v),height(v))
blur(1,1)
mergechroma(v,last)
return last
}



function colorfox(clip y)
{# (c) MWilson, http://forum.doom9.org/showthread.php?t=173364
y=y.greyscale().converttoyv12()
y.cjbx()
a=last
c1=a.converttorgb()

r=showred(c1)
g=showgreen(c1)
b=showblue(c1)

c=merge(r,merge(g,b).invert())
m=merge(g,merge(r,b).invert())
ye=merge(b,merge(r,g).invert())

mergergb(ye,m,c)

subtract(last,c1)
converttoyv12()
invert("UV")
subtract(a,last)
swapuv()
}


function colorjig(clip v, float "Weight")
{# (c) MWilson, http://forum.doom9.org/showthread.php?t=173364
Weight= Default(Weight,1)
v=v.greyscale().converttoyv12()
b=v.greyscale().colorfox().tweak(hue=90).invert("UV").coloryuv(autowhite=true).invert("V").converttoyv12()

merge(b,b.chromajig())
coloryuv(autowhite=true)
mergechroma(v,last,Weight)
}

function cfcf2(clip y)
{
y=y.greyscale().converttoyv12().invert().turnleft()
a=y.cjbx().utoy()
b=y.invert().TurnLeft().cjbx().TurnRight().invert().utoy()
ytouv(a,b,y)
mergechroma(y,last,.45)
converttoyv12()
c=last
subtract(c,y.cjbx())
invert("UV")
medianblur(0,10,10)
mergechroma(c,last,.33)
turnright()
invert("Y")
return last
}


Using the latest script, will update this post later.


Edit: Updated to the latest version. A note: this is for colorization, don't expect miracles! Sorry if I was misleading in the beginning of this thread, it wasn't on purpose. I was confused as well!

Edit: Sorry folks, as davidhorman pointed out this needs to have a call to greyscale! Code updated.

Edit: Code Updated - See Posts #34 & #35

Edit: Updated - See Post #37

Edit: Updated - See Posts #66 & #69

Edit: Updated 4/18/16

Edit: Minor Changes

Last edited by MWilson; 1st November 2017 at 15:01. Reason: Update
MWilson is offline   Reply With Quote