Math and statistics » Comparison operators module

Monadic and dyadic image comparison operators.

Contents

Functions

void dip::Equal(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
Equality comparison, sample-wise, with singleton expansion.
void dip::NotEqual(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
Inequality comparison, sample-wise, with singleton expansion.
void dip::Lesser(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
Inequality comparison, sample-wise, with singleton expansion.
void dip::Greater(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
Inequality comparison, sample-wise, with singleton expansion.
void dip::NotGreater(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
Inequality comparison, sample-wise, with singleton expansion.
void dip::NotLesser(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
Inequality comparison, sample-wise, with singleton expansion.
void dip::InRange(dip::Image const& in, dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
In-range ternary comparison, sample-wise, with singleton expansion.
void dip::OutOfRange(dip::Image const& in, dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
Out-of-range ternary comparison, sample-wise, with singleton expansion.
void dip::IsNotANumber(dip::Image const& in, dip::Image& out)
True for each pixel that is NaN.
void dip::IsInfinite(dip::Image const& in, dip::Image& out)
True for each pixel that is positive or negative infinity.
void dip::IsFinite(dip::Image const& in, dip::Image& out)
True for each pixel that is not NaN nor infinity.
void dip::Select(dip::Image const& in1, dip::Image const& in2, dip::Image const& in3, dip::Image const& in4, dip::Image& out, dip::String const& selector)
Compares in1 to in2 according to selector, and writes in3 or in4 to out depending on the result.
void dip::Select(dip::Image const& in1, dip::Image const& in2, dip::Image const& mask, dip::Image& out)
Writes either in1 or in2 to out depending on the value of mask.
void dip::Toggle(dip::Image const& in, dip::Image const& in1, dip::Image const& in2, dip::Image& out)
Writes to out whichever of in1 or in2 is closest to in.

Operators

template<typename T>
auto dip::operator==(dip::Image const& lhs, T const& rhs) -> dip::Image
Comparison operator, calls dip::Equal.
template<typename T>
auto dip::operator!=(dip::Image const& lhs, T const& rhs) -> dip::Image
Comparison operator, calls dip::NotEqual.
template<typename T>
auto dip::operator<(dip::Image const& lhs, T const& rhs) -> dip::Image
Comparison operator, calls dip::Lesser.
template<typename T>
auto dip::operator>(dip::Image const& lhs, T const& rhs) -> dip::Image
Comparison operator, calls dip::Greater.
template<typename T>
auto dip::operator<=(dip::Image const& lhs, T const& rhs) -> dip::Image
Comparison operator, calls dip::NotGreater.
template<typename T>
auto dip::operator>=(dip::Image const& lhs, T const& rhs) -> dip::Image
Comparison operator, calls dip::NotLesser.

Function documentation

void dip::Equal(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
#include "diplib.h"

Equality comparison, sample-wise, with singleton expansion.

Out will be binary. lhs must be an image, but rhs can also be a pixel or a sample (or a scalar value that implicitly converts to one).

void dip::NotEqual(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
#include "diplib.h"

Inequality comparison, sample-wise, with singleton expansion.

Out will be binary. lhs must be an image, but rhs can also be a pixel or a sample (or a scalar value that implicitly converts to one).

void dip::Lesser(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
#include "diplib.h"

Inequality comparison, sample-wise, with singleton expansion.

Out will be binary. lhs must be an image, but rhs can also be a pixel or a sample (or a scalar value that implicitly converts to one).

void dip::Greater(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
#include "diplib.h"

Inequality comparison, sample-wise, with singleton expansion.

Out will be binary. lhs must be an image, but rhs can also be a pixel or a sample (or a scalar value that implicitly converts to one).

void dip::NotGreater(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
#include "diplib.h"

Inequality comparison, sample-wise, with singleton expansion.

Out will be binary. lhs must be an image, but rhs can also be a pixel or a sample (or a scalar value that implicitly converts to one).

void dip::NotLesser(dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
#include "diplib.h"

Inequality comparison, sample-wise, with singleton expansion.

Out will be binary. lhs must be an image, but rhs can also be a pixel or a sample (or a scalar value that implicitly converts to one).

void dip::InRange(dip::Image const& in, dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
#include "diplib.h"

In-range ternary comparison, sample-wise, with singleton expansion.

Computes

out = ( in >= lhs ) && ( in <= rhs );

Out will be binary. in must be an image, but lhs and rhs can also be a pixel or a sample (or a scalar value that implicitly converts to one).

void dip::OutOfRange(dip::Image const& in, dip::Image const& lhs, dip::Image const& rhs, dip::Image& out)
#include "diplib.h"

Out-of-range ternary comparison, sample-wise, with singleton expansion.

Computes

out = ( in < lhs ) || ( in > rhs );

Out will be binary. in must be an image, but lhs and rhs can also be a pixel or a sample (or a scalar value that implicitly converts to one).

void dip::IsNotANumber(dip::Image const& in, dip::Image& out)

True for each pixel that is NaN.

void dip::IsInfinite(dip::Image const& in, dip::Image& out)

True for each pixel that is positive or negative infinity.

void dip::IsFinite(dip::Image const& in, dip::Image& out)

True for each pixel that is not NaN nor infinity.

void dip::Select(dip::Image const& in1, dip::Image const& in2, dip::Image const& in3, dip::Image const& in4, dip::Image& out, dip::String const& selector)

Compares in1 to in2 according to selector, and writes in3 or in4 to out depending on the result.

In short, this is the operation that is applied sample by sample:

in1 <selector> in2 ? in3 : in4

The string selector can be one of: “==”, “!=”, “>”, “<”, “>=”, “<=”

An alternative (slower) implementation would be:

dip::Image mask = in1 <selector> in2;
out = in4.Copy();
out.At( mask ) = in3.At( mask );

Note that all input images are singleton-expanded to match in size, so the function can e.g. be used with scalar values for in3 and in4:

    dip::Image result = dip::Select( in1, in2, dip::Image{ true }, dip::Image{ false }, "==" );

The above is an (less efficient) implementation of

dip::Image result = in1 == in2;

The output image has the same type as in3 and in4. If these types are different, the output type is given by

dip::DataType::SuggestDyadicOperation( in3.DataType(), in4.DataType() );

void dip::Select(dip::Image const& in1, dip::Image const& in2, dip::Image const& mask, dip::Image& out)

Writes either in1 or in2 to out depending on the value of mask.

In short, this is the operation that is applied sample by sample:

mask ? in1 : in2

An alternative (slower) implementation would be:

out = in2.Copy();
out.At( mask ) = in1.At( mask );

When out is the same image as in1, the operation becomes similar to (but faster than):

in1.At( !mask ) = in2.At( !mask );

Conversely, when out is the same image as in2, the operation becomes similar to (but faster than):

in2.At( mask ) = in1.At( mask );

The output image has the same type as in1 and in2. If these types are different, the output type is given by

dip::DataType::SuggestDyadicOperation( in1.DataType(), in2.DataType() );

void dip::Toggle(dip::Image const& in, dip::Image const& in1, dip::Image const& in2, dip::Image& out)

Writes to out whichever of in1 or in2 is closest to in.

Each pixel in out will contain the corresponding value in in1 or in2, whichever is closer to the value of in.

An alternative, slower implementation would be:

mask = dip::Abs( in - in1 ) < dip::Abs( in - in2 );
dip::Select( in1, in2, mask, out );

The output image has the same type as in1 and in2. If these types are different, the output type is given by

dataType = dip::DataType::SuggestDyadicOperation( in1.DataType(), in2.DataType() );

#include "diplib.h"
template<typename T>
dip::Image dip::operator==(dip::Image const& lhs, T const& rhs)

Comparison operator, calls dip::Equal.

#include "diplib.h"
template<typename T>
dip::Image dip::operator!=(dip::Image const& lhs, T const& rhs)

Comparison operator, calls dip::NotEqual.

#include "diplib.h"
template<typename T>
dip::Image dip::operator<(dip::Image const& lhs, T const& rhs)

Comparison operator, calls dip::Lesser.

#include "diplib.h"
template<typename T>
dip::Image dip::operator>(dip::Image const& lhs, T const& rhs)

Comparison operator, calls dip::Greater.

#include "diplib.h"
template<typename T>
dip::Image dip::operator<=(dip::Image const& lhs, T const& rhs)

Comparison operator, calls dip::NotGreater.

#include "diplib.h"
template<typename T>
dip::Image dip::operator>=(dip::Image const& lhs, T const& rhs)

Comparison operator, calls dip::NotLesser.