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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 7th January 2017, 14:50   #21  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by StainlessS View Post
I think the SelectEvery(-1) is mistake, should be SelectEvery(1,-1)
Yes, my mistake! (told you it was untested )

The script in the old thread had Loop(2,0,0), but I thought SelectEvery(1,-1) was a better way of expressing it.
Unfortunately, I wrote it wrong.

Quote:
From docs

Both step_size and offset1 are non optional.

Checked source args string, "SelectEvery " = "cii*"
Actually 1 compulsory clip, 1 compulsory int, and zero or more optional int, so maybe it is truly dark magic by the dark lord Gavino
So the docs are strictly speaking incorrect compared to implementation.
If offset1 is omitted, it defaults to zero.
So SelectEvery(-1) is equivalent to SelectEvery(-1, 0), which leads to a divide-by-zero in the filter constructor.
Maybe it should check for rogue input parameters and insist step_size > 0.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 7th January 2017, 16:25   #22  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,493
Okay, here's the beta plugin: pixel_rpn. It is x86 only!
And you'll also need xyremap (this is the fast beta version, the old version may be okay)

And here is the very long script:

Code:
dgsource("vis.dgi") # ffmpeg source will hopefully work

rgb=converttorgb24

################################################################################
################################################################################
## first call to pixel_rpn: fix shifts and broken frames
################################################################################
################################################################################

rgb=rgb.pixel_rpn("
$rgb:

################################################################################
# first replace broken frames with blends of their good neighbours
################################################################################
  n 505 == ?: [c0(-1,6,0)] 0.75 * [c0(3,6,0)] 0.25 * + :
  n 506 == ?: [c0(-2,6,0)] 0.5 * [c0(2,6,0)] 0.5 * + :
  n 507 == ?: [c0(-3,6,0)] 0.25 * [c0(1,6,0)] 0.75 * + :
  n 1015 == ?: [c0(-1,9,0)] 0.89 * [c0(8,9,0)] 0.11 * + :
  n 1016 == ?: [c0(-2,9,0)] 0.78 * [c0(7,9,0)] 0.22 * + :
  n 1017 == ?: [c0(-3,9,0)] 0.67 * [c0(6,9,0)] 0.33 * + :
  n 1018 == ?: [c0(-4,9,0)] 0.56 * [c0(5,9,0)] 0.44 * + :
  n 1019 == ?: [c0(-5,9,0)] 0.44 * [c0(4,9,0)] 0.56 * + :
  n 1020 == ?: [c0(-6,9,0)] 0.33 * [c0(3,9,0)] 0.67 * + :
  n 1021 == ?: [c0(-7,9,0)] 0.22 * [c0(2,9,0)] 0.78 * + :
  n 1022 == ?: [c0(-8,9,0)] 0.11 * [c0(1,9,0)] 0.89 * + :
  n 1422 == ?: [c0(-1,9,0)] 0.67 * [c0(2,9,0)] 0.33 * + :
  n 1423 == ?: [c0(-2,9,0)] 0.33 * [c0(1,9,0)] 0.67 * + :

################################################################################
# fix horizontal shifts in clip
################################################################################
  n 230 <= ?: [c0] :
  n 252 <= ?: [c0(5,0)] :
  n 360 <= ?: [c0(-2,0)] :
  n 390 <= ?: [c0(6,0)] :
  n 416 <= ?: [c0(-2,0)] :
  n 729 <= ?: [c0(6,0)] :
              [c0(9,0)]

################################################################################
# the statements above are nested if...then...else structures.
# this next operation endifs them in one go:
################################################################################
  . repeat
")

################################################################################
################################################################################
## second call to pixel_rpn: generate mask and also mask some parts manually
################################################################################
################################################################################

masked=rgb.pixel_rpn("
$rgb:
  [c0] # just copy the RGB channels as is

$a:
################################################################################
# what follows are a bunch of conditions which calculate areas to mask
################################################################################

# bottom line
  n 1016 <= ?:
    590
    590 n 550 - 0.4 * +
    590 n 1000 - 0.1 * -
    590 n 690 - 0.5 * +
    720 n 770 - 0.9 * -
    min max min max
  :
    515 n 1813 - 0 max 5 * +
    650 min
  .

  y <=

# top line
  150 n 73 - 0 max - 45 max
  n 1424 >= ?: 18 + .
  n 1756 >= ?: 10 + .
  y >

# right
  1075
  n 291 >= ?: 15 + .
  n 305 >= ?: 15 + .
  n 320 >= ?: 20 + .
  n 354 >= ?: 20 + .
  n 421 >= ?: 15 + .
  n 649 >= ?: 15 - .
  n 675 >= ?: 20 - .
  n 708 >= ?: 30 - .
  n 775 >= ?: 50 - .
  
  x <

# left
  95
  n 1430 >= ?: 80 + .
  x >
  
# corner
  x 1100 >
  y 100 <
  *

# corners
  n 430 >=
  n 506 <
  x y 1.5 * - -390 <
  * *

  x y - -300 <

# another corner
  n 908 >=
  n 933 <
  x 960 >
  y 460 >
  * * *

# foot bit
  n 1755 ==
  x y - 567 <
  x 640 >
  *
  y 100 <
  + *

  n 1753 ==
  y 100 <
  *

# post-it
  n 759 >=
  y 600 >
  n 773 <
  * *

# more bits
  n 1424 >=
  y 155 x 0.25 * - <
  *

  n 1511 >=
  y 80 <
  *

  n 1558 >=
  n 1567 <
  y x 1.25 * + 734 >
  y x 0.66 * - -310 >
  y x 1.25 * + 1485 >
  + * * *

  n 1847 >=
  x 500 >
  y 465 >
  x 915 <
  * * *

  n 1865 >=
  x 500 >
  *

  n 1866 >=
  x 300 >
  *

################################################################################
# all the above conditions are added (acts as a logical or)
################################################################################
  + repeat

  ?:
    0    # if true (non-zero), output 0
  :
    [b0] [g0] [r0] min <    # if not mostly blue...
#    [g0] 2 * [r0] > *       # or mostly red... (uncomment this to remove red tissue)
    ?:
      1    # then solid
    :
      0    # else clear
    .
  .
")

################################################################################
# the following call generates a clip with an overlaid mask for debugging
################################################################################

debug=masked.pixel_rpn("
$g: [a0] 255 *
$rb: [c0]
")

#return debug

################################################################################
# applies a 5x5 gaussian blur to the mask, and premultiplies RGB by alpha
################################################################################

masked=pixel_rpn(masked,"
$a:
  [a0(-2,-2)] [a0(-1,-2)] dup + dup + [a0(0,-2)] dup + dup + [a0(1,-2)] dup + dup + [a0(2,-2)] + + + +
  [a0(-2,-1)] [a0(-1,-1)] dup + dup + [a0(0,-1)] dup dup + + dup + [a0(1,-1)] dup + dup + [a0(2,-1)] + + + + dup + dup +
  [a0(-2, 0)] [a0(-1, 0)] dup + dup + [a0(0, 0)] dup dup + + dup + [a0(1, 0)] dup + dup + [a0(2, 0)] + + + + dup dup + + dup +
  [a0(-2, 1)] [a0(-1, 1)] dup + dup + [a0(0, 1)] dup dup + + dup + [a0(1, 1)] dup + dup + [a0(2, 1)] + + + + dup + dup +
  [a0(-2, 2)] [a0(-1, 2)] dup + dup + [a0(0, 2)] dup + dup + [a0(1, 2)] dup + dup + [a0(2, 2)] + + + +
  + repeat
  dup 0.00390625 * @A^ # store normalised alpha for premultiplication
$rgb:
  [c0] A * # premultiply by alpha (this only works because pixel_rpn calculates in the order ABGR, allowing us to set A and use it here)
")

################################################################################
# increase to full HD resolution and remap to a moving isometric projection
################################################################################

isometric=masked.addborders(320,180,320,180).xyremap( \
  x="  x 1080 - t 1500 * + 2 t 0.0 * - *     0.666666 *  ", \
  y="h y 1150 + t 1500 * - 2 t 0.0 * - * x - 0.666666 * -" \
).trim(1,0) # trim first frame, which is a dupe

################################################################################
# render as a stack, using pixel_rpn's [<.c] trick to copy the previous frame
################################################################################

stack=isometric.pixel_rpn("
$settings:
  frames:2000  # pad out to 2000 frames
  offset:25    # add 25 frames to the start

$rgb:
  [c0] [a0] 0.0039215686274509803921568627451 * 0.5 * @A *
# the '0.5 *' in the line above renders at half opacity for a nicer result - try 0.1 and 0.01 for different transparencies
  [<.c] 1 A - * +
")

################################################################################
# because we rendered the stack with half opacity slices,
# re-overlay full opacity slices for better animation.
# if you remove the "0.5 *" above, you can skip this call
################################################################################

pixel_rpn(stack,isometric,"
$rgb:
  [a1(-25)] 0.0039215686274509803921568627451 * @A [c1(-25)] *    # the (-25) offsets the offset added above, putting stack and isometric back in sync
  1 A - [c0] *
  +
")

converttoyv12 # convert to yv12 for encoding
assumefps(60)
I've annotated it as best I can, but I know it's not very readable. Any questions, let me know.
__________________
My AviSynth filters / I'm the Doctor

Last edited by wonkey_monkey; 7th January 2017 at 16:27.
wonkey_monkey is offline   Reply With Quote
Old 7th January 2017, 17:01   #23  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,493
And a semi-transparent visualisation from the same script:

http://i.imgur.com/Jt3U069.jpg
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 7th January 2017, 17:05   #24  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by davidhorman View Post
Any questions, let me know.
What is all that ?

EDIT: WOW, impressive image.

EDIT: @DavidHorman, rpn.html, typo, Maximmum, max x y min, Returns the highest of x or y
__________________
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; 7th January 2017 at 19:02.
StainlessS is offline   Reply With Quote
Old 7th January 2017, 17:59   #25  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
thanks david

Looking at the script, it's way above my programming knowledge but I'll play with the script/plugins and try to figure it out .



maybe I'll fiddle with some 3d approaches as smok3 suggested too . But mapping to 2d planes would still need the planes to be extruded at some point in the workflow for geometry
poisondeathray is offline   Reply With Quote
Old 7th January 2017, 18:09   #26  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,493
It's curious how the end result appears to be shaded, despite there being no such shading in the source images. I can't quite figure out the maths behind that. Maybe it's something to do with many semi-transparent dark pixels being stacked in the same place.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 7th January 2017, 18:49   #27  |  Link
Seedmanc
Registered User
 
Join Date: Sep 2010
Location: Russia
Posts: 85
davidhorman, yes, that's exactly what it is. Gives the depth impression. However it's hard to tune, sometimes even giving the smallest possible weight to the background instead of removing it entirely still results in all-dark picture because many frames add up.
Seedmanc is offline   Reply With Quote
Old 7th January 2017, 22:54   #28  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,493
Quote:
Originally Posted by StainlessS View Post
EDIT: @DavidHorman, rpn.html, typo, Maximmum, max x y min, Returns the highest of x or y
What's funny is that you spotted the spelling error, but didn't spot that I actually put "min" in the example code
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 7th January 2017, 23:58   #29  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
but didn't spot that I actually put "min" in the example code
Yeh, it was a test to see if you noticed once I had drawn attention to that line.

I'm getting a bit sick of repeatedly viewing the output clip, tis addictively fascinating.
At about the belly button, you can see sort of structures inside the larger cavities. (rendered as supplied script).

Those plugz of yours are quite fantastic, you truly are the Doctor/Surgeon.

EDIT: Structures


EDIT: Just using Avs standard here.
EDIT:
Quote:
Is there an anatomist in the house?
Pieces of the jigsaw, here:- https://www.google.com/search?q=orga...sBd_TZ30FSM%3A

EDIT: The shiny structure (not shown above) at high end of marked cavity is I think the Liver, blue marked structures may be somewhere about the Gall Bladder.
__________________
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; 26th November 2018 at 17:29.
StainlessS is offline   Reply With Quote
Old 8th January 2017, 02:04   #30  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,493
Is there an anatomist in the house?

Are you using Avisynth+? It'd be good to know my plugin works with it. It's internally multi-threaded, and I wasn't sure how well it would work. It needs more work though; this script only gave me 60% CPU utilisation. I think I can do better than that.
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 8th January 2017, 20:40   #31  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,346
Did some googling today and there are a bunch of open source (and some paid programs) that do image stacking and 3d model construction , some are medically oriented e.g/ slicer4, but some are versatile generic tools that can be used in many different ways eg. ImageJ / fiji . Some of them are just 2d to 3d viewers but others allow exporting 3d formats such as obj , stl . Some are geared towards 3d printing, but once you have a 3d mesh you can do lots of interesting manipulations in a 3d program such as blender . I got some fun ideas for next halloween
poisondeathray is offline   Reply With Quote
Reply

Tags
avisynth+, gscript, runtime, transition

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 22:37.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.