libcvd
Classes | Functions
Image loading and saving, and format conversion

Functions to support saving and loading of BasicImage and Image to and from streams. More...

Classes

struct  CVD::IsConvertible< In, Out >
 Can two types be converted with CVD::convert_image? More...
 
struct  CVD::PixelByPixelConvertible< In, Out >
 Can individual pixels of two types be converted with ConvertPixels::convert()? E.g. More...
 
struct  CVD::Pixel::DefaultConvertible< C >
 All pixel types which are DefaultConvertible can be converted freely from one to another. More...
 
class  CVD::Parameter< C >
 Class for holding parameters for image savers, with type erasure. More...
 

Functions

template<>
void CVD::convert_image (const BasicImage< bayer_bggr > &from, BasicImage< byte > &to)
 Convert Bayer pattern of various forms to greyscale data. More...
 
template<>
void CVD::convert_image (const BasicImage< bayer_bggr > &from, BasicImage< Rgb< byte >> &to)
 Convert Bayer pattern of various forms to rgb data. More...
 
template<>
void CVD::convert_image (const BasicImage< bayer_bggr16 > &from, BasicImage< unsigned short > &to)
 Convert 16bit Bayer pattern of various forms to greyscale data. More...
 
template<>
void CVD::convert_image (const BasicImage< bayer_bggr16 > &from, BasicImage< Rgb< unsigned short >> &to)
 Convert 16bit Bayer pattern of various forms to rgb data. More...
 
template<>
void CVD::convert_image (const BasicImage< bayer_bggr16be > &from, BasicImage< unsigned short > &to)
 Convert 16bit big endian Bayer pattern of various forms to greyscale data. More...
 
template<>
void CVD::convert_image (const BasicImage< bayer_bggr16be > &from, BasicImage< Rgb< unsigned short >> &to)
 Convert 16bit big endian Bayer pattern of various forms to rgb data. More...
 
template<>
void CVD::convert_image (const BasicImage< yuv422 > &from, BasicImage< Rgb< byte >> &to)
 Convert YUV 411 pixel data to RGB. More...
 
template<>
void CVD::convert_image (const BasicImage< yuv422 > &from, BasicImage< byte > &to)
 Convert YUV 422 pixel data to Y only. More...
 
template<>
void CVD::convert_image (const BasicImage< vuy422 > &from, BasicImage< Rgb< byte >> &to)
 Convert YUV 411 pixel data to both Y and RGB. More...
 
template<>
void CVD::convert_image (const BasicImage< vuy422 > &from, BasicImage< byte > &to)
 Convert VUY 422 pixel data to Y only. More...
 
template<>
void CVD::convert_image (const BasicImage< yuv420p > &from, BasicImage< Rgb< byte >> &to)
 Convert YUV420p pixel data to RGB. More...
 
template<>
void CVD::convert_image (const BasicImage< yuv420p > &from, BasicImage< byte > &to)
 Convert YUV420p pixel data to Y only. More...
 
template<class D , class Conv , class C >
Image< D > CVD::convert_image (const BasicImage< C > &from)
 Convert an image from one type to another using a specified conversion. More...
 
template<class D , class C >
Image< D > CVD::convert_image (const BasicImage< C > &from)
 Convert an image from one type to another using the default. More...
 
template<class D1 , class D2 , class C >
std::pair< Image< D1 >, Image< D2 > > CVD::convert_image_pair (const BasicImage< C > &from)
 Convert an image from one type to another using the default, returning a pair of images. More...
 
template<class PixelType >
void CVD::img_save (const BasicImage< PixelType > &im, std::ostream &o, ImageType::ImageType t, const std::map< std::string, Parameter<>> &p=std::map< std::string, Parameter<>>())
 Save an image to a stream. More...
 
template<class PixelType >
void CVD::pnm_save (const BasicImage< PixelType > &im, std::ostream &o)
 Save an image to a stream as a PNM. More...
 
template<class PixelType >
void CVD::pnm_load (Image< PixelType > &im, std::istream &i)
 Load a PNM image from a stream. More...
 
void CVD::output_eps_footer (std::ostream &o)
 Outputs an EPS footer to an ostream. More...
 
void CVD::output_eps_header (std::ostream &o, int xs, int ys)
 Outputs an EPS header to an ostream. More...
 
void CVD::output_eps_header (std::ostream &o, const ImageRef &s)
 Outputs an EPS header to an ostream. More...
 
template<class PixelType >
void CVD::output_eps_header (std::ostream &o, const BasicImage< PixelType > &im)
 Outputs an EPS header to an ostream. More...
 
template<class S , class T >
void CVD::copy (const BasicImage< S > &in, BasicImage< T > &out, ImageRef size=ImageRef(-1, -1), ImageRef begin=ImageRef(), ImageRef dst=ImageRef())
 Generic image copy function for copying sub rectangles of images into other images. More...
 

Detailed Description

Functions to support saving and loading of BasicImage and Image to and from streams.

Supports a few common file formats (autodetecting on loading). Also functions for perfoming type conversion as necessary.

Function Documentation

◆ convert_image() [1/14]

template<>
void CVD::convert_image ( const BasicImage< bayer_bggr > &  from,
BasicImage< byte > &  to 
)

Convert Bayer pattern of various forms to greyscale data.

Parameters
fromThe input data
toThe output data

◆ convert_image() [2/14]

template<>
void CVD::convert_image ( const BasicImage< bayer_bggr > &  from,
BasicImage< Rgb< byte >> &  to 
)

Convert Bayer pattern of various forms to rgb data.

Parameters
fromThe input data
toThe output data

◆ convert_image() [3/14]

template<>
void CVD::convert_image ( const BasicImage< bayer_bggr16 > &  from,
BasicImage< unsigned short > &  to 
)

Convert 16bit Bayer pattern of various forms to greyscale data.

Parameters
fromThe input data
toThe output data

◆ convert_image() [4/14]

template<>
void CVD::convert_image ( const BasicImage< bayer_bggr16 > &  from,
BasicImage< Rgb< unsigned short >> &  to 
)

Convert 16bit Bayer pattern of various forms to rgb data.

Parameters
fromThe input data
toThe output data

◆ convert_image() [5/14]

template<>
void CVD::convert_image ( const BasicImage< bayer_bggr16be > &  from,
BasicImage< unsigned short > &  to 
)

Convert 16bit big endian Bayer pattern of various forms to greyscale data.

Parameters
fromThe input data
toThe output data

◆ convert_image() [6/14]

template<class D , class Conv , class C >
Image< D > CVD::convert_image ( const BasicImage< C > &  from)

Convert an image from one type to another using a specified conversion.

Parameters
DThe destination image pixel type
CThe source image pixel type
ConvThe conversion to use
fromThe image to convert from

◆ convert_image() [7/14]

template<>
void CVD::convert_image ( const BasicImage< bayer_bggr16be > &  from,
BasicImage< Rgb< unsigned short >> &  to 
)

Convert 16bit big endian Bayer pattern of various forms to rgb data.

Parameters
fromThe input data
toThe output data

◆ convert_image() [8/14]

template<class D , class C >
Image<D> CVD::convert_image ( const BasicImage< C > &  from)

Convert an image from one type to another using the default.

Parameters
DThe destination image pixel type
CThe source image pixel type
fromThe image to convert from

◆ convert_image() [9/14]

template<>
void CVD::convert_image ( const BasicImage< yuv422 > &  from,
BasicImage< Rgb< byte >> &  to 
)

Convert YUV 411 pixel data to RGB.

Parameters
fromThe input data
toThe output dataConvert YUV 411 pixel data to Y only
fromThe input data
toThe output dataConvert YUV 422 pixel data to RGB
fromThe input data
toThe output data

◆ convert_image() [10/14]

template<>
void CVD::convert_image ( const BasicImage< yuv422 > &  from,
BasicImage< byte > &  to 
)

Convert YUV 422 pixel data to Y only.

Parameters
fromThe input data
toThe output data

◆ convert_image() [11/14]

template<>
void CVD::convert_image ( const BasicImage< vuy422 > &  from,
BasicImage< Rgb< byte >> &  to 
)

Convert YUV 411 pixel data to both Y and RGB.

Parameters
fromThe input dataConvert VUY 422 pixel data to RGB
fromThe input data
toThe output data

◆ convert_image() [12/14]

template<>
void CVD::convert_image ( const BasicImage< vuy422 > &  from,
BasicImage< byte > &  to 
)

Convert VUY 422 pixel data to Y only.

Parameters
fromThe input data
toThe output data

◆ convert_image() [13/14]

template<>
void CVD::convert_image ( const BasicImage< yuv420p > &  from,
BasicImage< Rgb< byte >> &  to 
)

Convert YUV420p pixel data to RGB.

Parameters
fromThe input data
toThe output data

◆ convert_image() [14/14]

template<>
void CVD::convert_image ( const BasicImage< yuv420p > &  from,
BasicImage< byte > &  to 
)

Convert YUV420p pixel data to Y only.

Parameters
fromThe input data
toThe output data

◆ convert_image_pair()

template<class D1 , class D2 , class C >
std::pair<Image<D1>, Image<D2> > CVD::convert_image_pair ( const BasicImage< C > &  from)

Convert an image from one type to another using the default, returning a pair of images.

Parameters
D1The first destination image pixel type
D2The second destination image pixel type
CThe source image pixel type
fromThe image to convert from

◆ copy()

template<class S , class T >
void CVD::copy ( const BasicImage< S > &  in,
BasicImage< T > &  out,
ImageRef  size = ImageRef(-1, -1),
ImageRef  begin = ImageRef(),
ImageRef  dst = ImageRef() 
)

Generic image copy function for copying sub rectangles of images into other images.

This performs pixel type conversion if the input and output images are different pixel types.

Parameters
ininput image to copy from
outoutput image to copy into
sizesize of the area to copy. By default this is the entirty of the input image
beginupper left corner of the area to copy, by default the upper left corner of the input image
dstupper left corner of the destination in the output image, by default the upper left corner of the output image
Exceptions
ImageRefNotInImageif either begin is not in the input image or dst not in the output image

◆ img_save()

template<class PixelType >
void CVD::img_save ( const BasicImage< PixelType > &  im,
std::ostream &  o,
ImageType::ImageType  t,
const std::map< std::string, Parameter<>> &  p = std::map<std::string, Parameter<>>() 
)

Save an image to a stream.

This function will convert types if necessary.

Parameters
PixelTypeThe pixel type of the image
ConversionThe conversion class to use
imThe image to save
oThe stream
tThe image file format to use (see ImageType::ImageType for a list of supported formats)

◆ output_eps_footer()

void CVD::output_eps_footer ( std::ostream &  o)

Outputs an EPS footer to an ostream.

Parameters
othe ostream

◆ output_eps_header() [1/3]

void CVD::output_eps_header ( std::ostream &  o,
int  xs,
int  ys 
)

Outputs an EPS header to an ostream.

Typical use is to output the header, save a raw PS image, output some other PS (eg annotations) and the output the EPS footer.

Parameters
othe ostream
xsthe width of the image
ysthe height of the image

◆ output_eps_header() [2/3]

void CVD::output_eps_header ( std::ostream &  o,
const ImageRef s 
)

Outputs an EPS header to an ostream.

Typical use is to output the header, save a raw PS image, output some other PS (eg annotations) and the output the EPS footer.

Parameters
othe ostream
ssize of the image

◆ output_eps_header() [3/3]

template<class PixelType >
void CVD::output_eps_header ( std::ostream &  o,
const BasicImage< PixelType > &  im 
)

Outputs an EPS header to an ostream.

Typical use is to output the header, save a raw PS image, output some other PS (eg annotations) and the output the EPS footer.

Parameters
othe ostream
imthe image

◆ pnm_load()

template<class PixelType >
void CVD::pnm_load ( Image< PixelType > &  im,
std::istream &  i 
)

Load a PNM image from a stream.

Deprecated Use img_load(Image<I>& im, std::istream& i) instead. This can handle and automatically detect other file formats as well.

Loading is simplistic, and automatic conversions of values are performed. So, for instance bytes are assumed to be in the range 0–255 and floats in the range 0–1, so loading bytes in to an Image<float> will result in an image with floats in the range 0–1. In the reverse direction, floats falling outside the range 0–1, will wrap when converted to bytes.

The image loader ignores the data range given by the file, if it is given.

Parameters
PixelTypeThe pixel type of the image
imThe image
iThe stream

◆ pnm_save()

template<class PixelType >
void CVD::pnm_save ( const BasicImage< PixelType > &  im,
std::ostream &  o 
)

Save an image to a stream as a PNM.

Deprecated Use img_save() instead, i.e. img_save(im, o, ImageType::PNM);

Parameters
PixelTypeThe pixel type of the image
imThe image
oThe stream