Pixel data types module
#include "diplib.h"
dip::DataType struct

DataType objects are used to indicate what the data type of an image is.

It is a simple enumeration type, but with some added member functions that can be used to query the data type. A series of constant expressions (dip::DT_XXX) have been defined that should be used when specifying a data type, there is never a need to call the constructors to this class explicitly. It is possible to call DataType member functions on these constants:

dip::DT_BIN.SizeOf();

See Pixel data types for more information about image sample data types.

Constructors, destructors, assignment and conversion operators

DataType() constexpr
The default data type is single-precision Float (dip::DT_SFLOAT).
template<typename T>
DataType(T ) explicit constexpr
Get the data type value of any expression, as long as that expression is of one of the known data types
DataType(dip::String const& name) explicit
A string can be cast to a data type. See Pixel data types for recognized strings.

Aliases

using Classes = dip::detail::Options
Specifies a collection of data types. more...

Functions

void swap(dip::DataType& other) noexcept
Swaps the values of this and other
auto Name() const -> char const*
Returns a C-style string constant with a representation of the data type name. See Pixel data types for returned strings.
auto SizeOf() const -> dip::uint
Returns the size in bytes of the data type.
auto IsInRange(dip::sint value) const -> bool
Returns true if the integer value is within the range representable by the data type.
auto IsInRange(dip::uint value) const -> bool
Returns true if the integer value is within the range representable by the data type.
auto Real() const -> dip::DataType
Returns the real data type corresponding to a complex data type
auto IsA(dip::DataType::Classes cls) const -> bool constexpr
Returns true if the data type is of the given class.
auto IsBinary() const -> bool constexpr
Returns true if the data type is binary.
auto IsUInt() const -> bool constexpr
Returns true if the data type is an unsigned integer type.
auto IsSInt() const -> bool constexpr
Returns true if the data type is a signed integer type.
auto IsInteger() const -> bool constexpr
Returns true if the data type is an integer type.
auto IsFloat() const -> bool constexpr
Returns true if the data type is a floating point type.
auto IsReal() const -> bool constexpr
Returns true if the data type is real (floating point or integer).
auto IsFlex() const -> bool constexpr
Returns true if the data type is one of the “flex” types (floating point or complex).
auto IsFlexBin() const -> bool constexpr
Returns true if the data type is floating point, complex or binary.
auto IsComplex() const -> bool constexpr
Returns true if the data type is complex.
auto IsUnsigned() const -> bool constexpr
Returns true if the data type is an unsigned type (binary or unsigned integer).
auto IsSigned() const -> bool constexpr
Returns true if the data type is a signed type (signed integer, floating point or complex)
static auto SuggestInteger(dip::DataType type) -> dip::DataType
Returns an integer type that is most suitable to hold samples of type. See Pixel data types.
static auto SuggestSigned(dip::DataType type) -> dip::DataType
Returns a signed type that is most suitable to hold samples of type. See Pixel data types.
static auto SuggestFloat(dip::DataType type) -> dip::DataType
Returns a suitable floating-point type that can hold the samples of type. See Pixel data types.
static auto SuggestDouble(dip::DataType type) -> dip::DataType
Returns a suitable double precision floating-point type (real or complex) that can hold large sums of type. See Pixel data types.
static auto SuggestComplex(dip::DataType type) -> dip::DataType
Returns a suitable complex type that can hold the samples of type. See Pixel data types.
static auto SuggestFlex(dip::DataType type) -> dip::DataType
Returns a suitable floating-point or complex type that can hold the samples of type. See Pixel data types.
static auto SuggestFlexBin(dip::DataType type) -> dip::DataType
Returns a suitable floating-point, complex or binary type that can hold the samples of type. See Pixel data types.
static auto SuggestAbs(dip::DataType type) -> dip::DataType
Returns a suitable type that can hold samples of type abs(type). See Pixel data types.
static auto SuggestReal(dip::DataType type) -> dip::DataType
Returns a suitable real type that can hold the samples of type. See Pixel data types.
static auto SuggestArithmetic(dip::DataType type1, dip::DataType type2) -> dip::DataType
Returns a suitable floating-point, complex or binary type (“FlexBin”) that can hold the result of an arithmetic computation performed with the two data types. more...
static auto SuggestDyadicOperation(dip::DataType type1, dip::DataType type2) -> dip::DataType
Returns a suitable type that can hold any samples of the two data types. more...

Operators

auto operator int() const -> int constexpr
DataType objects implicitly convert to the enumeration integer.
auto operator==(dip::DataType other) const -> bool
DataType objects can be compared.
auto operator Classes() const -> dip::DataType::Classes constexpr
Implicit conversion to dip::DataType::Classes options class.

Alias documentation

using Classes = dip::detail::Options

Specifies a collection of data types.

Valid values are:

Classes constant DT_BIN DT_UINT8 DT_SINT8 DT_UINT16 DT_SINT16 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
Class_Bin
Class_UInt8
Class_SInt8
Class_UInt16
Class_SInt16
Class_UInt32
Class_SInt32
Class_UInt64
Class_SInt64
Class_SFloat
Class_DFloat
Class_SComplex
Class_DComplex
Class_Binary
Class_UInt
Class_SInt
Class_Integer
Class_IntOrBin
Class_Float
Class_Complex
Class_Flex
Class_FlexBin
Class_Unsigned
Class_Signed
Class_Real
Class_SignedReal
Class_NonBinary
Class_NonComplex
Class_All

Note that you can add these constants together, for example dip::DataType::Class_UInt8 + dip::DataType::Class_UInt16.

It is possible to see if an image is of a type within a collection using the Contains method of dip::DataType::Classes with a dip::DataType as argument:

if( dip::DataType::Class_Flex.Contains( image.DataType() )) { ... }

But more convenient is to use the dip::DataType::IsA method:

if( image.DataType().IsA( dip::DataType::Class_Flex )) { ... }

This is equivalent to using one of the test functions, if defined for the specific group:

if( image.DataType().IsFlex() ) { ... }

The following combination of classes cover all data types, and are non-intersecting:

  • Class_Unsigned and Class_Signed
  • Class_Complex and Class_NonComplex
  • Class_Binary and Class_NonBinary
  • Class_FlexBin and Class_Integer
  • Class_Flex and Class_IntOrBin
  • Class_Binary, Class_Real and Class_Complex
  • Class_Binary, Class_Integer, Class_Float and Class_Complex

Function documentation

static dip::DataType SuggestArithmetic(dip::DataType type1, dip::DataType type2)

Returns a suitable floating-point, complex or binary type (“FlexBin”) that can hold the result of an arithmetic computation performed with the two data types.

The output value given type1 and type2 is as follows. First the two arguments are promoted using dip::DataType::SuggestFlexBin (which converts 8 and 16-bit integers to DT_SFLOAT and 32 and 64-bit integers to DT_DFLOAT), and the resulting two types are looked up in this table (note that the order of the two inputs is irrelevant, and the table is symmetric):

  DT_BIN DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_BIN DT_BIN DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_DCOMPLEX DT_SCOMPLEX DT_DCOMPLEX
DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX

static dip::DataType SuggestDyadicOperation(dip::DataType type1, dip::DataType type2)

Returns a suitable type that can hold any samples of the two data types.

The output value given type1 and type2 is as follows (note that the order of the two inputs is irrelevant, and the table is symmetric):

  DT_BIN DT_UINT8 DT_SINT8 DT_UINT16 DT_SINT16 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_BIN DT_BIN DT_UINT8 DT_SINT8 DT_UINT16 DT_SINT16 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_UINT8 DT_UINT8 DT_UINT8 DT_SINT16 DT_UINT16 DT_SINT16 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_SINT8 DT_SINT8 DT_SINT16 DT_SINT8 DT_SINT32 DT_SINT16 DT_SINT64 DT_SINT32 DT_SINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_UINT16 DT_UINT16 DT_UINT16 DT_SINT32 DT_UINT16 DT_SINT32 DT_UINT32 DT_SINT32 DT_UINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_SINT16 DT_SINT16 DT_SINT16 DT_SINT16 DT_SINT32 DT_SINT16 DT_SINT64 DT_SINT32 DT_SINT64 DT_SINT64 DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_UINT32 DT_UINT32 DT_UINT32 DT_SINT64 DT_UINT32 DT_SINT64 DT_UINT32 DT_SINT64 DT_UINT64 DT_SINT64 DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SINT32 DT_SINT32 DT_SINT32 DT_SINT32 DT_SINT32 DT_SINT32 DT_SINT64 DT_SINT32 DT_SINT64 DT_SINT64 DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_UINT64 DT_UINT64 DT_UINT64 DT_SINT64 DT_UINT64 DT_SINT64 DT_UINT64 DT_SINT64 DT_UINT64 DT_SINT64 DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_SINT64 DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_SFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_SFLOAT DT_DFLOAT DT_SCOMPLEX DT_DCOMPLEX
DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DFLOAT DT_DCOMPLEX DT_DCOMPLEX
DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_SCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_SCOMPLEX DT_DCOMPLEX DT_SCOMPLEX DT_DCOMPLEX
DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX DT_DCOMPLEX