#include "diplib.h"
dip::Image::Pixel class

A pixel represents a set of numeric value in an image, see Image representation.

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 type T. \relates dip::Image::Pixel

Constructors, destructors, assignment and conversion operators

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.
auto operator=(dip::Image::Sample const& sample) -> dip::Image::Pixel&
Assigning a number or sample to a Pixel copies the value over each of the samples in the pixel.
auto operator=(dip::Image::Pixel const& pixel) -> dip::Image::Pixel&
Assigning to a Pixel copies 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.

Classes

class Iterator
An iterator to iterate over the samples in the pixel. Mutable forward iterator.

Functions

void swap(dip::Image::Pixel& other) noexcept
Swaps *this and other.
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 Origin() const -> void*
Returns a pointer to the first sample referenced.
auto DataType() const -> dip::DataType
The data type of the pixel referenced.
auto Tensor() const -> dip::Tensor const&
The tensor shape for the pixel referenced.
auto TensorElements() const -> dip::uint
The number of samples in the pixel referenced.
auto IsScalar() const -> bool
Is it a scalar pixel?
auto TensorStride() const -> dip::sint
The stride to use to access the various samples in the pixel referenced.
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 ReshapeTensorAsVector() -> dip::Image::Pixel&
Change the tensor to a vector, 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 Diagonal() const -> dip::Image::Pixel
Extracts the tensor elements along the diagonal.
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 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 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 Imaginary() const -> dip::Image::Pixel
Extracts the imaginary component of the pixel values, throws an exception if the data type is not complex.
auto begin() const -> dip::Image::Pixel::Iterator
Returns an iterator to the first sample in the pixel.
auto end() const -> dip::Image::Pixel::Iterator
Returns an iterator to one past the last sample in the pixel.
auto All() const -> bool
True if all tensor elements are non-zero.
auto Any() const -> bool
True if one tensor element is non-zero.

Operators

auto operator bool() const -> bool explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
auto operator dip::uint() const -> dip::uint explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
auto operator dip::sint() const -> dip::sint explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
auto operator sfloat() const -> dip::sfloat explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
auto operator dfloat() const -> dip::dfloat explicit
A Pixel can be cast to basic numerical types. The first sample in the pixel is used.
auto operator scomplex() const -> dip::scomplex explicit
A Pixel can 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::uint index) const -> dip::Image::Sample
Indexing into a Pixel retrieves a reference to the specific sample.
auto operator[](dip::UnsignedArray const& indices) const -> dip::Image::Sample
Indexing into a Pixel retrieves a reference to the specific sample, indices must have one or two elements.
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.
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&
Bit-wise compound assignment operator.
template<typename T>
auto operator^=(T const& rhs) -> dip::Image::Pixel&
Bit-wise compound assignment operator.