Eyeon:Script/Reference/Applications/Fuse/Classes/Image/ChannelOpOf

From VFXPedia

< Eyeon:Script | Reference | Applications | Fuse | Classes | Image
Revision as of 04:32, 26 October 2008 by Daniel (Talk | contribs)
(diff) ← Older revision | Current revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents


Summary

The ChannelOpOf function performs operations on image channels from one or more images. It can be used to copy the red channel from one image to the alpha channel of another, or to multiply the RGB color channels of one image by its own alpha. This function essentially provides all the functionality normally found in the Channel Booleans tool.

The function returns a new image which contains the result of its operations.


Usage

Image:ChannelOpOf(string operation, image fg, table options)

operation (string, required)
A string that specifies the mathematical operation the function will use when combining channels. Can be one of the following :
Copy
Add
Subtract
Multiply
Divide
Max
Min
Invert
Difference
SignedAdd
Threshold
fg (image, required)
The image object used as the foreground, or second image in the operation. If this is nil, then the function will use the Image object calling the function as the foreground as well (i.e. "fg.r" is equivalent to "bg.r").
options (table, required)
A table containing named entries describing how each channel of the background image should be processed to produce the result. Each entry in the table may contain either a numeric constant value, or a string specifying a channel in the foreground or background image, which is combined using the specified operation to produce the desired result. The channels used in the entry are abbreviations, and the values are strings that read either Fg.channel or Bg.channel. Case is not important. See the Options section below for a list of acceptable channel abbreviations. Some example options tables are shown below:
{ R = "Fg.R", G = "Fg.G", B = "Fg.B", A = "Fg.A" }
 
{ R = "bg.a", G = "bg.a", B = "bg.a", A = 1.0 }
 
{ R = blend, G = blend, B = blend, A = blend }


Options Table

Channel Abbreviations (case is not important)

R, G, B, A
Red, Green, Blue and Alpha channels
Z
Z Buffer Channel
Coverage
Z buffer coverage channel
U, V
U and V co-ordinates channels
NX, NY, NZ
XYZ normals channels
BgR, BgG, BgB, BgA
The Background Red, Green and Blue channels
ObjectID, MaterialID
The ObjectID and MaterialID channels
VectX, VectY
The X and Y motion vector channels
BackVectX, BackVectY
Background X and Y motion vectors
HLS.H, HLS.L, HLS.S
Hue, Lightness and Saturation channels
YUV.Y, YUV.U, YUV.V
YUV colorspace channels

Example

This example would copy the RGBA channels in the foreground image to the background and return the results to img_out.

img_out = img:ChannelOpOf("Copy", img_fg, { R = "Fg.R", G = "Fg.G", B = "Fg.B", A = "Fg.A" } )


This example would subtract foreground's RGBA channels from the background and return the results to img_out.

img_out = img:ChannelOpOf("Subtract", img_fg, { R = "Fg.R", G = "Fg.G", B = "Fg.B", A = "Fg.A" } )


This example would Add the R, G and B of image_bg to the R, G and B of image_fg, returning the results to img_out.

img_out = img_bg:ChannelOpOf("Add", img_fg, { R = "Fg.R", G = "Fg.G", B = "Fg.B", A = "Fg.A" })


This example would multiply every pixel in img_bg by the value of blend (in this case 0.5) and return the results to img_out.

blend = 0.5
img_out = img_bg:ChannelOpOf("Multiply", nil, { R = blend, G = blend, B = blend, A = blend })


This example would clip every pixel in img_bg outside the range of 0.2 .. 0.8, scale the remaining pixels to the range of 0 .. 1 and return the results to img_out.

blend = 0.5
img_out = img_bg:ChannelOpOf("Threshold", nil, { R = "bg.r", G = "bg.g", B = "bg.b", A = "bg.a" }, 0.2, 0.8)


Tips for ChannelOpOf (edit)

  • Additional extra channel abbreviations:
PositionX, PositionY, PositionZ
world position channels
DisparityX, DisparityY
(since Fusion 6.31)
  • The channel names are the same as in the Pixel object. They are slightly different from the values for the IMG_Channel attribute when constructing image objects though.
  • Pre-Divide/Post-Multiply functionality can be achieved with these two calls to ChannelOpOf:
img = img:ChannelOpOf("Divide", nil, {R = "bg.a", G = "bg.a", B = "bg.a", A = 1.0})
img = img:ChannelOpOf("Multiply", nil, {R = "bg.a", G = "bg.a", B = "bg.a", A = 1.0})

or, even better, use the following two methods which aren't documented in the Fuse manual but can be found in the C++ SDK:

img:AlphaDivide()
img:AlphaMultiply()

They each take an optional destination Image as the first (and only) argument. With no arguments, or with nil as the first argument, they will operate in-place. Note that these functions only exist as of Fusion 6.0 build 511. They can't be used if you need the fuse to work in earlier versions.

The table does not have to contain all of the channels, just the ones you need to change. You can also skip a channel by setting the it to nil.

img = img:ChannelOpOf("Copy", img_fg, {A = fg.A})
img = img:ChannelOpOf("Multiply", nil, {R = nil, G = nil, B = nil, A = gain})