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. |
|
|
Thread Tools | Search this Thread | Display Modes |
14th October 2012, 00:35 | #1 | Link |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
xyremap - reverse Polish pixel remapper (experimental)
Download beta: xyremap0.5beta.zip v0.5 (beta)
version 0.5: some new RPN functions, a bug fix, and (approximately) gamma-aware interpolation (see http://forum.doom9.org/showthread.ph...01#post1736501) version 0.4: new x86 RPN compiler; new functionality (see http://forum.doom9.org/showthread.ph...05#post1735605) Download: xyremap0.3.zip v0.3 version 0.3: new parameter "static" to speed up non-animating remaps version 0.2: bug fixes to pixel interpolator, min/max functions, added new RPN parameters See included xyremap.txt for parameters, etc. See here and here for explanations of Reverse Polish Notation Please note that the RPN parser is not very intelligent when it comes to malformed notation, and may simply return an unexpected result without erroring. Examples To make some animated waves: Code:
xyremap(version.converttorgb32,y="y x 0.1 * n 5 / + sin 8 * +") To take a trip into the time vortex: Code:
stackhorizontal(version,version) stackvertical(last,last) converttorgb32 xyremap(\ "y h 0.5 * - x w 0.5 * - atan2 n 250 / + TAU + u 1.5 * TAU / * u 0.5 * % u 0.25 * +",\ "1 y h 0.5 * - 2 ^ x w 0.5 * - 2 ^ + sqrt / w 100 * * n + v 0.5 * % v 0.25 * +",\ "y h 0.5 * - 2 ^ x w 0.5 * - 2 ^ + sqrt w 0.5 * /",\ w=640,\ h=360,\ draft=false) Last edited by wonkey_monkey; 30th August 2015 at 18:59. |
18th October 2012, 19:13 | #2 | Link |
Registered User
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
|
Whoa, this is just what I was requesting a short while ago, but then gave up that project...
Would love to get some time to play around with this, looks like it can do pretty much everything =). "Note that "-" is used instead of "+" because we are mapping from output to input pixels, not the other way around (which would be more intuitive)." I'm guessing it's like this so that each output pixel will have an input location (interpolated pixel) to get its data from. "t: t=n/framecount (so 0<=0<1)" 0<=t<1 |
18th October 2012, 22:40 | #3 | Link | ||
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Quote:
Quote:
David |
||
1st November 2012, 13:58 | #4 | Link |
Registered User
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
|
Am I the only one who finds this interesting?
Feature requests: - Ability to choose the color of the padding outside the input image, or extend the existing border pixels. The bicubic interpolation is making my stretched edges dark. - Boolean to make x and y go from 0 to 1 so I don't have to divide by u and v. - Is it possible to make the function go the other direction, map input pixels to the output image instead? It's difficult enough to find the function from input to output that then needs to be reverseed/solved with WolframAlpha, but my functions are often non-solvable =). And it would be easier to wrap helper functions around them. |
1st November 2012, 17:51 | #5 | Link | ||||
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Apparently
Quote:
Quote:
Code:
... 0.5 max w 0.5 - min ... 0.5 max h 0.5 - min Quote:
Quote:
TL;DR: there is a bug in the interpolator that I need to fix which is producing slightly wrong pixel values. David Last edited by wonkey_monkey; 1st November 2012 at 18:05. |
||||
1st November 2012, 19:02 | #6 | Link |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
xyremap v0.2
A couple of bugs fixed - min/max weren't working properly, and the pixel interpolation bug is fixed - and some new RPN parameters are added: Code:
a: pixel x coordinate normalised to [0-1] b: pixel y coordinate normalised to [0-1] c: pixel y coordinate normalised to [0-1*display_aspect_ratio] Hope that helps! David |
2nd November 2012, 20:06 | #7 | Link |
Registered User
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
|
Thanks.
Yes it might be a problem with mapping into the same, but my functions don't do that =). Oh well, I guess I can live without it. I padded it myself using pointresize (needed 2 pixels so the last pixel wouldn't be slightly dark), but I would've liked for an easier solution. The modulo solution looks interesting though, didn't think of that. Another request: an "if" statement. Last edited by ajp_anton; 2nd November 2012 at 20:12. |
2nd November 2012, 20:39 | #8 | Link |
Registered User
Join Date: Sep 2008
Posts: 365
|
The plugin functions in itself is interesting, but as probably many others I only use avisynth to correct "errors" in the video, like f eks rainbowing and dotcrawl.
My guess is that those who want to manipulate video and add effects turn to Adobe AfterEffects or similar.
__________________
(i have a tendency to drunk post) |
6th November 2012, 18:56 | #9 | Link | ||
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Quote:
Quote:
Anyway, here's another frivolous (and very slow) use of xyremap: Code:
a=blankclip(width=640,height=1280,length=1500).subtitle(\ "It is a period of civil war.\n"+\ "Rebel spaceships, striking\n"+\ "from a hidden base, have won\n"+\ "their first victory against\n"+\ "the evil Galactic Empire. \n\n"+\ "During the battle, Rebel\n"+\ "spies managed to steal secret\n"+\ "plans to the Empire's\n"+\ "ultimate weapon, the DEATH\n"+\ "STAR, an armored space\n"+\ "station with enough power to\n"+\ "destroy an entire planet. \n\n"+\ "Pursued by the Empire's\n"+\ "sinister agents, Princess\n"+\ "Leia races home aboard her\n"+\ "starship, custodian of the\n"+\ "stolen plans that can save\n"+\ "her people and restore\n"+\ "freedom to the galaxy.... "\ ,lsp=0,align=8,size=50).converttorgb32 b=a.reduceby2.bicubicresize(320,320) c=b.reduceby2.bicubicresize(160,80) d=c.reduceby2.bicubicresize(80,20) a=a.xyremap("x w 0.5 * - 1 y h / * / u w / * u 0.5 * +","v h y - y / h * n 4 * - v + - v 1280 / *","y 4 - h / sqrt 1 h y - 0.005 * - *",w=640,h=360) b=b.xyremap("x w 0.5 * - 1 y h / * / u w / * u 0.5 * +","v h y - y / h * n 4 * - v + - v 1280 / *","y h / sqrt h y - 0.005 * 1 180 y - 0.01 * - min *",w=640,h=360) c=c.xyremap("x w 0.5 * - 1 y h / * / u w / * u 0.5 * +","v h y - y / h * n 4 * - v + - v 1280 / *","y h / sqrt 180 y - 0.01 * 1 90 y - 0.02 * - min *",w=640,h=360) d=d.xyremap("x w 0.5 * - 1 y h / * / u w / * u 0.5 * +","v h y - y / h * n 4 * - v + - v 1280 / *","y h / sqrt 90 y - 0.02 * *",w=640,h=360) e=overlay(a,b,mode="add",pc_range=true) f=overlay(c,d,mode="add",pc_range=true) overlay(e,f,mode="add",pc_range=true) Tell me that's not practical David |
||
6th November 2012, 20:53 | #10 | Link |
Registered User
Join Date: Jan 2006
Posts: 1,867
|
I think this would be useful to remove barrel distortion from a camera lens. Once you do that, it's simple to stitch together scenes into panoramas.
The other problems though, could be vignetting and exposure changes, but in some cases it could work. |
6th November 2012, 22:27 | #11 | Link |
HeartlessS Usurer
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
|
This is quite spectacular, limited usage as Mastrboy suggests, but impressive, just the same.
Think maybe the fascination with Dr Who may have influenced the vortex-ish type intro. EDIT: PS, nice work.
__________________
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; 6th November 2012 at 22:29. |
7th November 2012, 09:58 | #13 | Link | ||
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Quote:
Quote:
|
||
20th November 2012, 22:25 | #14 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
David,
I'd like to suggest some extensions that I hope are manageable to program, yet extend the capabilities significantly. A) Extension of RPN
B) Extension of input variables r/g/b/a red/green/blue/alpha pixel values C) Extension of parameters r/g/b/a red/green/blue/alpha pixel values additionally to x/y coordinates - i understand that xyremap is made with two cascaded loops, one over the lines and one over the columns? so, with the extensions b) and c), instead of remapping, xyremap could be used as color manipulation function beyond YV12LUT() for RGB format. D) A background clip, and dx, dy parameters to overlay output with offset over it - considering alpha, of course. E) new name xyrgbaSwissKnife |
21st November 2012, 00:44 | #15 | Link |
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Hi Martin,
I had considered some extensions. I'm not sure what you mean about dup - how would you "re-use" the duplicated operand? I considered an assignment operator, =, to set your own variables (and perhaps then an operator to reset the current stack as well, if required, leaving assigned variables intact), but that means extra checks to make sure the hard-coded variables aren't overwritten. Perhaps also some comparison operators - lt, gt, eq - and some way to implement if ... then ... else in RPN. As for B) and C), which r/g/b/a pixel values would these be? The filter is all about calculating x,y coordinates of source pixels, so how can it know which pixel to read to get the RGBA values? I'm also not sure what you mean by "additionally to x/y coordinates" in C). A separate RGBA filter is certainly possible, though. D) I thought was best left to the user to use the internal layer filter. E) Silly David Last edited by wonkey_monkey; 21st November 2012 at 00:49. |
21st November 2012, 12:05 | #16 | Link |
Registered User
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
|
"some way to implement if ... then ... else in RPN."
See how it's done in mt_masktools. You have the ==, >, <... checks that take two input variables and return true/false. Then you have the ? that takes three inputs. One bool, one to return if it's true, one if it's false. if a==b, then T, else F a b == T F ? |
21st November 2012, 18:30 | #17 | Link |
Registered User
Join Date: Mar 2007
Posts: 407
|
- You are right: MaskTools also use RPN, and I feel it would be a good idea to use similar operand sets. I only used yv12lut so far. There is no min operator. To subtract a value, but avoid negative results, I write "x 128 - 0 < 0 x 128 - ?", or in human speech, "subtract 128 from x, and if the result is below zero, take zero, else take x minus 128". X-128 must be computed twice, and if I needed to limit a very complicated expression, I have no confidence that I could manage that (bug finding is not easy with RPN). I thought that with dup, an intermediate result could be stored and re-used more easily. But in fact it would be useless because the copy is needed only later and cannot easily handled on the RPN stack.
A different strategy would be needed. A limited set of 'variables'-operands, like 's0' stores top of stack to 'v0' and leaves it also on stack, 'r0' recalls 'v0' to top of stack would help - and stay within the syntax. As a side thought: To facilitate bug finding, the function could throw an error if the expression does not end with 1 entry on the stack, and dump the stack. What do you think about this? |
21st November 2012, 19:26 | #18 | Link | |
Registered User
Join Date: Mar 2007
Posts: 407
|
Quote:
For the RPN formulas of parameters "x" and "y", no extension is useful. My suggestion meant four more parameters string "r", string "g", string "b", string "a", all with RPN expressions. With these expressions, also the variables r, g, b, a of the source pixel would be fantastic (instead of copying it 1:1). Imagine the cool color gradients possible with just xyremapping a BlankClip, even x="x", y="y" and using the variables x,y in the brightness RPN expression (shiver). xyremap(x="x",y="y",r="x u 2 / - 2 ^ y v 2 / - 2 ^ + u 2 ^ v 2 ^ + / PI * cos") red = cos( PI * ((x-u/2)²+(y-v/2)²)/(u²+v²) ) It would be a pity if x and y would not be present as variables to define the brightness. No color gradients then. You allow an implicit cropping with the parameters w and h. You are right: even if an alpha value is calculated with xyremap, the output clip can still be forwarded to layer. I tend to create complicated processing. Because long graphs use much memory, I prefer few powerful filters over many simple ones. Only because of that, I phantasized to combine the two steps into one. |
|
21st November 2012, 23:15 | #19 | Link | |||
Formerly davidh*****
Join Date: Jan 2004
Posts: 2,496
|
Quote:
Code:
compiler error - check your string (x) # where x is how many values are left on the stack Code:
x 128 - 0 < 0 x 128 - ? Code:
x 128 - 0 min Code:
x 128 - q= 0 < 0 q ? Quote:
Quote:
Warping an image in two dimensions is hard enough - warping it in 6 is crazy! David PS x="x" and y="y" are the defaults for those expressions, so don't need to be specified. Last edited by wonkey_monkey; 21st November 2012 at 23:36. |
|||
22nd November 2012, 00:09 | #20 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
MaskTools v2: "mt_lutspa()"
__________________
- 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!) |
Thread Tools | Search this Thread |
Display Modes | |
|
|