Thea
Public Member Functions | Static Public Member Functions | List of all members
Image Class Reference

A 2D image. More...

#include <Image.hpp>

Inheritance diagram for Image:
IImage Serializable

Public Member Functions

fipImage const * _getFreeImage () const
 [Internal use only] Get the wrapped FreeImage bitmap. More...
 
fipImage * _getFreeImage ()
 [Internal use only] Get the wrapped FreeImage bitmap. More...
 
void _setType (Type type_)
 [Internal use only] Set the type of the image. More...
 
int8 clear ()
 Destroy all image data, resetting the image to an invalid state. More...
 
bool convert (Type dst_type)
 Convert this image to a different format. More...
 
bool convert (Type dst_type, Image &dst) const
 Convert an image from one format to another. More...
 
int getBitsInChannel (int channel) const
 Get the number of bits assigned to a particular channel. More...
 
int getBitsPerChannel () const
 Get the number of bits assigned to each channel. More...
 
int getBitsPerPixel () const
 Get the number of bits assigned to each pixel. More...
 
void const * getData () const
 Get a pointer to the image data. More...
 
void * getData ()
 Get a pointer to the image data. More...
 
int64 getDepth () const
 Get the depth of the image in pixels. More...
 
int64 getHeight () const
 Get the height of the image in pixels. More...
 
double getNormalizedValue (void const *pixel, int channel) const
 Get the value of a channel of a particular pixel, normalized to the range [0, 1]. More...
 
int32 getRowAlignment () const
 Get the byte alignment of a pixel row. More...
 
void const * getScanLine (int64 row, int64 z=0) const
 Get a pointer to the beginning of a specified row of pixels, optionally for a specific depth slice. More...
 
void * getScanLine (int64 row, int64 z=0)
 Get a pointer to the beginning of a specified row of pixels, optionally for a specific depth slice. More...
 
int64 getScanWidth () const
 Get the number of bytes consumed by a row of pixels. More...
 
int32 getType () const
 Get the type of the image pixels, corresponding to one of the values of the Type enum class. More...
 
int64 getWidth () const
 Get the width of the image in pixels. More...
 
bool hasByteAlignedChannels () const
 Check if all pixel channels are aligned to byte addresses. More...
 
bool hasByteAlignedPixels () const
 Check if the image pixels start at byte addresses. More...
 
 Image ()
 Construct an empty image with no initial data. More...
 
 Image (Type type_, int64 width_, int64 height_, int64 depth_=1)
 Construct an uninitialized image of the specified type and pixel dimensions, which must have valid non-zero values. More...
 
 Image (BinaryInputStream &input, Codec const &codec=CodecAuto(), bool read_block_header=false)
 Construct an image by deserializing it from an input stream. More...
 
 Image (std::string const &path, Codec const &codec=CodecAuto())
 Construct an image by loading it from a file. More...
 
bool invert ()
 Invert the pixel values of the image. More...
 
bool isComplex () const
 Check if the channels hold complex (as opposed to real) values. More...
 
bool isFloatingPoint () const
 Check if the channels hold floating-point values (at any precision). More...
 
int8 isValid () const
 Check if the image has been allocated non-zero memory space (hence has valid type and dimensions) or not. More...
 
void load (std::string const &path, Codec const &codec=CodecAuto())
 Load the image from an image file. More...
 
int numChannels () const
 Get the number of channels per pixel. More...
 
virtual void read (TextInputStream &input, Codec const &codec=CodecAuto())
 Read the object from a text input stream. More...
 
void read (BinaryInputStream &input, Codec const &codec=CodecAuto(), bool read_block_header=false)
 Read the object from a binary input stream. More...
 
bool rescale (int64 new_width, int64 new_height, int64 new_depth=1, Filter filter=Filter::AUTO)
 Rescale the image to a new width and height. More...
 
int8 resize (int64 type, int64 width_, int64 height_, int64 depth_=1)
 Resize the image, changing its type and dimensions. More...
 
void save (std::string const &path, Codec const &codec=CodecAuto()) const
 Save the image to an image file. More...
 
virtual void write (TextOutputStream &output, Codec const &codec=CodecAuto()) const
 Write the object to a text output stream. More...
 
void write (BinaryOutputStream &output, Codec const &codec=CodecAuto(), bool write_block_header=false) const
 Write the object to a binary output stream. More...
 
 ~Image ()
 Destructor. More...
 

Static Public Member Functions

static TextInputStream::Settings const & configReadSettings ()
 Get the default settings for parsing configuration text files. More...
 
static TextOutputStream::Settings const & configWriteSettings ()
 Get the default settings for writing configuration text files. More...
 

Detailed Description

A 2D image.

Definition at line 31 of file Image.hpp.

Constructor & Destructor Documentation

Image ( )

Construct an empty image with no initial data.

Definition at line 643 of file Image.cpp.

Image ( Type  type_,
int64  width_,
int64  height_,
int64  depth_ = 1 
)

Construct an uninitialized image of the specified type and pixel dimensions, which must have valid non-zero values.

Definition at line 649 of file Image.cpp.

Image ( BinaryInputStream input,
Codec const &  codec = CodecAuto(),
bool  read_block_header = false 
)

Construct an image by deserializing it from an input stream.

See also
read()

Definition at line 655 of file Image.cpp.

Image ( std::string const &  path,
Codec const &  codec = CodecAuto() 
)

Construct an image by loading it from a file.

See also
load()

Definition at line 661 of file Image.cpp.

~Image ( )

Destructor.

Definition at line 707 of file Image.cpp.

Member Function Documentation

fipImage const* _getFreeImage ( ) const

[Internal use only] Get the wrapped FreeImage bitmap.

Definition at line 189 of file Image.hpp.

fipImage* _getFreeImage ( )

[Internal use only] Get the wrapped FreeImage bitmap.

Definition at line 192 of file Image.hpp.

void _setType ( Type  type_)

[Internal use only] Set the type of the image.

Definition at line 1036 of file Image.cpp.

int8 clear ( )
virtual

Destroy all image data, resetting the image to an invalid state.

Returns
True on success, false on error.
See also
isValid()

Implements IImage.

Definition at line 720 of file Image.cpp.

static TextInputStream::Settings const& configReadSettings ( )
staticinherited

Get the default settings for parsing configuration text files.

Definition at line 69 of file Serializable.hpp.

static TextOutputStream::Settings const& configWriteSettings ( )
staticinherited

Get the default settings for writing configuration text files.

Definition at line 76 of file Serializable.hpp.

bool convert ( Type  dst_type)

Convert this image to a different format.

Currently only source/target format combinations supported by FreeImage are available.

Definition at line 1061 of file Image.cpp.

bool convert ( Type  dst_type,
Image dst 
) const

Convert an image from one format to another.

Currently only source/target format combinations supported by FreeImage are available.

Definition at line 1067 of file Image.cpp.

int getBitsInChannel ( int  channel) const

Get the number of bits assigned to a particular channel.

For luminance images, the single channel is assumed to correspond to the enum value Channel::ALPHA. If the image doesn't contain the specific channel (e.g. luminance images don't have red, green or blue channels) a value of zero is returned.

Definition at line 115 of file Image.hpp.

int getBitsPerChannel ( ) const

Get the number of bits assigned to each channel.

Returns -1 if the channels don't all have the same number of bits.

This returns a cached value and is likely to be faster than calling the equivalent function in Image::Type.

Definition at line 108 of file Image.hpp.

int getBitsPerPixel ( ) const

Get the number of bits assigned to each pixel.

This returns a cached value and is likely to be faster than calling the equivalent function in Image::Type.

Definition at line 101 of file Image.hpp.

void const * getData ( ) const
virtual

Get a pointer to the image data.

Implements IImage.

Definition at line 786 of file Image.cpp.

void * getData ( )
virtual

Get a pointer to the image data.

Implements IImage.

Definition at line 792 of file Image.cpp.

int64 getDepth ( ) const
virtual

Get the depth of the image in pixels.

Reimplemented from IImage.

Definition at line 71 of file Image.hpp.

int64 getHeight ( ) const
virtual

Get the height of the image in pixels.

Implements IImage.

Definition at line 70 of file Image.hpp.

double getNormalizedValue ( void const *  pixel,
int  channel 
) const

Get the value of a channel of a particular pixel, normalized to the range [0, 1].

The following caveats should be noted:

  • Signed integer channels are scaled to the range [-1, 1). E.g. Type::LUMINANCE_16 natively stores values in the range [-32768, 32767], which is mapped to [1, 1) by dividing by 32768.
  • Floating point channels are assumed to be pre-normalized and no further normalization is done.
  • For complex channels, the function returns the magnitude of the complex number.
  • For single-channel images, the luminance is extracted with Channel::ALPHA.

This is a relatively slow way to iterate over pixel values and is provided only for convenience.

This function does not support channels smaller than a byte (e.g. Type::LUMINANCE_1U), and returns a value of zero for such images.

Definition at line 801 of file Image.cpp.

int32 getRowAlignment ( ) const
virtual

Get the byte alignment of a pixel row.

Each row is padded to take up a number of bytes which is a multiple of the alignment value.

Implements IImage.

Definition at line 877 of file Image.cpp.

void const * getScanLine ( int64  row,
int64  z = 0 
) const
virtual

Get a pointer to the beginning of a specified row of pixels, optionally for a specific depth slice.

Implements IImage.

Definition at line 841 of file Image.cpp.

void * getScanLine ( int64  row,
int64  z = 0 
)
virtual

Get a pointer to the beginning of a specified row of pixels, optionally for a specific depth slice.

Implements IImage.

Definition at line 847 of file Image.cpp.

int64 getScanWidth ( ) const
virtual

Get the number of bytes consumed by a row of pixels.

Rows may be aligned to 32-bit (or other) boundaries for performance reasons, so this is not necessarily equal to the number of pixels in a row times the size of a pixel.

Implements IImage.

Definition at line 868 of file Image.cpp.

int32 getType ( ) const
virtual

Get the type of the image pixels, corresponding to one of the values of the Type enum class.

Implements IImage.

Definition at line 72 of file Image.hpp.

int64 getWidth ( ) const
virtual

Get the width of the image in pixels.

Implements IImage.

Definition at line 69 of file Image.hpp.

bool hasByteAlignedChannels ( ) const

Check if all pixel channels are aligned to byte addresses.

This returns a cached value and is likely to be faster than calling the equivalent function in Image::Type.

Definition at line 129 of file Image.hpp.

bool hasByteAlignedPixels ( ) const

Check if the image pixels start at byte addresses.

For example, RGB_8U does, but LUMINANCE_1U does not.

This returns a cached value and is likely to be faster than calling the equivalent function in Image::Type.

Definition at line 122 of file Image.hpp.

bool invert ( )

Invert the pixel values of the image.

Definition at line 1055 of file Image.cpp.

bool isComplex ( ) const

Check if the channels hold complex (as opposed to real) values.

This returns a cached value and is likely to be faster than calling the equivalent function in Image::Type.

Definition at line 87 of file Image.hpp.

bool isFloatingPoint ( ) const

Check if the channels hold floating-point values (at any precision).

This returns a cached value and is likely to be faster than calling the equivalent function in Image::Type.

Definition at line 94 of file Image.hpp.

int8 isValid ( ) const
virtual

Check if the image has been allocated non-zero memory space (hence has valid type and dimensions) or not.

An image created by the default constructor is invalid and must be further initialized using Image::read() or a similar function.

Implements IImage.

Definition at line 713 of file Image.cpp.

void load ( std::string const &  path,
Codec const &  codec = CodecAuto() 
)

Load the image from an image file.

The file should not have a prefixed Codec::BlockHeader. An exception will be thrown if the image cannot be loaded.

Definition at line 958 of file Image.cpp.

int numChannels ( ) const

Get the number of channels per pixel.

For example: 1 for luminance, 3 for RGB, 4 for RGBA. A complex number corresponds to a single channel (not two). Returns -1 if the image is of unknown type.

This returns a cached value and is likely to be faster than calling the equivalent function in Image::Type.

Definition at line 80 of file Image.hpp.

virtual void read ( TextInputStream input,
Codec const &  codec = CodecAuto() 
)
virtualinherited

Read the object from a text input stream.

Reimplemented in Pyramid3d, KMeans, Pyramid2d, HoughForest::Options, BagOfWords, KMeans::Options, and Pyramid1d.

Definition at line 61 of file Serializable.hpp.

void read ( BinaryInputStream input,
Codec const &  codec = CodecAuto(),
bool  read_block_header = false 
)
virtual

Read the object from a binary input stream.

Parameters
inputThe stream from which to read data.
codecThe codec to use. If set to CodecAuto(), the codec will be autodetected (if possible) from the input.
read_block_headerIf true, a Codec::BlockHeader object containing information about the codec and size of the serialized block will be first read from the input, and used to aid codec detection etc. The implementation is free to ignore this directive, e.g. if the codec and input size can be detected through other means. This behavior must be synchronized with write(BinaryOutputStream &, Codec const &, bool): either both must omit block headers, or both must read/write them if directed to do so.

Implements Serializable.

Definition at line 927 of file Image.cpp.

bool rescale ( int64  new_width,
int64  new_height,
int64  new_depth = 1,
Filter  filter = Filter::AUTO 
)

Rescale the image to a new width and height.

Definition at line 902 of file Image.cpp.

int8 resize ( int64  type,
int64  width,
int64  height,
int64  depth = 1 
)
virtual

Resize the image, changing its type and dimensions.

All previous image data is discarded. type should be one of the Type values.

Returns
True on success, false on error.

Implements IImage.

Definition at line 737 of file Image.cpp.

void save ( std::string const &  path,
Codec const &  codec = CodecAuto() 
) const

Save the image to an image file.

The file will not have a prefixed Codec::BlockHeader. An exception will be thrown if the image cannot be saved.

Definition at line 969 of file Image.cpp.

virtual void write ( TextOutputStream output,
Codec const &  codec = CodecAuto() 
) const
virtualinherited

Write the object to a text output stream.

Reimplemented in Pyramid3d, KMeans, Pyramid2d, HoughForest::Options, BagOfWords, KMeans::Options, and Pyramid1d.

Definition at line 65 of file Serializable.hpp.

void write ( BinaryOutputStream output,
Codec const &  codec = CodecAuto(),
bool  write_block_header = false 
) const
virtual

Write the object to a binary output stream.

Parameters
outputThe stream to which data will be written.
codecThe codec to use. If set to CodecAuto(), an appropriate codec will be automatically selected.
write_block_headerIf true, a Codec::BlockHeader object containing information about the codec and size of the serialized block will be first written to the input. The implementation is free to ignore this directive, e.g. if the codec and input size are encoded through other means. This behavior must be synchronized with read(BinaryInputStream &, Codec const &, bool): either both must omit block headers, or both must read/write them if directed to do so.

Implements Serializable.

Definition at line 942 of file Image.cpp.


The documentation for this class was generated from the following files: