en fr

Sysquake Pro – Table of Contents

Sysquake – Table of Contents

Sysquake for LaTeX – Table of Contents

Image I/O

This section describes functions which offer support for reading and writing image files. Formats supported include PNG and JPEG.

Calerga gratefully acknowledges the following contributions: PNG encoding and decoding are based on libpng; and JPEG encoding and decoding are based on the work of the Independent JPEG Group.

Functions

imageread

Read an image file.

Syntax

A = imageread(fd)
A = imageread(fd, options)

Description

imageread(fd) reads a PNG or JPEG file from file descriptor fd and returns it as an array whose first dimension is the image height and second dimension the image width. Grayscale images have a third dimension equal to 1 (i.e. plain matrices). Color images have a third dimension equal to 3; fist plane is the red component, second plane the green component, and third plane the blue component. By default, the result is a uint8 or uint16 array whose type matches the pixel format in the image files. Value range from 0 for black to 255 or 65535 for maximum intensity.

The file descriptor is usually obtained by opening a file with fopen in binary mode (text mode, with end-of-line translation, would produce garbage or cause a decoding error).

A second argument can specify special options to modify the result. Options are usually created with function imagereadset, or given directly as named arguments.

Example

fd = fopen('image.png', 'r');
im = imageread(fd);
fclose(fd);

See also

imagereadset, imagewrite

imagereadset

Options for image input.

Syntax

options = imagereadset
options = imagereadset(name1=value1, ...)
options = imagereadset(name1, value1, ...)
options = imagereadset(options0, name1=value1, ...)
options = imagereadset(options0, name1, value1, ...)

Description

imagereadset(name1,value1,...) creates the option argument used by imageread. Options are specified with name/value pairs, where the name is a string which must match exactly the names in the table below. Case is significant. Options which are not specified have a default value. The result is a structure whose fields correspond to each option. Without any input argument, imagereadset creates a structure with all the default options. Note that imageread also interpret the lack of an option argument, or the empty array [], as a request to use the default values.

When its first input argument is a structure, imagereadset adds or changes fields which correspond to the name/value pairs which follow.

Here is the list of permissible options. Currently they are used only when reading PNG files.

NameDefaultMeaning
Scale16falseconvert 16-bit images to uint8
StripAlphatrueignore the alpha channel

Named arguments can be given directly to imageread without calling explicitly imageset.

Examples

Default options:

imagereadset
  Scale16: false
  StripAlpha: true

Reading a PNG file with alpha channel (an RGB+alpha image is an array of size [height, width, 4]):

fd = fopen('image.png');
im = imageread(fd, StripAlpha=false);
fclose(fd);

See also

imageread

imageset

Options for image output.

Syntax

options = imageset
options = imageset(name1=value1, ...)
options = imageset(name1, value1, ...)
options = imageset(options0, name1=value1, ...)
options = imageset(options0, name1, value1, ...)

Description

imageset(name1,value1,...) creates the option argument used by imagewrite. Options are specified with name/value pairs, where the name is a string which must match exactly the names in the table below. Case is significant. Options which are not specified have a default value. The result is a structure whose fields correspond to each option. Without any input argument, imageset creates a structure with all the default options. Note that imagewrite also interpret the lack of an option argument, or the empty array [], as a request to use the default values.

When its first input argument is a structure, imageset adds or changes fields which correspond to the name/value pairs which follow.

Here is the list of permissible options:

NameDefaultMeaning
Type'PNG''PNG' or 'JPG'/'JPEG'
Quality80JPEG quality (0=worst,100=best)
Progressivefalsetrue to permit progressive decoding

Named arguments can be given directly to imagewrite without calling explicitly imageset.

Examples

Default options:

imageset
  Type: 'png'
  Quality: 80
  Progressive: false

Writing the contents of array A into a small, low-quality JPEG file:

fd = fopen('A.jpg', 'w');
imagewrite(fd, A, Type='JPG', Quality=20);
fclose(fd);

See also

imagewrite

imagewrite

Write an image file.

Syntax

imagewrite(fd, A)
imagewrite(fd, A, options)

Description

imagewrite(fd,A) writes array A to a PNG file specified by file descriptor fd. Image A is an array whose first dimension is the image height and second dimension the image width. Grayscale images have their third dimension equal to 1 (i.e. they are plain matrices). Color images have a third dimension equal to 3; fist plane is the red component, second plane the green component, and third plane the blue component. In both cases, value range is 0 for black to 1 for maximum intensity. Values outside this range are clipped.

imagewrite(fd,A,options) uses structure options to specify image file options. Options are usually created with function imageset, or given directly as named arguments; they include the file type.

The file descriptor is usually obtained by opening a file with fopen in binary mode (text mode, with end-of-line translation, would produce a corrupted image file).

Example

Write the image contained in the matrix im to a file "image.png", using the default options.

fd = fopen('image.png', 'w');
imagewrite(fd, im);
fclose(fd);

Write the same image as a JPEG file.

fd = fopen('image.jpg', 'w');
imagewrite(fd, im, Type='JPEG');
fclose(fd);

See also

imageset, imageread