Class image#
Defined in File image.h
Nested Relationships#
Nested Types#
Class Documentation#
-
class image#
Class used to represent an image.
A class to represent an image, which can be created from a file, a buffer and provided by a window. It provides tools to save and compare images.
Constructors
-
image()#
Default/copy/move constructors/operators.
-
~image()#
Default/copy/move constructors/operators.
Operators
-
bool operator==(const image &reference) const#
Comparison operators, uses image::compare with a threshold of 1e-14.
-
bool operator!=(const image &reference) const#
Comparison operators, uses image::compare with a threshold of 1e-14.
Resolution
-
unsigned int getWidth() const#
Set/Get image resolution.
- Deprecated:
{ setResolution is deprecated, use the appropriate constructor }
-
unsigned int getHeight() const#
Set/Get image resolution.
- Deprecated:
{ setResolution is deprecated, use the appropriate constructor }
Channel Count
-
unsigned int getChannelCount() const#
Set/Get image channel count.
- Deprecated:
{ setChannelCount is deprecated, use the appropriate constructor }
Buffer Data
-
image &setContent(void *buffer)#
Set/Get image buffer data. Its size is expected to be
width * height * channelCount * typeSize
.- Deprecated:
{ setData and getData are deprecated, use setContent and getContent instead }
-
void *getContent() const#
Set/Get image buffer data. Its size is expected to be
width * height * channelCount * typeSize
.- Deprecated:
{ setData and getData are deprecated, use setContent and getContent instead }
Public Types
Public Functions
-
explicit image(const std::string &path)#
Create an image from file, the following formats are supported: PNG, PNM, TIFF, BMP, HDR, JPEG, GESigna, MetaImage, TGA. EXR files are also supported if the associated module is built. The complete list can be retrieve at runtime by calling
getSupportedFormats()
. Throw animage::read_exception
in case of failure.
-
image(unsigned int width, unsigned int height, unsigned int channelCount, ChannelType type = ChannelType::BYTE)#
Create an image from a given width, height, and channel count. A channel type can also be given. Default is BYTE.
-
std::vector<double> getNormalizedPixel(const std::pair<int, int> &xy) const#
Read one specific pixel and return all channel normalized values. If the channel type is BYTE or SHORT, the values are normalized to [0, 1] range.
Warning
Because of the normalization, this function can be slow, prefer getContent when reading several pixels and normalization is not needed.
-
ChannelType getChannelType() const#
Get image channel type. throw an
image::read_exception
if the type is unknown.
-
unsigned int getChannelTypeSize() const#
Get image channel type size in bytes.
-
bool compare(const image &reference, double threshold, double &error) const#
Compare current image to a reference using the provided threshold. If the comparison fails, ie. error is higher than the threshold, this outputs the resulting diff and error and return false, return true otherwise. The error is minimum between Minkownski and Wasserstein distance on a SSIM computation, as specified in VTK. Please note, due to possible arithmetic imprecision in the SSIM computation using a threshold of zero may return false with identical images. Depending on the VTK version, another comparison algorithm may be used. 1e-14: Pixel perfect comparison. 0.05: Visually indistinguishable. 0.1: Small visible difference. 0.5: Comparable images. 1.0: Different type, size or number of components
-
void save(const std::string &path, SaveFormat format = SaveFormat::PNG) const#
Save an image to a file in the specified format. Default format is PNG if not specified. PNG: Supports channel type BYTE and SHORT with channel count of 1 to 4 JPG: Supports channel type BYTE with channel count of 1 or 3 TIF: Supports channel type BYTE, SHORT and FLOAT with channel count of 1 to 4 BMP: Supports channel type BYTE with channel count of 1 to 4 Throw an
image::write_exception
if the format is incompatible with with image channel type or channel count
-
std::vector<unsigned char> saveBuffer(SaveFormat format = SaveFormat::PNG) const#
Save an image to a memory buffer in the specified format. Default format is PNG if not specified. PNG: Supports channel type BYTE and SHORT with channel count of 1 to 4 JPG: Supports channel type BYTE with channel count of 1 or 3 BMP: Supports channel type BYTE with channel count of 1 to 4 TIF format is not supported yet. Throw an
image::write_exception
if the type is TIF or if the format is incompatible with with image channel type or channel count.
-
const f3d::image &toTerminalText(std::ostream &stream) const#
Convert to colored text using ANSI escape sequences for printing in a terminal. Block and half-block characters are used to represent two pixels per character (vertically) meaning that each text line represent two rows of pixels. Byte encoded RGB and RGBA images are supported (alpha channel values are binarized). Assumes terminal support for:
unicode block characters (
U+2580
,U+2584
,U+2588
)SGR escape codes (
ESC[0m
,ESC[49m
)24-bit escape codes (
ESC[38;2;{r};{g};{b}m
,ESC[48;2;{r};{g};{b}m
) Throw aimage::write_exception
if the type is not byte RGB or RGBA.
-
std::string toTerminalText() const#
Convert to colored text using ANSI escape sequences for printing in a terminal. See
toTerminalText(std::ostream& stream)
. Throw aimage::write_exception
if the type is not byte RGB or RGBA.
-
f3d::image &setMetadata(const std::string &key, const std::string &value)#
Set the value for a metadata key. Setting an empty value (
""
) removes the key.
-
std::string getMetadata(const std::string &key) const#
Get the value for a metadata key. Throw a
image::read_exception
if key does not exist.
-
std::vector<std::string> allMetadata() const#
List all the metadata keys which have a value set.
Public Static Functions
-
static std::vector<std::string> getSupportedFormats()#
Get the list of supported image format extensions when opening a file.
-
struct metadata_exception : public f3d::exception#
An exception that can be thrown by the image. when there is an error related to metadata
Public Functions
-
explicit metadata_exception(const std::string &what = "")#
-
explicit metadata_exception(const std::string &what = "")#
-
image()#