### 28.1.2 Creating and loading images

The image command creates image objects from files or data.

- image accepts either a string filename from which the image is loaded or two mandatory arguments for creating images from data:
  - n, a positive integer in {1,2,3,4}.
  - data, a sequence of numeric matrices of the same size which contain the channel data. Each matrix must have integral values between 0 and 255, representing 8-bit color values.
- image(filename) or image(n,data) returns the corresponding image object.
- The parameter n represents the color type of the image (1 – grayscale image, 2 – grayscale image with alpha channel, 3 – RGB image, 4 – RGBA image).
- If the number of matrices in data is smaller than n, then it can be either:
  - 1, for writing the same data to all color channels and 255 to the alpha channel if there is one.
  - 2, for writing the same data from the first matrix to all color channels and the values from the second matrix to the alpha channel (this requires n∈{2,4}).
  - 3, for writing the data to R, G, and B channels and the value 255 to the alpha channel.

#### Examples

img:=image("/usr/local/share/giac/doc/logo.png")

an image of size 64×64 (RGBA) |  |  |  |  |  |  |  |  |  |

The command lines below create a simple noisy grayscale image with n× n pixels.

n:=200:; p:=(j,k)->round(max(0,min(255,1000*((j-n/2)^2+(k-n/2)^2)/n^2+randnorm(0,10)))):; data:=matrix(n,n,p):; img:=image(1,data)

an image of size 200×200 (grayscale) |  |  |  |  |  |  |  |  |  |

display(inv(img))

We are displaying the negative image (inv is applied) to have an impression of a square-shaped picture.