The first step in most image processing tasks is to load an image
into Octave. This is done using the
imread function, which uses the
GraphicsMagick library for reading. This means a vast number of image
formats is supported. The
imwrite function is the corresponding function
for writing images to the disk.
In summary, most image processing code will follow the structure of this code
I = imread ("my_input_image.img"); J = process_my_image (I); imwrite ("my_output_image.img", J);
Read images from various file formats.
The size and numeric class of the output depends on the format of the image. A color image is returned as an MxNx3 matrix. Gray-level and black-and-white images are of size MxN. The color depth of the image determines the numeric class of the output: "uint8" or "uint16" for gray and color, and "logical" for black and white.
Write images in various file formats.
If fmt is not supplied, the file extension of filename is used to determine the format.
The parameter-value pairs (p1, v1, ...) are optional. Currently the following options are supported for JPEG images:
- Set the quality of the compression. The value should be an integer between 0 and 100, with larger values indicating higher visual quality and lower compression.
Extension Format bmp Windows Bitmap gif Graphics Interchange Format jpg and jpeg Joint Photographic Experts Group pbm Portable Bitmap pcx pgm Portable Graymap png Portable Network Graphics pnm Portable Anymap ppm Portable Pixmap ras Sun Raster tif and tiff Tagged Image File Format xwd X11 Dump
Extension Format hdf Hierarchical Data Format V4 jp2 and jpx Joint Photographic Experts Group 2000
Query or set the internal variable that specifies a colon separated list of directories in which to search for image files.
When called from inside a function with the "local" option, the variable is changed locally for the function and any subroutines it calls. The original variable value is restored when exiting the function.
It is possible to get information about an image file on disk, without actually
reading it into Octave. This is done using the
imfinfo function which
provides read access to many of the parameters stored in the header of the image
Read image information from a file.
imfinforeturns a structure containing information about the image stored in the file filename. The output structure contains the following fields.
- The full name of the image file.
- Number of bytes of the image on disk
- Date of last modification to the file.
- Image height in pixels.
- Image Width in pixels.
- Number of bits per channel per pixel.
- Image format (e.g.,
- Long form image format description.
- X resolution of the image.
- Y resolution of the image.
- Number of unique colors in the image.
- Tile name.
- Time in 1/100ths of a second (0 to 65535) which must expire before displaying the next image in an animated sequence.
- Number of iterations to loop an animation (e.g., Netscape loop extension) for.
- Endian option for formats that support it. Is either
- Gamma level of the image. The same color image displayed on two different workstations may look different due to differences in the display monitor.
trueif the image has transparency.
- Image modulus depth (minimum number of bits required to support red/green/blue components without loss of accuracy).
- JPEG/MIFF/PNG compression level.
- Preferred number of colors in the image.
- Units of image resolution. Is either
"pixels per inch",
"pixels per centimeter", or
- Image type. Is either
- FlashPix viewing parameters.