Image Input and Output
RAVL includes a comprehensive mechanism for reading and writing objects
from and to files in a uniform and transparent fashion. It is based around two
Save. In particular,
there is a set of routines to handle a variety of image file formats, together
with the ability to convert between several different pixel representations.
The generic load/save mechanism is described in Ravl.Core.IO. In order to invoke
the libraries specific to image I/O, you need to:
The generic load/save call can then be used in the usual way.
For an example of how to use the system with
images see exImgIO.cc.
(Remember: to compile this example you'll need the "RavlImageIO" library.)
To find what file formats and conversions are available, use the
conv tool, with the following options:
Here's a summary of currently supported formats. Supported natively
in ravl are:
-lf - list all known file formats
-lc - list all known conversions
-lt - list all known classes (?)
With RavlExtImgIO which uses various open source libraries you also get:
- pgm Grey scale images.
- ppm RGB colour images.
- pbm Bit image
- jpeg Lossy compressed images. Colour and grey scale. (Supports sequences stored in a single file.)
- png Lossless compressed images. Colour and grey scale.
- tiff Lossless compressed images.
Creating image converters
If you wish to load and save your own image type as
pgm or any other file format that is already supported, and the
particular conversion you want is not currently available, it is
straightforward to add one to the collection (currently in
Ravl/Image/ImageIO/ImgTypeCnv.cc). Following is an example for
converting a byte image into a double image. For more information on writing
converters see Ravl.Core.IO
ImageC< RealT> DPConvImageCT2RealImageCT(const ImageC< ByteT> &dat)
ImageC< RealT> ret(dat.Rectangle());
for(Array2dIter2C< RealT,ByteT> it(ret,dat);it;it++)
it.Data1() = (RealT) it.Data2();
The argument in the function call indicates (as a ratio of the
number of bytes in the respective pixels) the amount of
information lost in the conversion. In this example, no
information is lost, so the ratio is 1. For double to char
conversion, the ration would be 8.