LookupTable class
Encapsulates the concept of the look-up table (LUT).
Contents
The Apply
method takes a real, scalar input image and applies the LUT to it, yielding an output that
depends on the characteristics of the LUT, as described below.
If HasIndex
is true, the value of each input pixel is looked up in the index, using interpolation,
yielding a location in the LUT. Again using interpolation, the corresponding LUT values are written
to the output image.
If HasIndex
is false, the value of each input pixel is directly interpreted as a location in the LUT.
For a floating-point input image, interpolation is used to find the corresponding LUT value. For an
integer-valued input image, the pixel value is directly considered the index into the LUT (as interpolation
makes no sense here). Note that the first LUT value is at index 0.
The LUT can contain tensor values, yielding a tensor output image. This is useful to produce e.g. an RGB image from an index representation, as used in GIF files and some TIFF files. It is also useful, for example, to create a color representation from a labeled image.
The output image will have the data type of the LUT.
Note that for binary images, the function dip::Select
is available for a similar result.
Constructors, destructors, assignment and conversion operators
- LookupTable(dip::Image values, dip::FloatArray index = {}) explicit
- The look-up table values are provided through an image. Optionally, provide the index.
Functions
- auto HasIndex() const -> bool
- True if the LUT has an index.
- auto DataType() const -> dip::DataType
- Returns the data type of the LUT, which will also be the data type of the result of applying the LUT.
- void SetOutOfBoundsValue(dip::dfloat value)
- Sets out-of-bounds behavior to using
value
. - void SetOutOfBoundsValue(dip::dfloat lowerValue, dip::dfloat upperValue)
- Sets out-of-bounds behavior to using
lowerValue
andupperValue
. - void KeepInputValueOnOutOfBounds()
- Sets out-of-bounds behavior to using the input value.
- void ClampOutOfBoundsValues()
- Returns out-of-bounds behavior to the default.
- void Apply(dip::Image const& in, dip::Image& out, dip::String const& interpolation) const
- Apply the LUT to a scalar, real-valued image.
- auto Apply(dip::dfloat value, dip::String const& interpolation) const -> dip::Image::Pixel
- Apply the LUT to a scalar value.
- void Convert(dip::DataType dataType)
- Converts the LUT to a different data type. Values are clipped to the target range and/or truncated, as applicable. Complex values are converted to non-complex values by taking the absolute value.
Function documentation
LookupTable(dip::Image values, dip::FloatArray index = {}) explicit
The look-up table values are provided through an image. Optionally, provide the index.
values
must be 1D, but otherwise can be of any data type and have any number of tensor elements.
The result of applying the LUT will be an image with the same data type and number of tensor
elements as values
.
If index
is given, it must have the same number of elements as pixels are in values
, and it
must be sorted small to large. No check is done on the sort order of index
. If index
is given,
HasIndex
will be true.
void Apply(dip::Image const& in, dip::Image& out, dip::String const& interpolation) const
Apply the LUT to a scalar, real-valued image.
See the description for dip::LookupTable
for how this function works. interpolation
can be one of:
"linear"
: the default, uses linear interpolation."nearest"
: uses nearest neighbor interpolation (i.e. rounds the input value to the nearest index)."zero order"
: uses zero order hold interpolation (i.e. uses thefloor
of the input value).