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. |
17th May 2016, 15:20 | #1 | Link |
Registered User
Join Date: Jan 2010
Posts: 709
|
Motion Compensate Limited Sharpen 16bit
Here a sharpen I'm worked on some time ago, it's inspired to Didée's prof of concept,
dependencies: - Dither tools by cretindesalpes - MVTools 2.6.x/2.7.x - MaskTools2 and RgTools by tp7 Code:
function MCLS_16(clip c, float "strength", clip "sharp", int "thsad", int "plane",\ float "ss", bool "repair", int "dmode", bool "masked", bool "blur_gaussian") { #Motion Compensate Limited Sharpen for a 16bit stacked clip by Motenai Yoda #first relase - beta 7 #it works (or should) with 16bit stacked clip input/output strength = Default(strength, 1.0) thsad = Default(thsad, 400) plane = Default(plane, 0) ss = Default(ss, Defined(sharp) ? 1.0 : 1.25) repair = Default(repair, Defined(sharp) ? false : true) dmode = Default(dmode, 1) masked = Default(masked, true) blur_gaussian = Default(blur_gaussian, false) str = String(strength) HD = (c.width > 1280) ? 2 : (c.width > 720) ? 1 : 0 Pel = Select(HD, 2, 1, 1) Truemotion = Select(HD, True, False, False) Blksize = Select(HD, 8, 16, 32) Overlap = Select(HD, 4, 8, 8) Yp = (plane == 0 || plane == 4) ? 3 : 1 Up = (plane == 1 || plane == 3 || plane == 4) ? 3 : 1 Vp = (plane == 2 || plane == 3 || plane == 4) ? 3 : 1 Chromap = (plane == 0) ? false : true width2 = Round(c.width*ss) height2 = Round(c.height*ss/2.0) wpad = 16-(width2%16) hpad = 16-(height2%16) bRadius = Round(Select(HD, 3, 3, 4) / 1.25 * ss) resized_source = (ss != 1.0) ? c.Dither_resize16(width2+wpad, height2+hpad, y=3, u=Up,\ v=Vp) : c resized_sharp = Defined(sharp) ? (ss != 1.0) ? sharp.Dither_resize16(width2+wpad, height2+hpad,\ y=Yp, u=Up, v=Vp) : sharp : nop() pre = resized_source.Dither_removegrain16(3, (Up == 3) ? 3 : -1, (Vp == 3) ? 3 : -1) sharp0 = Defined(sharp) ? Dither_sub16(resized_sharp, resized_source, wrap=False, y=Yp, u=Up,\ v=Vp, dif=true) : Dither_sub16(resized_source, blur_gaussian ? Dither_box_filter16(resized_source,\ radius=max(bRadius-2, 1), y=Yp, u=Up, v=Vp).Dither_box_filter16(radius=max(bRadius-1,1), y=Yp, u=Up, v=Vp).\ Dither_box_filter16(radius=max(bRadius-1,1), y=Yp, u=Up, v=Vp) : Dither_box_filter16(resized_source,\ radius=bRadius, y=Yp, u=Up, v=Vp), wrap=False, y=Yp, u=Up, v=Vp, dif=true) source0 = Ditherpost(pre, mode=-1, y=3, u=Up, v=Vp) mask = (masked) ? source0.mt_edge("min/max", y=3, u=1, v=1).mt_deflate(y=3, u=1, v=1).\ removegrain(12, -1, -1) : nop() mask = (masked) ? stackvertical(mask, mask) : nop() sup0 = source0.MSuper(pel=Pel, sharp=2, chroma=Chromap) sharp0m = sharp0.Dither_get_msb() sup1 = sharp0m.MSuper(pel=Pel, sharp=2, chroma=Chromap) sharp0l = sharp0.Dither_get_lsb() sup2 = sharp0l.MSuper(pel=Pel, sharp=2, chroma=Chromap) bv1 = sup0.MAnalyse(isb=true, delta=1, chroma=Chromap, blksize=Blksize, truemotion=Truemotion, overlap=Overlap) fv1 = sup0.MAnalyse(isb=false, delta=1, chroma=Chromap, blksize=Blksize, truemotion=Truemotion, overlap=Overlap) nullclip = source0.mt_lut(y= (Yp==3) ? -0 : 1, u= (Up==3) ? -0 : 1, v= (Vp==3) ? -0 : 1) diff1 = sharp0m.MDegrain1(sup1, bv1, fv1, plane=plane, thsad=thsad, lsb=true) diff2 = sharp0l.MDegrain1(sup2, bv1, fv1, plane=plane, thsad=thsad, lsb=false) diff2_16 = stackvertical(nullclip, diff2) diff3 = Dither_add16(diff1, diff2_16, wrap=False, y=Yp, u=Up, v=Vp, dif=false) sharped_back = Dither_add16(resized_source, diff3, wrap=False, y=Yp, u=Up, v=Vp, dif=true) repaired = (repair) ? Dither_repair16(sharped_back, resized_source, (Yp == 3) ? 1 : -1 ,\ (Up == 3) ? 1 : -1, (Vp == 3) ? 1 : -1).Dither_merge16(sharped_back,sharped_back.mt_lut(y=-76,\ u=1,v=1),luma=true, y=Yp, u=Up, v=Vp): sharped_back bias = (dmode == 1) ? resized_source.Dither_lut16("x 4096. - 56064. / 0 1 clip pi * sin 0.5 ^ 65536. * "+\ str+" *", y=3, u=1, v=1) : nop() bias = (masked) ? (dmode == 1) ? bias.mt_logic(mask, "min", y=3, u=1, v=1) : mask : bias repaired = (dmode == 1 || masked) ? Dither_merge16(resized_source, repaired, bias, y=Yp, u=Up, v=Vp, luma=true) :\ repaired resized_back = (ss != 1.0) ? Dither_resize16(repaired, c.width(), c.height()/2, y=Yp, u=Up, v=Vp) : repaired return ytouv((Up == 3) ? resized_back.utoy() : c.utoy(), (Vp == 3) ? resized_back.vtoy() : c.vtoy(),\ (Yp == 3) ? resized_back : c) } edit2: fixed some flaw about chroma processing when Y plane is not processed (a bit slower than before if plane = 1/2/3) note 22/06/2016 : I used mt_logic "min" to merge edgemask and lumamask, as edgemask is basically 0/255, when it's 0 it's the minimum, when it's 255 isn't the minimum, moreover with a lumamask value X = x/256 , if multiplied togheter X*0 = 0, X*(255/255) = X*1 = X so using a lut to multiply them should give roughtly same result.
__________________
powered by Google Translator Last edited by Motenai Yoda; 22nd June 2016 at 00:56. |
21st May 2016, 12:44 | #5 | Link |
Registered User
Join Date: Jan 2010
Posts: 709
|
screen for animation stuff
original - masked=false - masked=true Anyway it can be used even feeding a yet sharped clip, as well it is 16 bit. Notice only with an external "sharp" clip supersampling and repair are booth disabled. ie with a min/max sharp Code:
function MinMaxSharp(clip c, int "radius"){ radius = Default(radius, 1) max = (radius == 1) ? c.mt_expand(u=1, v=1) : c.mt_expand(u=1, v=1).mt_expand(u=1, v=1) min = (radius == 1) ? c.mt_inpand(u=1, v=1) : c.mt_inpand(u=1, v=1).mt_inpand(u=1, v=1) avg = mt_average(min, max, u=1, v=1) diff = c.mt_makediff(avg, u=1, v=1) return c.mt_adddiff(diff, u=2, v=2) } function MinMaxSharp_16(clip c, int "radius"){ radius = Default(radius, 1) quant= int(pow(((2*radius)+1),2) - 1) min = c.Dither_median16(rx=radius, ry=radius, rt=0,ql=0,qh=0, y=3, u=1, v=1) max = c.Dither_median16(rx=radius, ry=radius, rt=0,ql=quant,qh=quant, y=3, u=1, v=1) avg = Yoda_Average16(max, min, y=3, u=1, v=1) diff = c.Dither_sub16(avg, wrap=False, y=3, u=1, v=1, dif=True) return c.Dither_add16(diff, false, u=2, v=2, dif=true) } or with a limited supersampled one Code:
function FLSF_16(clip c, float "strenght", int "radius", bool "edgemode",\ float "ss", bool "fast", int "dmode") { #v7 strenght = Default(strenght, 1.0) radius = Default(radius, 1) edgemode = Default(edgemode, true) ss = Default(ss, 1.25) fast = Default(fast, true) dmode = Default(dmode, 1) strenght = (fast==true && radius == 1) ? strenght * 0.8 : strenght nr = !fast width2 = Round(c.width*ss) height2 = Round(c.height*ss/2) wpad = 16-(width2%16) hpad = 16-(height2%16) c.converttoy8() (ss != 1.0) ? Dither_resize16nr(last, width2+wpad, height2+hpad, noring=nr) : last quant= int(pow(((2*radius)+1),2) - 1) dark = Dither_median16(rx=radius, ry=radius, rt=0,ql=0,qh=0, y=3, u=1, v=1) bright = Dither_median16(rx=radius, ry=radius, rt=0,ql=quant,qh=quant, y=3, u=1, v=1) #avg = (fast==true && radius==1) ? Dither_Box_Filter16_Fixed(3,3,1,1) :\ Yoda_Average16(bright, dark, y=3, u=1, v=1) avg = (fast==true && radius==1) ? Yoda_GaussianRG16(3,false) : Yoda_Average16(bright,\ dark, y=3, u=1, v=1) diff = Dither_sub16(avg, wrap=False, y=3, u=1, v=1, dif=True) diff2 = (strenght == 1.0) ? diff : Dither_lut16(diff,yexpr="x 128 256 * - "+\ string(strenght)+" * 128 256 * + ", u=1, v=1) sharp = Dither_add16(diff2, false, u=1, v=1, dif=true) darkdiff = Dither_sub16(dark, sharp, wrap=False, y=3, u=1, v=1) brightdiff = Dither_sub16(sharp, bright, wrap=False, y=3, u=1, v=1) darkclamp = Dither_add16(sharp, darkdiff, wrap=False, y=3, u=1, v=1) brightclamp = Dither_sub16(darkclamp, brightdiff, wrap=False, y=3, u=1, v=1) clamp = (radius==1) ? Dither_Repair16(sharp, last, 1, -1) : brightclamp bias = (dmode == 1) ? Dither_lut16("x 16 256. * - 219. 256. * / pi * sin 256. 256. * *",\ u=1, v=1) : last clamp = (dmode == 1) ? Dither_merge16(last, clamp, bias, u=1, v=1) : clamp resized = (ss != 1.0) ? Dither_resize16nr(clamp, c.width, c.height/2, noring=nr).\ converttoyv12() : clamp.converttoyv12() mask = c.Dither_Get_Msb().mt_edge("min/max", u=1, v=1) mask = stackvertical(mask,mask) return (edgemode) ? mt_merge(c, resized, mask, u=2, v=2) : mergechroma(resized, c) } (note FLSF_16() is very prone to loss 1-2 (radius) px detail and flat edges) ps: Yoda_Average16() can be replaced by Dither_merge16(sharped_back,sharped_back.mt_lut(y=-128,\ u=1,v=1),luma=true, y=Yp, u=Up, v=Vp) or Dither_add16(a,b.Dither_sub16(a, diff=true, y=Yp, u=Up, v=Vp).\ Dither_lut16("x 2. /" , y=Yp, u=Up, v=Vp), diff=true, y=Yp, u=Up, v=Vp) Yoda_GaussianRG16(3,false) by Dither_Removegrain16(20,0).Dither_Removegrain16(20,0).Dither_Removegrain16(20,0)
__________________
powered by Google Translator Last edited by Motenai Yoda; 21st May 2016 at 14:21. |
15th October 2016, 16:34 | #6 | Link | |
Registered User
Join Date: Jan 2010
Posts: 709
|
new 0.8 beta
Quote:
__________________
powered by Google Translator Last edited by Motenai Yoda; 18th October 2016 at 02:13. |
|
16th October 2016, 00:12 | #7 | Link |
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,904
|
Are you planning to support 16bit interleave as well in the future?
Oh, by the way, you wrote "unction" instead of "Function" in the pastebin Last edited by FranceBB; 16th October 2016 at 22:11. |
18th October 2016, 02:09 | #8 | Link | |
Registered User
Join Date: Jan 2010
Posts: 709
|
beta 9
Quote:
@FranceBB to compensate this time first I paste it with the old title, then without avisynth highlight, and finally posted the wrong one btw I'd like to change a lot when new avs+ and 16bit aware mvtools2 will be reality and to put a bunch of Assert() too ps should be better mcstuffin' the mask too?
__________________
powered by Google Translator Last edited by Motenai Yoda; 18th October 2016 at 02:44. |
|
18th October 2016, 10:25 | #9 | Link |
Broadcast Encoder
Join Date: Nov 2013
Location: Royal Borough of Kensington & Chelsea, UK
Posts: 2,904
|
Got it.
Thank you very much indeed anyway. As to the current version, I'll test it this evening since I'm at work right now. Anyway, when the new mvtools2 will be released, I don't know how it's gonna handle calculations. In case MVTools2 will be aware of 16 bit stack only (input-output), it would be fine to get it working with your script and leave the interleave option for those who want to use an 8bit mask and 16 calculations. Anyway, I honestly don't know how many benefits will bring a 16bit mask, even considering speed vs quality. |
18th October 2016, 22:24 | #11 | Link |
Registered User
Join Date: Jan 2012
Location: Mesopotamia
Posts: 2,587
|
cool, and in normal avs? you will add lsb_in like Dfttest?
__________________
See My Avisynth Stuff |
13th March 2017, 18:56 | #13 | Link |
Registered User
Join Date: Jan 2010
Posts: 709
|
new experimental try which trade on avs+ 16bit yv12 format (yv16? yv24? yuv444? Not tested)
this version doesn't support stacked/doublewidth formats http://pastebin.com/AmN6iT5X
__________________
powered by Google Translator |
15th March 2017, 01:56 | #14 | Link |
Registered User
Join Date: Jan 2010
Posts: 709
|
Another testing one, now works with 8-16bit y/yv12/yv16/yv24 input, mask and sharp clips (but the same colorformat, unless input is y or plane=0)
http://pastebin.com/SZuLFRP5
__________________
powered by Google Translator |
16th March 2017, 13:31 | #15 | Link | |
Acid fr0g
Join Date: May 2002
Location: Italy
Posts: 2,580
|
Quote:
__________________
@turment on Telegram |
|
16th March 2017, 16:50 | #16 | Link | |
Registered User
Join Date: Jan 2010
Posts: 709
|
Quote:
- dither is (-1 none/truncate or round, 0 ordered, 1 floyd-steinberg) - dither_bits define at what bitdepth it will dither, unlike Ditherpost where indicates dithering bits, ie: convertbits(bits=8,dither=0,dither_bits=2) return you a 2 bit dithered into 8 bit format, also it has to be min input bit -8 if dither=0
__________________
powered by Google Translator Last edited by Motenai Yoda; 21st March 2017 at 17:26. |
|
4th January 2018, 22:11 | #18 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
Maybe you would like to tell Yoda which script you are talking about.
The 'Mask' arg to said function is a clip, in older version of function 'Masked' was a bool. EDIT: I did not find an SMg.avs EDIT: Below Google search found nothing Code:
"SMg.avs" site:forum.doom9.org Code:
"SZuLFRP5.avsi" site:forum.doom9.org (or should be used with the older version of the script).
__________________
I sometimes post sober. StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace "Some infinities are bigger than other infinities", but how many of them are infinitely bigger ??? Last edited by StainlessS; 4th January 2018 at 22:49. |
5th January 2018, 07:28 | #20 | Link |
Registered User
Join Date: Jan 2010
Posts: 709
|
Hi Ale_x try replacing "mask=false" with "edgemode=0"
also on a newer masktools2 version you have to replace all #F with @F
__________________
powered by Google Translator Last edited by Motenai Yoda; 5th January 2018 at 07:45. |
|
|