#include "diplib.h"
Sample class
A sample represents a single numeric value in an image, see Image representation.
Contents
Objects of this class are meant as an interface between images and numbers. These objects are not actually how values are stored in an image, but rather represent a reference to a sample in an image. Through this reference, individual samples in an image can be changed. For example:
dip::Image img( { 256, 256 } ); img.At( 10, 20 )[ 0 ] = 3;
In the code above, img.At( 10, 20 )[ 0 ] returns a Sample object. Assigning to this object
changes the sample in img that is referenced.
See Indexing for more information.
Derived classes
-
template<typename T>class dip::
Image:: CastSample - Derived from
dip::Image::Sample, works identically except it implicitly converts to typeT. \relates dip::Image::Sample more...
Constructors, destructors, assignment and conversion operators
- auto operator=(dip::Image::Sample const& sample) -> dip::Image::Sample& constexpr
- Assigning to a
Samplecopies the value over to the sample referenced. -
template<typename T, typename <SFINAE>>auto operator=(T value) -> dip::Image::Sample& constexpr
- It is also possible to assign a constant directly.
- Sample(dip::DataType dataType = DT_SFLOAT) explicit
- Construct a new
Sampleby giving the data type. Initialized to 0. -
template<typename T, typename <SFINAE>>Sample(T value) constexpr
- A numeric value implicitly converts to a
Sample. - Sample(dip::Image::Pixel const& pixel)
- A
dip::Image::Pixel, when cast to aSample, references the first value in the pixel. - Sample(dip::Image const& image) explicit
- A
dip::Image, when cast to aSample, references the first sample in the first pixel in the image.
Functions
-
template<typename T, typename <SFINAE>>auto As() const -> T constexpr
- Returns the value of the sample as the given numeric type, similar to using
static_cast. - auto DataType() const -> dip::DataType constexpr
- The data type of the sample referenced.
- static auto Maximum(dip::DataType dt) -> dip::Image::Sample
- Creates a sample with the largest finite value for the given data type. Not implemented for complex types.
- static auto Minimum(dip::DataType dt) -> dip::Image::Sample
- Creates a sample with the lowest finite value for the given data type. Not implemented for complex types.
- auto Origin() const -> void* constexpr
- Returns a pointer to the sample referenced.
- void swap(dip::Image::Sample& other) noexcept
- Swaps
*thisandother.
Operators
- auto operator bool() const -> bool explicit constexpr
- A
Samplecan be cast to basic numerical types. - auto operator dfloat() const -> dip::dfloat explicit constexpr
- A
Samplecan be cast to basic numerical types. - auto operator dip::sint() const -> dip::sint explicit constexpr
- A
Samplecan be cast to basic numerical types. - auto operator dip::uint() const -> dip::uint explicit constexpr
- A
Samplecan be cast to basic numerical types. - auto operator scomplex() const -> dip::scomplex explicit constexpr
- A
Samplecan be cast to basic numerical types. - auto operator sfloat() const -> dip::sfloat explicit constexpr
- A
Samplecan be cast to basic numerical types. -
template<typename T>auto operator%=(T const& rhs) -> dip::Image::Sample&
- Compound assignment operator.
-
template<typename T>auto operator&=(T const& rhs) -> dip::Image::Sample&
- Bit-wise compound assignment operator.
-
template<typename T>auto operator*=(T const& rhs) -> dip::Image::Sample&
- Compound assignment operator.
-
template<typename T>auto operator+=(T const& rhs) -> dip::Image::Sample&
- Compound assignment operator.
-
template<typename T>auto operator-=(T const& rhs) -> dip::Image::Sample&
- Compound assignment operator.
-
template<typename T>auto operator/=(T const& rhs) -> dip::Image::Sample&
- Compound assignment operator.
-
template<typename T>auto operator^=(T const& rhs) -> dip::Image::Sample&
- Bit-wise compound assignment operator.
-
template<typename T>auto operator|=(T const& rhs) -> dip::Image::Sample&
- Bit-wise compound assignment operator.
Function documentation
Sample( dip::DataType dataType = DT_SFLOAT) explicit
Construct a new Sample by giving the data type. Initialized to 0.
template<typename T, typename <SFINAE>>
Sample(
T value) constexpr
A numeric value implicitly converts to a Sample.
Sample( dip::Image::Pixel const& pixel)
A dip::Image::Pixel, when cast to a Sample, references the first value in the pixel.
Sample( dip::Image const& image) explicit
A dip::Image, when cast to a Sample, references the first sample in the first pixel in the image.
dip::Image::Sample& operator=( dip::Image::Sample const& sample) constexpr
Assigning to a Sample copies the value over to the sample referenced.
template<typename T, typename <SFINAE>>
dip::Image::Sample&
operator=(
T value) constexpr
It is also possible to assign a constant directly.
void swap( dip::Image::Sample& other) noexcept
Swaps *this and other.
static dip::Image::Sample Maximum( dip::DataType dt)
Creates a sample with the largest finite value for the given data type. Not implemented for complex types.
static dip::Image::Sample Minimum( dip::DataType dt)
Creates a sample with the lowest finite value for the given data type. Not implemented for complex types.
template<typename T, typename <SFINAE>>
T
As(
) const constexpr
Returns the value of the sample as the given numeric type, similar to using static_cast.
void* Origin( ) const constexpr
Returns a pointer to the sample referenced.
dip::DataType DataType( ) const constexpr
The data type of the sample referenced.
bool operator bool( ) const explicit constexpr
A Sample can be cast to basic numerical types.
dip::uint operator dip::uint( ) const explicit constexpr
A Sample can be cast to basic numerical types.
dip::sint operator dip::sint( ) const explicit constexpr
A Sample can be cast to basic numerical types.
dip::sfloat operator sfloat( ) const explicit constexpr
A Sample can be cast to basic numerical types.
dip::dfloat operator dfloat( ) const explicit constexpr
A Sample can be cast to basic numerical types.
dip::scomplex operator scomplex( ) const explicit constexpr
A Sample can be cast to basic numerical types.
template<typename T>
dip::Image::Sample&
operator+=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Sample&
operator-=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Sample&
operator*=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Sample&
operator/=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Sample&
operator%=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Sample&
operator&=(
T const& rhs)
Bit-wise compound assignment operator.
template<typename T>
dip::Image::Sample&
operator|=(
T const& rhs)
Bit-wise compound assignment operator.
template<typename T>
dip::Image::Sample&
operator^=(
T const& rhs)
Bit-wise compound assignment operator.
std::ostream&
dip:: operator<<(
std::ostream& os, dip::Image::Sample const& sample)
You can output a dip::Image::Sample to std::cout or any other stream.
It is printed like any numeric value of the same type.