View Full Version : Display test pattern (Gscript)
lisztfr9
17th November 2012, 23:20
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\GScript.dll")
A = BlankClip(500, 483, 320, color=$00008B)
A
Function V_lines(clip "A", int "large", int "start")
{
W = width(A)
# large = 1
# start = 13
end = W - start
left = Crop(A, 0, 0, -end, 0)
right = Crop(A, start, 0, 0, 0)
Wr = width(right)
hband = Crop(right, 0, 0, -(Wr - large), 0)
right = Crop(right, large, 0, 0, 0)
hband = hband.BlankClip(color=$FFFF00)
A = StackHorizontal(left , hband, right)
Return A
}
GScript("""
for (i=1, Width(A), 10){
V_lines(last, 1, i)
}
""")
Thanks, L
Jenyok
18th November 2012, 18:51
Could we see picture of script result ?
StainlessS
18th November 2012, 19:10
Same script but a little less ugly: (EDIT: Removed quotes from V_lines args as were NOT optional args)
A = BlankClip(500, 483, 320, color=$00008B)
A
Function V_lines(clip A, int large, int start) {
W = width(A)
# large = 1
# start = 13
end = W - start
left = Crop(A, 0, 0, -end, 0)
right = Crop(A, start, 0, 0, 0)
Wr = width(right)
hband = Crop(right, 0, 0, -(Wr - large), 0)
right = Crop(right, large, 0, 0, 0)
hband = hband.BlankClip(color=$FFFF00)
A = StackHorizontal(left , hband, right)
Return A
}
GScript("""
for (i=1, Width(A), 10) {
V_lines(last, 1, i)
}
""")
Result:
https://s20.postimg.org/hnlzz4nst/VStripes.png (https://postimg.org/image/o1b32dsop/)
lisztfr9
18th November 2012, 20:45
@StainlessS
Nice StainlessS ! i have to beautify my code. Ok, for the quotes
This is just an exercise in order to make a poor man's descratch... It's the line scanning stage. I should be able to remove 1 dark line in a frame thanks to this, keeping the last 3 values of luma (for i), checking thresholds (1 and 3 mostly equal, 2 spike), and later calling V_lines for (i - 1) to correct luma. It's a kind of normalisation.
I guess that flicker correction (with an horizontal scan) should involve working on more than 1 frame, but seems possible.... Since flicker changes every single frame, real luma variations would span over at least 2 frames and would be skipped for correction.
StainlessS
18th November 2012, 21:13
Dont know if helpful but RT_stats has functions to get eg AverageLuma of a single line (horiz/vert), usuable via GScript.
Also eg YDifference (RT_YDifference) to get luma difference between lines (horiz/vert via x,y,w,h).
Lines can be from different frames or the same frame with different x,y coords.
EDIT: Or even different frames with different x,y coords.
EDIT: Or even different clips, different frames with different x,y coords.
EDIT: Some of the funcs available in RT_Stats:
RT_AverageLuma(clip,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,bool "interlaced"=false,int "Matrix"=0)
Returns FLOAT value average luma (0.0 -> 255.0) in frame(n+delta) for area x,y,w,h.
RT_YDifference(clip,int "n"=current_frame,int "delta"=1,int "x"=0,int "y"=0,int "w"=0,int "h"=0,int "x2"=x,int "y2"=y,
bool "interlaced"=false,int "Matrix"=0)
Returns FLOAT value luma difference (0.0 -> 255.0) between frame n area x,y,w,h, and frame (n+delta) area x2,y2,w,h.
Note, by default it will be equivalent to YDifferenceToNext as delta defaults to 1 and x,y,w,h defaults full frame.
Note, 'x2' and 'y2' default to 'x' and 'y' respectively.
RT_LumaDifference(clip,clip2,int "n"=current_frame,int "delta"=0,int "x"=0,int "y"=0,int "w"=0,int "h"=0,
int "n2"=current_frame,int "delta2"=0,int "x2"=x,int "y2"=y,bool "interlaced"=false,int "Matrix"=0)
Returns FLOAT value luma difference (0.0 -> 255.0) between clip frame (n+delta) area x,y,w,h, and clip2 frame (n2+delta2) area x2,y2,w,h.
Note, 'x2' and 'y2' default to 'x' and 'y' respectively.
lisztfr9
18th November 2012, 21:35
Dont know if helpful but RT_stats has functions to get eg AverageLuma of a single line (horiz/vert), usuable via GScript.
Also eg YDifference (RT_YDifference) to get luma difference between lines (horiz/vert via x,y,w,h).
Lines can be from different frames or the same frame with different x,y coords.
EDIT: Or even different frames with different x,y coords.
Ok i will read further on that... gosh.
lisztfr9
22nd November 2012, 17:33
Hi StainlessS,
I tried the If statement but can't get this to work :
if ( condition ) {
statements
}
else {
statements
}
Testing :
GScript("""
for (i=1, Width(A), 10){
V_lines(last, 1, i)
If (i =< 100 = true){
V_lines(last, 1, i + 1)
}
Else {
V_lines(last, 1, i + 3)
}
}
""")
TIA, L
Edit : I see there is something wrong with the brackets...
Also wrong ...
GScript("""
for (i=1, Width(A), 10){
V_lines(last, 1, i)
(i =< 100) ? V_lines(last, 1, i + 1) : V_lines(last, 1, i + 3)
}
""")
StainlessS
22nd November 2012, 18:12
Try this (untested)
GScript("""
for (i=1, Width(A), 10) {
V_lines(last, 1, i)
If (i <= 100) {
V_lines(last, 1, i + 1)
} Else {
V_lines(last, 1, i + 3)
}
}
""")
EDIT: "<=" is LessOrEqual, presume thats what you want, or would it be just plain "<" LessThan, that you want.
http://avisynth.org/mediawiki/Operators
Try indenting your code, it does not just "look nice", you can see the logic structure just from the shape
without even reading the code.
lisztfr9
22nd November 2012, 18:32
Yes it's that, sorry ! Same as in Qbasic
StainlessS
22nd November 2012, 19:00
No need to be sorry, wer'e all just beginners. :)
martin53
24th November 2012, 14:44
lisztfr9,
I am not sure if you are trying GScript or if you are making a test pattern.
For a test pattern, I would like to give you a hint.
AviSynth video processing is made as a chain of elementary processing steps. Typically, every step takes the frame in memory, allocates additional memory for its output and calculates the output pixels from the input pixels (if we omit the time line for a moment).
That means: because you call a function that takes and delivers a clip in a loop, you (maybe inadvertently) build a long chain of processors and thus something that allocates much memory.
This script (verified) also produces vertical thin lines at a distance of 10:
BlankClip(pixel_type="YV12").mt_lutspa(mode="absolute", expr="x 10 % 0 == 255 0 ?")
lisztfr9
24th November 2012, 14:59
@martin53
Thanks martin, i'm happy to learn every bit here...
Some other thing that worries me is the link between Levels and mt_lutf as :
mt_lutf(B, hband, mode = "avg", expr = "y 6 +")
I'm sure the same thing can be done with Levels, maybe just setting average_luma + 6 as last parameter. I will check that later. Or reducing gamma.... but gamma act as a multiplicand , so imho it increase dynamic range...
Edit : Ok i should definitively use Tweak for that.
martin53
24th November 2012, 20:04
Yep - or ColorYUV(off_y=6).
lisztfr9
24th November 2012, 23:57
BlankClip(pixel_type="YV12").mt_lutspa(mode="absolute", expr="x 10 % 0 == 255 0 ?")
It's working as promised, but i had to update masktools V2, from masktools-v2.0a37 to the last one, masktools-v2.0a48.
The "?" execute code conditionally, the 2 last integers seems to set colors, and if i cancel the "==" i get it in reverse colors. gosh...
http://unreal666.hdd1.ru/docs/avisynth/russian/externalfilters/masktools2.htm#mt_lutspa
Gavino
25th November 2012, 00:20
It's working as promised, but i had to update masktools V2, from masktools-v2.0a37 to the last one, masktools-v2.0a48.
Because the 'mode' parameter was not added to mt_lutspa until v2.0a45.
The "?" execute code conditionally, the 2 last integers seems to set colors, and if i cancel the "==" i get it in reverse colors. gosh...
Also when i set "!=" instead. Why ? Also i don't understand why it draws lines !
The expression means 'if x%10 == 0 then 255 else 0'. ('%' means mod)
So at points in the image where x=0, 10, 20, ..., the pixel is set to 255 (white), otherwise it is set to 0 (black). This results in a series of vertical lines.
Changing '==' to '!=' reverses the condition, thus inverting the colors at each point.
lisztfr9
25th November 2012, 08:52
@Gavino
Yes Gavino, i'm not used to RPN, in particular having the "==" sign as postfix. It's rather a boolean operator as a equal sign. I should ever translate to infix
Gavino
25th November 2012, 10:38
Don't forget that masktools also has a mt_polish() function which converts infix notation to RPN, so you don't need to use RPN if you don't want to. For example, the previous expression could be written as:
expr=mt_polish("x % 10 == 0 ? 255 : 0")
There is also a function mt_infix() which does the reverse, and can be used to check the meaning of RPN expressions you find in other people's scripts (or the correctness of your own).
Subtitle(mt_infix("x 10 % 0 == 255 0 ?"))
will show
x % 10 == 0 ? 255 : 0
lisztfr9
25th November 2012, 11:02
Very useful ! but
http://manao4.free.fr/mt_masktools.html
Don't say anything about mt_infix, or i'm blind :)
Ok it's shown as add (Alpha 5)
Gavino
25th November 2012, 11:39
Very useful ! but
http://manao4.free.fr/mt_masktools.html
Don't say anything about mt_infix, or i'm blind :)
Ok it's shown as add (Alpha 5)
The on-line web page is hopelessly out of date, and covers only up to v2.0a27.
mt_infix was introduced in v2.0a37 (it was actually mt_polish that came in at alpha 5).
You need to look at the documentation in the masktools download zip file - documentation\mt_masktools.html.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.