#include "diplib.h"
Pixel class
A pixel represents a set of 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 pixels are stored in an image, but rather represent a reference to a pixel in an image. Through this reference, individual pixels in an image can be changed. For example:
dip::Image img( { 256, 256 }, 3 ); img.At( 10, 20 ) = { 4, 5, 6 };
In the code above, img.At( 10, 20 ) returns a Pixel object. Assigning to this object
changes the pixel in img that is referenced.
See Indexing for more information.
Derived classes
-
template<typename T>class dip::
Image:: CastPixel - Derived from
dip::Image::Pixel, works identically except it implicitly converts to typeT. \relates dip::Image::Pixel more...
Constructors, destructors, assignment and conversion operators
- auto operator=(dip::Image::Sample const& sample) -> dip::Image::Pixel&
- Assigning a number or sample to a
Pixelcopies the value over each of the samples in the pixel. - auto operator=(dip::Image::Pixel const& pixel) -> dip::Image::Pixel&
- Assigning to a
Pixelcopies the values over to the pixel referenced. -
template<typename T, typename <SFINAE>>auto operator=(std::initializer_list<T> values) -> dip::Image::Pixel&
- It is also possible to assign from an initializer list.
- Pixel(dip::DataType dataType = DT_SFLOAT, dip::uint tensorElements = 1) explicit
- Construct a new
Pixelby giving data type and number of tensor elements. Initialized to 0. - Pixel(dip::Image::Sample const& sample)
- A
Pixelcan be constructed from a single sample, yielding a scalar pixel with the same data type as the sample. - Pixel(dip::FloatArray const& values, dip::DataType dt = DT_SFLOAT)
- A
Pixelcan be constructed from adip::FloatArray. The pixel will be a column vector. -
template<typename T, <SFINAE> = 0>Pixel(std::initializer_list<T> values)
- A
Pixelcan be constructed from an initializer list, yielding a pixel with the same data type and number of tensor elements as the initializer list. The pixel will be a column vector. - Pixel(dip::Image const& image) explicit
- A
dip::Image, when cast to aPixel, references the first pixel in the image.
Classes
Functions
- auto All() const -> bool
- True if all tensor elements are non-zero.
- auto Any() const -> bool
- True if one tensor element is non-zero.
-
template<typename T, typename <SFINAE>>auto As() const -> T
- Returns the value of the first sample in the pixel as the given numeric type, similar to using
static_cast. - auto begin() const -> dip::Image::Pixel::Iterator
- Returns an iterator to the first sample in the pixel.
- auto DataType() const -> dip::DataType
- The data type of the pixel referenced.
- auto Diagonal() const -> dip::Image::Pixel
- Extracts the tensor elements along the diagonal.
- auto end() const -> dip::Image::Pixel::Iterator
- Returns an iterator to one past the last sample in the pixel.
- auto Imaginary() const -> dip::Image::Pixel
- Extracts the imaginary component of the pixel values, throws an exception if the data type is not complex.
- auto IsScalar() const -> bool
- Is it a scalar pixel?
- auto Origin() const -> void*
- Returns a pointer to the first sample referenced.
- auto Real() const -> dip::Image::Pixel
- Extracts the real component of the pixel values, returns an identical copy if the data type is not complex.
- auto ReshapeTensor(dip::uint rows, dip::uint cols) -> dip::Image::Pixel&
- Change the tensor shape, without changing the number of tensor elements.
- auto ReshapeTensor(dip::Tensor const& other) -> dip::Image::Pixel&
- Change the tensor shape, without changing the number of tensor elements.
- auto ReshapeTensorAsDiagonal() -> dip::Image::Pixel&
- Change the tensor to a diagonal matrix, without changing the number of tensor elements.
- auto ReshapeTensorAsVector() -> dip::Image::Pixel&
- Change the tensor to a vector, without changing the number of tensor elements.
- void swap(dip::Image::Pixel& other) noexcept
- Swaps
*thisandother. - auto Tensor() const -> dip::Tensor const&
- The tensor shape for the pixel referenced.
- auto TensorColumn(dip::uint index) const -> dip::Image::Pixel
- Extracts the tensor elements along the given column. The tensor representation must be full (i.e. no symmetric or triangular matrices).
- auto TensorElements() const -> dip::uint
- The number of samples in the pixel referenced.
- auto TensorRow(dip::uint index) const -> dip::Image::Pixel
- Extracts the tensor elements along the given row. The tensor representation must be full (i.e. no symmetric or triangular matrices).
- auto TensorStride() const -> dip::sint
- The stride to use to access the various samples in the pixel referenced.
Operators
- auto operator bool() const -> bool explicit
- A
Pixelcan be cast to basic numerical types. The first sample in the pixel is used. - auto operator dfloat() const -> dip::dfloat explicit
- A
Pixelcan be cast to basic numerical types. The first sample in the pixel is used. - auto operator DimensionArray() const -> dip::FloatArray
- Returns a FloatArray containing the sample values of the pixel. For a complex-valued pixel, the modulus (absolute value) is returned.
- auto operator dip::sint() const -> dip::sint explicit
- A
Pixelcan be cast to basic numerical types. The first sample in the pixel is used. - auto operator dip::uint() const -> dip::uint explicit
- A
Pixelcan be cast to basic numerical types. The first sample in the pixel is used. - auto operator scomplex() const -> dip::scomplex explicit
- A
Pixelcan be cast to basic numerical types. The first sample in the pixel is used. - auto operator sfloat() const -> dip::sfloat explicit
- A
Pixelcan be cast to basic numerical types. The first sample in the pixel is used. -
template<typename T>auto operator%=(T const& rhs) -> dip::Image::Pixel&
- Compound assignment operator.
-
template<typename T>auto operator&=(T const& rhs) -> dip::Image::Pixel&
- Bit-wise compound assignment operator.
-
template<typename T>auto operator*=(T const& rhs) -> dip::Image::Pixel&
- Compound assignment operator.
-
template<typename T>auto operator+=(T const& rhs) -> dip::Image::Pixel&
- Compound assignment operator.
-
template<typename T>auto operator-=(T const& rhs) -> dip::Image::Pixel&
- Compound assignment operator.
-
template<typename T>auto operator/=(T const& rhs) -> dip::Image::Pixel&
- Compound assignment operator.
- auto operator[](dip::uint index) const -> dip::Image::Sample
- Indexing into a
Pixelretrieves a reference to the specific sample. - auto operator[](dip::UnsignedArray const& indices) const -> dip::Image::Sample
- Indexing into a
Pixelretrieves a reference to the specific sample,indicesmust have one or two elements. -
template<typename T>auto operator^=(T const& rhs) -> dip::Image::Pixel&
- Bit-wise compound assignment operator.
-
template<typename T>auto operator|=(T const& rhs) -> dip::Image::Pixel&
- Bit-wise compound assignment operator.
Function documentation
Pixel( dip::DataType dataType = DT_SFLOAT, dip::uint tensorElements = 1) explicit
Construct a new Pixel by giving data type and number of tensor elements. Initialized to 0.
Pixel( dip::Image::Sample const& sample)
A Pixel can be constructed from a single sample, yielding a scalar pixel with the same
data type as the sample.
Pixel( dip::FloatArray const& values, dip::DataType dt = DT_SFLOAT)
A Pixel can be constructed from a dip::FloatArray. The pixel will be a column vector.
template<typename T, <SFINAE> = 0>
Pixel(
std::initializer_list<T> values)
A Pixel can be constructed from an initializer list, yielding a pixel with the same data
type and number of tensor elements as the initializer list. The pixel will be a column vector.
Pixel( dip::Image const& image) explicit
A dip::Image, when cast to a Pixel, references the first pixel in the image.
dip::Image::Pixel& operator=( dip::Image::Sample const& sample)
Assigning a number or sample to a Pixel copies the value over each of the samples in the pixel.
dip::Image::Pixel& operator=( dip::Image::Pixel const& pixel)
Assigning to a Pixel copies the values over to the pixel referenced.
template<typename T, typename <SFINAE>>
dip::Image::Pixel&
operator=(
std::initializer_list<T> values)
It is also possible to assign from an initializer list.
void swap( dip::Image::Pixel& other) noexcept
Swaps *this and other.
template<typename T, typename <SFINAE>>
T
As(
) const
Returns the value of the first sample in the pixel as the given numeric type, similar to using static_cast.
void* Origin( ) const
Returns a pointer to the first sample referenced.
dip::DataType DataType( ) const
The data type of the pixel referenced.
dip::Tensor const& Tensor( ) const
The tensor shape for the pixel referenced.
dip::uint TensorElements( ) const
The number of samples in the pixel referenced.
bool IsScalar( ) const
Is it a scalar pixel?
dip::sint TensorStride( ) const
The stride to use to access the various samples in the pixel referenced.
dip::Image::Pixel& ReshapeTensor( dip::uint rows, dip::uint cols)
Change the tensor shape, without changing the number of tensor elements.
dip::Image::Pixel& ReshapeTensor( dip::Tensor const& other)
Change the tensor shape, without changing the number of tensor elements.
dip::Image::Pixel& ReshapeTensorAsVector( )
Change the tensor to a vector, without changing the number of tensor elements.
dip::Image::Pixel& ReshapeTensorAsDiagonal( )
Change the tensor to a diagonal matrix, without changing the number of tensor elements.
dip::Image::Pixel Diagonal( ) const
Extracts the tensor elements along the diagonal.
dip::Image::Pixel TensorRow( dip::uint index) const
Extracts the tensor elements along the given row. The tensor representation must be full (i.e. no symmetric or triangular matrices).
dip::Image::Pixel TensorColumn( dip::uint index) const
Extracts the tensor elements along the given column. The tensor representation must be full (i.e. no symmetric or triangular matrices).
dip::Image::Pixel Real( ) const
Extracts the real component of the pixel values, returns an identical copy if the data type is not complex.
dip::Image::Pixel Imaginary( ) const
Extracts the imaginary component of the pixel values, throws an exception if the data type is not complex.
dip::Image::Pixel::Iterator begin( ) const
Returns an iterator to the first sample in the pixel.
dip::Image::Pixel::Iterator end( ) const
Returns an iterator to one past the last sample in the pixel.
bool All( ) const
True if all tensor elements are non-zero.
bool Any( ) const
True if one tensor element is non-zero.
bool operator bool( ) const explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
dip::uint operator dip::uint( ) const explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
dip::sint operator dip::sint( ) const explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
dip::sfloat operator sfloat( ) const explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
dip::dfloat operator dfloat( ) const explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
dip::scomplex operator scomplex( ) const explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
dip::FloatArray operator DimensionArray( ) const
Returns a FloatArray containing the sample values of the pixel. For a complex-valued pixel, the modulus (absolute value) is returned.
dip::Image::Sample operator[]( dip::uint index) const
Indexing into a Pixel retrieves a reference to the specific sample.
dip::Image::Sample operator[]( dip::UnsignedArray const& indices) const
Indexing into a Pixel retrieves a reference to the specific sample, indices must have one or two elements.
template<typename T>
dip::Image::Pixel&
operator+=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Pixel&
operator-=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Pixel&
operator*=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Pixel&
operator/=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Pixel&
operator%=(
T const& rhs)
Compound assignment operator.
template<typename T>
dip::Image::Pixel&
operator&=(
T const& rhs)
Bit-wise compound assignment operator.
template<typename T>
dip::Image::Pixel&
operator|=(
T const& rhs)
Bit-wise compound assignment operator.
template<typename T>
dip::Image::Pixel&
operator^=(
T const& rhs)
Bit-wise compound assignment operator.
dip::Image::Pixel
dip:: operator+(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Arithmetic operator, element-wise.
dip::Image::Pixel
dip:: operator-(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Arithmetic operator, element-wise.
dip::Image::Pixel
dip:: operator*(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Arithmetic operator, tensor multiplication.
dip::Image::Pixel
dip:: operator/(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Arithmetic operator, element-wise.
dip::Image::Pixel
dip:: operator%(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Arithmetic operator, element-wise.
dip::Image::Pixel
dip:: operator&(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Bit-wise operator, element-wise.
dip::Image::Pixel
dip:: operator|(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Bit-wise operator, element-wise.
dip::Image::Pixel
dip:: operator^(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Bit-wise operator, element-wise.
dip::Image::Pixel
dip:: operator-(
dip::Image::Pixel const& in)
Unary operator, element-wise.
dip::Image::Pixel
dip:: operator~(
dip::Image::Pixel const& in)
Bit-wise unary operator operator.
dip::Image::Pixel
dip:: operator!(
dip::Image::Pixel const& in)
Boolean unary operator, element-wise.
bool
dip:: operator==(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Comparison operator, can only be true if the two pixels have compatible number of tensor elements.
bool
dip:: operator!=(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Comparison operator, equivalent to !(lhs==rhs).
bool
dip:: operator<(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Comparison operator, can only be true if the two pixels have compatible number of tensor elements.
bool
dip:: operator>(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Comparison operator, can only be true if the two pixels have compatible number of tensor elements.
bool
dip:: operator<=(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Comparison operator, can only be true if the two pixels have compatible number of tensor elements.
bool
dip:: operator>=(
dip::Image::Pixel const& lhs, dip::Image::Pixel const& rhs)
Comparison operator, can only be true if the two pixels have compatible number of tensor elements.
std::ostream&
dip:: operator<<(
std::ostream& os, dip::Image::Pixel const& pixel)
You can output a dip::Image::Pixel to std::cout or any other stream.
It is printed as a sequence of values, prepended with “Pixel with values:”.