Math and statistics » Comparison operators module

Monadic and dyadic image comparison operators.

Contents

Functions

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::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() );