< Previous | Contents | Next >

Creating Pixel Functions

Functions are defined to access 2 or more images on a pixel by pixel basis. p1 is the pixel of image 1, p2 is pixels from image 2. This Example uses a Function table to define 5 different functions and a simple drop down menu to select which function is processing.


--Function table for operations p1 is a pixel from image1 and p2 is a pixel from image2

op_funcs =

{

[1] = function(x,y,p1,p2) -- min

p1.R = math.min(p1.R, p2.R) p1.G = math.min(p1.G, p2.G) p1.B = math.min(p1.B, p2.B) p1.A = math.min(p1.A, p2.A) return p1

end,

[2] = function(x,y,p1,p2) -- max

p1.R = math.max(p1.R, p2.R) p1.G = math.max(p1.G, p2.G) p1.B = math.max(p1.B, p2.B) p1.A = math.max(p1.A, p2.A) return p1

end,

[3] = function(x,y,p1,p2) -- add

p1.R = p1.R + p2.R p1.G = p1.G + p2.G p1.B = p1.B + p2.B p1.A = p1.A + p2.A

return p1

end,

[4] = function(x,y,p1,p2)

-- Variables. any number of variables can be named and passed to the function

p1.R = gain * (p1.R - p2.R) p1.G = p1.G - p2.G - bright p1.B = var_C * (p1.B - p2.B) p1.A = p1.A - p2.A

return p1

end,

-- Copy Img2 RGB to Background and Normals Aux channels of img1

-- This is the all the channels available

-- R, G, B, A, BgR, BgG, BgB, BgA, Z, Coverage, ObjectID, MaterialID, U, V, W, NX, NY, NZ

-- VectorX, VectorY, BackVectorX, BackVectorY, DisparityX, DisparityY,

PositionX, PositionY, PositionZ

[5] = function(x,y,p1,p2)

p1.R = p1.R p1.G = p1.G p1.B = p1.B p1.A = p1.A p1.BgR = p2.R p1.BgG = p2.G p1.BgB = p2.B p1.BgA = p2.A

return p1

end,

}