< Previous | Contents | Next >
Editing the Matrix
Sometimes it is necessary to manipulate the matrix directly. Each matrix object exposes individual elements as properties. To access the first element in the first row, we would use the property matrix. n11, the second element would be matrix.n21, then matrix.n31 and so on. This is best demonstrated by the following code, which would print a table of all the elements in a 4x4 ColorMatrix, organized as in our examples above.
m = ColorMatrix() | "b", | "1") | |||
print("", | "r", "g", | ||||
print("R", | m.n11, | m.n21, | m.n31, | m.n41) | |
print("G", print("B", | m.n12, m.n13, | m.n22, m.n23, | m.n32, m.n33, | m.n42) m.n43) | |
print("A", | m.n14, | m.n24, | m.n34, | m.n44) | |
![]()

function CopyColorMatrix(m)
local new_m = ColorMatrix()
new_m.n11 = m.n11 new_m.n21 = m.n21 new_m.n31 = m.n31 new_m.n41 = m.n41 new_m.n12 = m.n12 new_m.n22 = m.n22 new_m.n32 = m.n32 new_m.n42 = m.n42 new_m.n13 = m.n13 new_m.n23 = m.n23 new_m.n33 = m.n33 new_m.n43 = m.n43
return new_m
end
The following function could be used to copy a ColorMatrix.
The following could be used to apply a gain of 0.5 to each pixel in an image.
local img = InImg:GetValue(req)
m = ColorMatrix()
m.n41 = 0.5
m.n42 = 0.5
m.n43 = 0.5