View Full Version : Halftone Effect for AviSynth?
vampiredom
14th November 2013, 22:01
I am looking to create a halftone effect in AviSynth. I tried the VirtualDub plugin (http://www.hlinke.de/vdub-filter/halftone.zip) but it is RGB32 only, extremely slow and only does monochrome output.
I was able to simulate CMYK color halftoning by merging channels and rotating and layering. It looks pretty good but the performance is impossibly bad.
Does anyone know of any other ways to achieve a "printed" CMYK halftone effect in AviSynth more efficiently?
This is the effect I made (It's actually only CMY ... I did not bother with a separate black channel. It runs slowly enough already!)
http://3dvp.com/halftone.png
vampiredom
17th November 2013, 02:53
Here is the function as I have it now, for those who are curious. All the colorspace conversions are an attempt to extract some performance from Rotate(), which is slow enough with YV12 but dismally slow on high-res RGB32
Any better ideas out there? Or would anyone be interested in custom development of such a plugin (with decent quality / usable perf) for AviSynth? :confused:
Please let me know. Thanks!
Input to HalftoneCMY() should be an HD image or video (low resolution sources do not get good results, so upsample it first).
###########################
# LOAD VirtualDub PLUGIN
LoadVirtualDubPlugin("HalfTone.vdf", "halftone", 0)
###########################
function HalftoneCMY(
\ clip input,
\ int "size",
\ int "density",
\ float "weight"
\ ) {
size = Default(size, 14)
density = Default(density, 15)
weight = Default(weight, 1.0).Max(0.0).Min(1.0)
#########################
input
KillAudio()
ConvertToRGB24()
#########################
w = width()
h = height()
padY = Round(Float(w) * 0.333 / 2.0) * 2
padX = Round(Float(h) * 0.333 / 2.0) * 2
r = ShowRed("Y8")
g = ShowGreen("Y8")
b = ShowBlue("Y8")
c = Merge(b,g).ConvertToRGB32(matrix="pc.601")
m = Merge(r,b).AddBorders(padX,padY,padX,padY,color=$FFFFFF).ConvertToYV12().Rotate( 60, color=$FFFFFFFF).ConvertToRGB32(matrix="pc.601")
y = Merge(g,r).AddBorders(padX,padY,padX,padY,color=$FFFFFF).ConvertToYV12().Rotate(-60, color=$FFFFFFFF).ConvertToRGB32(matrix="pc.601")
c = c.halftone($FFFFFF, $000000, size, density)
m = m.halftone($FFFFFF, $000000, size, density)
y = y.halftone($FFFFFF, $000000, size, density)
m = m.ConvertToYV12(matrix="pc.601").Rotate(-60, color=$FFFFFF).Crop(padX,padY,-padX,-padY).ConvertToRGB32(matrix="pc.601")
y = y.ConvertToYV12(matrix="pc.601").Rotate(60 , color=$FFFFFF).Crop(padX,padY,-padX,-padY).ConvertToRGB32(matrix="pc.601")
c = BlankClip(c, pixel_type="RGB32", color=$00FFFF).Mask(c)
m = BlankClip(m, pixel_type="RGB32", color=$FF00FF).Mask(m)
y = BlankClip(y, pixel_type="RGB32", color=$FFFF00).Mask(y)
BlankClip(c, color=$FFFFFF)
Layer(c, op="Mul")
Layer(m, op="Mul")
Layer(y, op="Mul")
ConvertToYV12()
Invert("uv")
(weight != 1.0) ? Merge(input.ConvertToYV12(), last, weight=weight) : (hasAudio(input)) ? AudioDub(input) : last
}
martin53
1st December 2013, 22:16
Frankly, I have no knowledge about halftone. But just to contribute a few hints: You can create a halftone mask with mt_lutspa() and only rotate the mask. Use loop() to repeat the mask on all frames, that costs no additional CPU.
For the example, I did not rotate but only shift the mask.
BlankClip(pixel_type="YV12", width=640+16, height=480+16)
s = "(abs( (x % 16) - 8)^2 + abs( (y % 16) - 8)^2)^0.5788 * 254/((2*8^2)^0.5788)"
s = mt_polish(s)
mt_lutspa(expr=s, relative=false)
#~ ScriptClip("Subtitle(String(AverageLuma))") __END__ # activate this line to check that AverageLuma is 127 with uncropped mask segments
Mask=YToUV(last, last.Crop(8,4,0,0).AddBorders(0,0,8,4), last.Crop(4,8,0,0).AddBorders(0,0,4,8))
Image=ColorBars(width=16, height=12, pixel_type="YV24").ConvertToRGB(matrix="Rec709").GaussResize(640,480)
#~ Image __END__ # activate this line to see the raw image
s = mt_polish("x > y ? 255 : 0")
mt_lutxy(YToUV(Image.ShowGreen(pixel_type="Y8"),Image.ShowBlue(pixel_type="Y8"),Image.ShowRed(pixel_type="Y8")), Mask, expr=s, chroma="process")
MergeRGB(last, last.UToY, last.VToY)
ConvertToRGB(matrix="PC.709")
EDIT: fixed some bugs in the example
vampiredom
1st December 2013, 23:51
I will check it out, thanks for the reply!
martin53
2nd December 2013, 20:12
2nd example, not useful, but funny and with variation over time; with rotation and loop(). :cool:
EffectRotation is from V.C. Mohans EffectsMany plugin.
function UVgradient() {
BlankClip(pixel_type="YV24", length=1000)
ScriptClip("""
last
s = string(abs((current_frame+255) % 510 - 255))
su = mt_polish("255*x")
sv = mt_polish("255*y")
mt_lutspa(expr=s, uexpr=su, vexpr=sv, chroma="process")
""")
ConvertToRGB(matrix="Rec709")
}
BlankClip(pixel_type="YV12", width=1280, height=1280, length=2)
s = "(abs( (x % 16) - 8)^2 + abs( (y % 16) - 8)^2)^0.5788 * 254/((2*8^2)^0.5788)"
s = mt_polish(s)
mt_lutspa(expr=s, relative=false)
rawmask = last
m1 = rawmask.EffectRotation(ir=800, id=10).Crop(320, 240, 640, 480)
m2 = rawmask.EffectRotation(ir=800, id=10+30).Crop(320, 240, 640, 480)
m3 = rawmask.EffectRotation(ir=800, id=10+60).Crop(320, 240, 640, 480)
Mask=YToUV(m2, m3, m1).Loop(1000)
Image=UVGradient()
s = mt_polish("x > y ? 255 : 0")
mt_lutxy(YToUV(Image.ShowGreen(pixel_type="Y8"),Image.ShowBlue(pixel_type="Y8"),Image.ShowRed(pixel_type="Y8")), Mask, expr=s, chroma="process")
MergeRGB(last, last.UToY, last.VToY)
ConvertToRGB(matrix="PC.709")
StainlessS
12th March 2016, 03:37
I recently remembered this thread and thought I would resurrect it just in case Vampiredom gets emails (not been on-site for some time)
and had no response to PM.
Here webpages on ImageMagick CMYK halftoning:-
https://www.imagemagick.org/discourse-server/viewtopic.php?t=18409
http://www.imagemagick.org/Usage/quantize/#halftone
and maybe this could be a useful starting point:- http://forum.doom9.org/showthread.php?p=1753435#post1753435
SSH4
15th March 2016, 07:59
Just use After Effects of Photoshop. It easier, faster and... and its all.
wonkey_monkey
16th March 2016, 09:30
Just use After Effects o[r] Photoshop. It easier, faster and... and its all.
Same goes for a good proportion of problems posed on these forums, but for some reason it's not always an option. $$$
SSH4
17th March 2016, 09:36
Same goes for a good proportion of problems posed on these forums, but for some reason it's not always an option. $$$
Just download trail. ;)
I don't think anyone need halftone effect on every video basis :D
If i'm wrong, i scare, that tons of halftoneprinteffect videos are coming.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.