extractAlpha.py

extractAlpha.py

Usually we use "Shuffle" node to extract alpha from ID mattes. Some of us use "Expression" node to do the same thing. Some time we need to use basic maths function in "Expression" node to get exact matte. This code create 'Expression' node and feed the value from the window. It also clamp the value. So no need to worry about the clamp issue.

Example maths function: r, (r+b)-g, (r+g+b), (r-g)

This code will pop-up small window like below image.,



User can select maths function from the list of drop-down menu. Most of the maths function's are pre-defined and stored on the UserChoice menu. This code allow user to feed their custom maths function. If user feed anything on custom math field this code will take the code and feed the info into the expression node.

Below video will explain how the function works:




Hope this will help you friends.,

Download:  https://drive.google.com/file/d/0BzfeLEFhrh44WFRjU1lYLU1fODQ/edit?usp=sharing

nukepedia: extractalpha.py


Raw code:

'''
Created on 26-March-2014
@author: satheesh-R
mail - satheesrev@gmail.com
'''

import nuke

def extractAlpha():
    ea = nuke.Panel("extractAlpha.... by satheesh-R", 350)
    ea.addEnumerationPulldown('UserChoice:\n(pre-defined math)', 'none r g b a r+g+b r+g+b+a r+g r+b g+b r-g r-b g-b (r+g)-b (r+b)-g (g+b)-r')
    math = ea.addSingleLineInput('custom Math:', '')
    ea.addButton("cancel")
    ea.addButton("ok")
    show = ea.show()
    outChannel = ea.value('UserChoice:\n(pre-defined math)')
    customMath = ea.value('custom Math:')
    print outChannel
    if show == 0:
        return
    if customMath:
        exp = nuke.createNode('Expression')
        exp['expr3'].setValue('clamp('+customMath+')')
        exp['label'].setValue(customMath+'  to  alpha')
    else:
        if outChannel == 'none':
            return
        else:
            exp = nuke.createNode('Expression')
            exp['expr3'].setValue('clamp('+outChannel+')')
            exp['label'].setValue(outChannel+'  to  alpha')

Popular posts from this blog

2D Volumetric rays in nuke

Nuke workFlow optimisation TIPS

Export Maya camera and Objects to Nuke