IMWRITE(1)

NAME
imwrite - writes to an image file in ANY format

SYNOPSIS
imwrite(Image, filename, <opt_args>)
imwrite(Index, Map, filename, <opt_args>)

PARAMETERS

filename
    a string, the image filename to be created. The extension determines the type of the image.

Image
    For truecolor images, this is a MxNx3 hypermatrix in 0-65535 range; For binary images or intensity grayscale images, it is a MxNx1 matrix in 0-65535 range.

Index
    MxN matrix containing the indexes to the image colormap (for indexed images). Indices start at 0.

Map Mx3 matrix containing the image colormap (for indexed images). Entries range from 0 to 65535.

<opt_args>
    This is a sequence of statements key1=value1, key2=value2,... where key1, key2,... can be one of the following:
    quality
        sets the quality level for some formats of images that accept this parameter, like JPEG. Ranges from 1 to 100 (default 75).

    In the future, other options may be added, such as dithering and compression type.

DESCRIPTION
imwrite creates BMP, GIF, JPEG, PNG, PCX, TIFF, XPM, and even more types of image files from Scilab elements. The format of the file is inferred from the extension in the filename parameter.

imwrite(Img, filename) creates an image filename in disk, from Img matrix. For truecolor images, Img is a MxNx3 hypermatrix, so for example Img(:,:,1) stands for the red channel. For binary images or intensity grayscale images, Img is a MxNx1 matrix.

imwrite(Index, Map, filename) does the same work, but from Index (MxN) and Map (Mx3) matrices. Grayscale and Paletted images are written in this way.

EXAMPLE
a=int( 255*rand(100,150) );    // create a random image
xbasc();
imshow(a);
imwrite(a*257,'SIPtmp.jpg');   // a*255 is in 0-65535 range
xbasc();
imshow('SIPtmp.jpg');
// now try viewing this image with an ordinary viewer to see
// how it really worked!

REMARKS
In writing a binary image, one has to multiply it by 65535.

The file created by imwrite is not necessarily indexed or truecolor. Commands of the form imwrite(I,M,filename) have a greater chance of creating an indexed image, and imwrite(RGB,filename) have a good chance of creating a truecolor image. However, the final result depends on the characteristics of the image format. For example, JPEG images are always truecolor or grayscale. Typing imwrite(Index,Map,'foo.jpg') will necessarily create a truecolor image. But imwrite(Index,Map,'foo.gif') will certainly create an indexed image.

In theory, imwrite will write to any raster image format. In practice, it has been tested only for BMP, GIF, JPEG, PNG, PCX, TIFF, XPM, and MIFF. Writing to other formats will probably work, but have not been tested by the developers of the SIP toolbox.

BUGS AND SHORTCOMINGS
Images are stored in double precision matrices. Hopefully, the next release will make usage of integer types.

AUTHORS
Ricardo Fabbri <rfabbri@if.sc.usp.br>

AVAILABILITY
The latest version of the Scilab Image Processing toolbox can be found at

    http://cyvision.if.sc.usp.br/~rfabbri/sip/

SEE ALSO
imread, imfinfo, imshow