CImage:Array


The Array method extracts the pixel data from a CImage into a lua array (table).

Syntax

tArray = CImage:Array()

where

    tArray is a lua array (table) containing all the pixel values of the image.

Example 1

The following script creates a CImage from a 1-dimensional table, subtracts 0.5 from every element of the table, and then uses the Array method to save the results back into the table:

t = { 1, 3, 5, 7, 9 }

-- make an array (lua table) of data

I = CImage:newarray( t )

-- create a new CImage object

I = I - 0.5

-- subtract 0.5 from every pixel (array element)

t = I:Array()

-- save to the table

for i,v in pairs( t ) do

-- loop over every table element

  Printf("%d:%lg, ", i,v )

-- Print each member

end

-- result: 1:0.5, 2:2.5, 3:4.5, 4:6.5, 5:8.5

Note that the for loop can be compacted to be: for i,v in pairs( I:Array() ) do. However in this form, note that the data are not stored because the lua table is not explicitly assigned.

Related Topics

newarray

Math Operators

CImage class