Advertisement
LiQuidCrab

Flicker

Mar 29th, 2021
1,509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.41 KB | None | 0 0
  1. Group {
  2.  name Flicker4
  3.  help "This tool allows you to run the curve too and maps the intensity values to the white point and gain. Then holds on a reference frame and either adds or removes flicker from there. The ability to alter these values has been added with the Tint, Multiply and Add options. you can also normalize the curve data to fit between 0 and 1 and then used to switch operations that will be used for either the darkest or lightest moments in your shot."
  4.  selected true
  5.  xpos -502
  6.  ypos -35
  7.  addUserKnob {20 flickercontrols l "Flicker Controls" t "This tool allows you to run the curve too and maps the intensity values to the white point and gain. Then holds on a reference frame and either adds or removes flicker from there."}
  8.  addUserKnob {41 channels_1 l channels T Grade1.channels}
  9.  addUserKnob {41 go l Go! t "Run the curve tool to calculate the average intensities" T CurveTool.go}
  10.  addUserKnob {41 ROI t "Area to sample" -STARTLINE T CurveTool.ROI}
  11.  addUserKnob {41 resetROI l Reset t "reset sample area" -STARTLINE T CurveTool.resetROI}
  12.  addUserKnob {26 br l "" +STARTLINE T " "}
  13.  addUserKnob {4 operation l Operation t "Add flicker or remove flicker. Inverts which values are being modified.  (White point or Gain)" M {Deflicker "Add Flicker" "" ""}}
  14.  addUserKnob {3 first_frame_1 l "Reference Frame" t "Select reference frame for Deflicker or add flicker"}
  15.  first_frame_1 1
  16.  addUserKnob {22 currentframe l "Current Frame" t "Select current frame" -STARTLINE T nuke.thisNode().knob('first_frame_1').setValue(nuke.frame())}
  17.  addUserKnob {6 tint_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  18.  addUserKnob {20 modifiers l Modifiers t "Modify the sampled curves by tinting, adding and multiplying the values." n 1}
  19.  modifiers 0
  20.  addUserKnob {18 tint l Tint t "Add color to the flicker or deflicker. This is useful if you need to boost or change the color."}
  21.  tint {0 0 0}
  22.  addUserKnob {6 tint_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  23.  addUserKnob {7 valuemultiplier l Multiply t "Increase or decrease the intensity of the effect. This stretches the curves based on your reference frame. Careful because the values could dip below 0 and then your black point should be clamped." R 0 10}
  24.  valuemultiplier 1
  25.  addUserKnob {7 add l Add t "This adds values to the curve. This will move the curve up or down in the curve editor." R 0 10}
  26.  addUserKnob {7 flickerGradeMix l mix t "This will mix the result in the Flicker Grade node allowing you to have less affect on the deflicker or add flicker."}
  27.  flickerGradeMix 1
  28.  addUserKnob {6 flickerBlackClamp l "black clamp" t "Clamp your black point on your internal and external grade nodes created with this tool." +STARTLINE}
  29.  addUserKnob {6 flickerWhiteClamp l "white clamp" t "Clamp your white point on your internal and external grade nodes." -STARTLINE}
  30.  addUserKnob {20 endGroup_2 l endGroup n -1}
  31.  addUserKnob {20 AVG l "AVG Intensity Data: Apply to external grade node" t "collection of data generated with the curve tool and different sliders in this tool. You can create an external grade node with the button or copy the values for your own use outside of the tool.\n" n 1}
  32.  AVG 0
  33.  addUserKnob {22 createGrade l "Create Flicker Grade" t "This creates a grade node based on the curve tool data. The values are set 1 for the refence point and also take into account the settings you have applied above." T "def bakeCurve( curve, first, last, inc ):\n    '''bake an expresison curve into a keyframes curve'''\n    for f in xrange( first, last, inc ):\n        curve.setKey( f, curve.evaluate( f ) )\n    curve.setExpression( 'curve' )\n\n####################################################\ndef getCurves( knob, views ):\n    '''return a list of all animation curves found in the given knob'''\n    curves = \[]\n    for v in views:\n        curves.extend( knob.animations( v ) )\n    return curves\n\n####################################################\ndef bakeExpressionKnobs( node, first, last, inc, views ):  \n    '''bake all knobs in node that carry expressions'''\n    # GET ALL KNOBS WITH EXPRESSIONS IN THEM\n    expKnobs = \[ k for k in node.knobs().values() if k.hasExpression() ]\n\n    # GET ALL CURVES INSIDE THAT KNOB INCLUDING SPLIT FIELDS AND VIEWS\n    allCurves = \[]\n    for k in expKnobs:\n        allCurves += getCurves( k, views )\n\n    # BAKE ALL CURVES\n    for c in allCurves:\n        bakeCurve( c, first, last, inc )\n\n####################################################\ndef bakeDependentNodes():\n    '''Add this to onUserDestroy callback - not yet implemented'''\n    parentNode = nuke.thisNode() # THIS IS GIVEN TO US BY THE CALLBACK, i.e. WHEN A NODE IS DELETED - WELL, NOT YET\n    depNodes  = parentNode.dependent( nuke.EXPRESSIONS )\n    \n    ret = nuke.getFramesAndViews( 'bake curves in dependent nodes?', '%s-%s' % (parentNode.firstFrame(), parentNode.lastFrame()) )\n    if not ret:\n        return\n    fRange = nuke.FrameRange( ret\[0] )\n    views = ret\[1]\n\n    for n in depNodes:\n        bakeExpressionKnobs( n, fRange.first(), fRange.last(), fRange.increment(), views )\n        \n\n####################################################\ndef bakeSelectedNodes():\n    '''bake selected nodes' knobs that carry expressions'''\n    ret = nuke.getFramesAndViews( 'bake curves in selected nodes?', '%s-%s' % (nuke.root().firstFrame(), nuke.root().lastFrame()) )\n    if not ret:\n        return\n    fRange = nuke.FrameRange( ret\[0] )\n    views = ret\[1]\n\n    for n in nuke.selectedNodes():\n        bakeExpressionKnobs( n, fRange.first(), fRange.last(), fRange.increment(), views )\n\n\nflickerNodeName = nuke.thisNode().name()\nn = nuke.thisNode().knob('link').value()\n\n\nnuke.root().begin()\nfg = nuke.createNode('Grade', inpanel = False)\nfg\['label'].setValue('FlickerGrade')\n\nfg\['white'].setValue(1, 0)\nfg\['white'].setValue(1, 1)\nfg\['white'].setValue(1, 2)\n\nfg\['white'].setExpression('\{\}.values.r'.format(flickerNodeName), 0)\nfg\['white'].setExpression('\{\}.values.g'.format(flickerNodeName), 1)\nfg\['white'].setExpression('\{\}.values.b'.format(flickerNodeName), 2)\n\nfg\['mix'].setExpression('\{\}.flickerGradeMix'.format(flickerNodeName))\n\nfg\['black_clamp'].setExpression('\{\}.flickerBlackClamp'.format(flickerNodeName))\nfg\['white_clamp'].setExpression('\{\}.flickerWhiteClamp'.format(flickerNodeName))\n\nif n == 0:\n\tbakeSelectedNodes()\nelse:\n\tpass\n" +STARTLINE}
  34.  addUserKnob {6 link l "link output" t "Use and expression instead of copying animation" -STARTLINE}
  35.  link true
  36.  addUserKnob {18 values l "Flicker Data" t "This is the values from the curve tool that have been normalized to 1 based on your selected reference frame. You can drag these into your own grade node."}
  37.  values {{"((((avgGain.r/avgWhite.r)*valuemultiplier)+add) - valuemultiplier + 1)+tint.r"} {"((((avgGain.g/avgWhite.g)*valuemultiplier)+add) - valuemultiplier + 1)+tint.g"} {"((((avgGain.b/avgWhite.b)*valuemultiplier)+add) - valuemultiplier + 1)+tint.b"}}
  38.  addUserKnob {6 values_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  39.  addUserKnob {41 intensitydata l "Original Curvetool data" t "sampled intensity data from the curve tool" T CurveTool.intensitydata}
  40.  addUserKnob {19 avgWhite l INVISIBLE +INVISIBLE}
  41.  avgWhite {{operation==0?CurveTool.intensitydata.r:(CurveTool.intensitydata.r(first_frame_1))} {operation==0?CurveTool.intensitydata.g:(CurveTool.intensitydata.g(first_frame_1))} {operation==0?CurveTool.intensitydata.b:(CurveTool.intensitydata.b(first_frame_1))} 0}
  42.  addUserKnob {6 avgWhite_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  43.  addUserKnob {19 avgGain l INVISIBLE +INVISIBLE}
  44.  avgGain {{operation==0?(CurveTool.intensitydata.r(first_frame_1)):CurveTool.intensitydata.r} {operation==0?(CurveTool.intensitydata.g(first_frame_1)):CurveTool.intensitydata.g} {operation==0?(CurveTool.intensitydata.b(first_frame_1)):CurveTool.intensitydata.b} 0}
  45.  addUserKnob {6 avgGain_panelDropped l "panel dropped state" -STARTLINE +HIDDEN}
  46.  addUserKnob {20 endGroup n -1}
  47.  addUserKnob {20 normGroup l "Normalize Data" t "Inside this group you can normalize your curve to fit between 0 and 1. This can be useful to define different operations tobe used during the brightest and darkest values in your shot. (Differnt keying setups, grades etc)" n 1}
  48.  normGroup 0
  49.  addUserKnob {22 Normalize t "Normalize a set range on a curve to fit between 0 and 1." T "orig_knob = nuke.thisNode()\['controller']\n\nif nuke.thisNode()\['normValues'].isAnimated():\n    nuke.thisNode()\['normValues'].clearAnimated()\n    anim = None\n    orig_knob.clearAnimated()\n    orig_knob.setAnimated(True)\n\nr = nuke.getInput('Enter Frame Range:')\nrstr = r.split(\"-\")\n\nstart = float(rstr\[0])\nend = float(rstr\[1])\n\nfor fr in range(int(start), int(end)+1):\n    orig_knob.setExpression('(CurveTool.intensitydata.r+CurveTool.intensitydata.g+CurveTool.intensitydata.b)/3')\n    orig_knob.animation(0).setKey(fr, orig_knob.animation(0).evaluate(fr))\n\nfor view in nuke.views():\n    # There's currently no way to ask a knob if it has an\n    # expression at a given view, so we have to check the\n    # AnimationCurve objects for that. However, we can still\n    # use knob.isAnimated() to partially optimize this.\n    if orig_knob.isAnimated(view=view):\n        aSize = 1 if orig_knob.singleValue(view) else orig_knob.arraySize()\n        for index in range(aSize):\n            anim = orig_knob.animation(index, view=view)\n            if anim is None or anim.noExpression():\n                continue\n            for f in range(int(start), int(end) + 1):\n                #knob.setValueAt(anim.evaluate(f), f, index)\n                anim.setKey(f, anim.evaluate(f))\n            orig_knob.setExpression('curve', channel=index, view=view)\n            # Even if the expression would have evaluated to a\n            # constant (flat) curve, we can't tell until after\n            # it has been baked and the expression is gone.\n            if anim.constant():\n                orig_knob.clearAnimated(index, view=view)\n\ntarget_knob = nuke.thisNode()\['normValues']\ntarget_knob.setAnimated()\nanim_list = orig_knob.animations()\n\nindex = 0\n\nfor a in anim_list:\n  anim = a.keys()\n  print anim\n\n  vals = list()\n  for val in anim:\n     vals.append(val.y)\n\n  high = max(vals)\n  low = min(vals)\n  diff = 1\n  low_val = 0\n\n  cvals = list()\n  for cval in vals:\n     cvals.append( cval - low )\n\n  chigh = max(cvals)\n  ratio = None\n  if (chigh > 0):\n     ratio = float(diff) / float(chigh)\n  else:\n     continue\n  print 'ratio is ' + str(ratio)\n  \n  for rvals in anim:\n     v = ( (rvals.y-low)*ratio ) + low_val\n     print v, rvals.x, index\n     target_knob.setValueAt( v , rvals.x)\n  index += 1\n" +STARTLINE}
  50.  addUserKnob {7 controller l INVISIBLE +INVISIBLE}
  51.  controller 0.0001
  52.  addUserKnob {22 dissolve l "create dissolve" t "Create a dissolve and use the normValues to dissolve between high and low values." -STARTLINE T "a = nuke.thisNode().name()\nb = nuke.thisNode()\nn = nuke.thisNode().knob('link2').getValue()\n\ndef flickerDissolve():\n\tdz = nuke.createNode('Dissolve', inpanel = False)\n\tdz\['label'].setValue('FlickerDissolve')\n\tdz\['which'].fromScript(b\['normValues'].toScript())\n\ndef flickerDissolveExp():\n\tdz = nuke.createNode('Dissolve', inpanel = False)\n\tdz\['label'].setValue('FlickerDissolve')\n\tdz\['which'].setExpression('\{\}.normValues'.format(a))\n\nnuke.root().begin()\n\nif n == 1:\n\tflickerDissolveExp()\nelse:\n\tflickerDissolve()\n"}
  53.  addUserKnob {6 link2 l "link output" t "Use and expression instead of copying animation" -STARTLINE}
  54.  link2 true
  55.  addUserKnob {7 normValues l "Normalized 0-1" t "This is where the normalized curve data is stored to be used in switch, dissolve and blend nodes"}
  56.  addUserKnob {20 endGroup_1 l endGroup n -1}
  57.  addUserKnob {26 br1 l "" +STARTLINE T "  "}
  58.  addUserKnob {41 alpha l "Unpremult by" T Unpremult1.alpha}
  59.  addUserKnob {41 maskChannel l "mask channel" t "The mask channel can alsobe used to further define a region to be sampled." T Keymix1.maskChannel}
  60.  addUserKnob {41 invertMask l invert -STARTLINE T Keymix1.invertMask}
  61.  addUserKnob {20 info}
  62.  addUserKnob {26 creator l "" +STARTLINE T "\nFlicker Version 2.5\nCreated by Rob Bannister"}
  63.  addUserKnob {26 site l "" +STARTLINE T "<a href=\"http://www.bannisterpost.com\" style=\"color:white\">www.bannisterpost.com</a>"}
  64.  addUserKnob {26 help_1 l "" +STARTLINE T "<a href=\"http://www.bannisterpost.com/downloads/flicker/\" style=\"color:white\">HELP</a>"}
  65. }
  66.  Input {
  67.   inputs 0
  68.   name Input1
  69.   xpos -106
  70.   ypos 123
  71.  }
  72.  Dot {
  73.   name Dot11
  74.   xpos -72
  75.   ypos 286
  76.  }
  77. set N35f2700 [stack 0]
  78.  Dot {
  79.   name Dot16
  80.   xpos -72
  81.   ypos 385
  82.  }
  83. set N35f2380 [stack 0]
  84.  Unpremult {
  85.   alpha none
  86.   name Unpremult1
  87.   xpos -374
  88.   ypos 381
  89.  }
  90.  Dot {
  91.   name Dot4
  92.   xpos -340
  93.   ypos 481
  94.  }
  95. set N35f2e00 [stack 0]
  96.  Grade {
  97.   white {{"((((avgGain.r/avgWhite.r)*valuemultiplier)+add) - valuemultiplier + 1)+tint.r"} {"((((avgGain.g/avgWhite.g)*valuemultiplier)+add) - valuemultiplier + 1)+tint.g"} {"((((avgGain.b/avgWhite.b)*valuemultiplier)+add) - valuemultiplier + 1)+tint.b"} 0}
  98.   black_clamp false
  99.   mix {{parent.flickerGradeMix}}
  100.   name Grade1
  101.   selected true
  102.   xpos -374
  103.   ypos 700
  104.  }
  105.  Premult {
  106.   alpha {{{parent.Unpremult1.alpha}}}
  107.   name Premult1
  108.   xpos -374
  109.   ypos 1071
  110.  }
  111. set N35f3c00 [stack 0]
  112.  Dot {
  113.   name Dot7
  114.   xpos -340
  115.   ypos 1300
  116.  }
  117.  Input {
  118.   inputs 0
  119.   name mask
  120.   xpos 170
  121.   ypos 1071
  122.   number 1
  123.  }
  124. set N35f3500 [stack 0]
  125. push $N35f3c00
  126. push $N35f2380
  127.  Keymix {
  128.   inputs 3
  129.   name Keymix1
  130.   xpos -106
  131.   ypos 1065
  132.  }
  133.  Switch {
  134.   inputs 2
  135.   which {{"!\[exists parent.input1]"}}
  136.   name Switch2
  137.   xpos -106
  138.   ypos 1296
  139.  }
  140.  Output {
  141.   name Output1
  142.   xpos -106
  143.   ypos 1458
  144.  }
  145.  StickyNote {
  146.   inputs 0
  147.   name StickyNote1
  148.   label "Add Flicker"
  149.   xpos -256
  150.   ypos 698
  151.  }
  152. push $N35f3c00
  153. push $N35f2e00
  154.  Viewer {
  155.   inputs 2
  156.   frame_range 1-89
  157.   fps 23.97602463
  158.   name Viewer1
  159.   xpos -951
  160.   ypos 736
  161.  }
  162.  StickyNote {
  163.   inputs 0
  164.   name StickyNote2
  165.   label deFlicker
  166.   xpos -505
  167.   ypos 698
  168.  }
  169. push $N35f3500
  170.  Dot {
  171.   name Dot14
  172.   xpos 204
  173.   ypos 194
  174.  }
  175.  Dot {
  176.   name Dot15
  177.   xpos -196
  178.   ypos 194
  179.  }
  180. push $N35f2700
  181.  Merge2 {
  182.   inputs 2
  183.   operation mask
  184.   name Merge1
  185.   xpos -230
  186.   ypos 283
  187.   disable {{"!\[exists parent.input1]"}}
  188.  }
  189.  CurveTool {
  190.   ROI {200 200 1720 880}
  191.   autocropdata {{curve x1 0} {curve x1 0} {curve x1 0} {curve x1 0}}
  192.   intensitydata {0.0001 0.0001 0.0001 0}
  193.   name CurveTool
  194.   xpos -374
  195.   ypos 283
  196.  }
  197. end_group
  198.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement