Volume Cartographer 2.27.0
Files | Classes | Enumerations | Functions
Utilities

Miscellaneous utility functions. More...

Collaboration diagram for Utilities:

Files

file  FloatComparison.hpp
 Methods for comparing floating point numbers.
 
file  Logging.hpp
 
file  MemorySizeStringParser.hpp
 
file  MeshMath.hpp
 Utility functions for calculations on meshes.
 

Classes

class  volcart::RangeIterable< T, >
 Provides an iterable range of numbers with optional step size. More...
 
class  volcart::Range2DIterable< T, >
 Provides an iterable range of 2D number pairs with optional step size. More...
 
class  volcart::EnumerateIterable< Iterable >
 
class  volcart::Signal< Types >
 Basic signal class for implementing event callbacks. More...
 

Enumerations

enum class  volcart::ColorMap {
  volcart::ColorMap::Magma = 0 , volcart::ColorMap::Inferno , volcart::ColorMap::Plasma , volcart::ColorMap::Viridis ,
  volcart::ColorMap::Phase , volcart::ColorMap::BWR
}
 Built-in color maps. More...
 

Functions

cv::Mat volcart::ApplyLUT (const cv::Mat &img, const cv::Mat &lut, float min, float max, bool invert=false)
 Apply a LUT to an image. More...
 
cv::Mat volcart::ApplyLUT (const cv::Mat &img, const cv::Mat &lut, bool invert=false, const cv::Mat &mask=cv::Mat())
 Apply a LUT to an image. More...
 
cv::Mat volcart::GenerateLUTScaleBar (const cv::Mat &lut, bool invert=false, std::size_t height=36, std::size_t width=256)
 Generate a LUT scale bar image. More...
 
auto volcart::Canny (cv::Mat src, const CannySettings &settings) -> cv::Mat
 Perform Canny edge segmentation on an image.
 
cv::Mat volcart::GetColorMapLUT (ColorMap cm, std::size_t bins=256)
 Get a color map LUT for use with ApplyLUT.
 
cv::Mat volcart::GetColorMapLUT (const std::string &name, std::size_t bins=256)
 Get a color map LUT for use with ApplyLUT.
 
std::string volcart::FormatStrToRegexStr (const std::string &s)
 Converts a printf-style format string to a std::regex string. More...
 
auto volcart::QuantizeImage (const cv::Mat &m, int depth=CV_16U, bool scaleMinMax=true) -> cv::Mat
 Convert image to specified depth using max scaling. More...
 
auto volcart::ColorConvertImage (const cv::Mat &m, int channels=1) -> cv::Mat
 Convert image to specified number of channels.
 
template<typename T >
auto volcart::range (T stop)
 
template<typename T0 , typename T1 >
auto volcart::range (T0 start, T1 stop)
 
template<typename T0 , typename T1 , typename T2 >
auto volcart::range (T0 start, T1 stop, T2 step)
 
template<typename T0 , typename T1 >
auto volcart::range2D (T0 vStop, T1 uStop)
 
template<typename T0 , typename T1 , typename T2 , typename T3 >
auto volcart::range2D (T0 vStart, T1 vStop, T2 uStart, T3 uStop)
 
template<typename T0 , typename T1 , typename T2 , typename T3 , typename T4 >
auto volcart::range2D (T0 vStart, T1 vStop, T2 uStart, T3 uStop, T4 step)
 
template<class Iterable >
auto volcart::enumerate (Iterable &&it)
 Wrap an Iterable into a new one whose iterators return an [index, value] pair. More...
 
template<typename... Args>
EnumerateIterable< std::vector< std::common_type_t< Args... > > > volcart::enumerate (Args &&... args)
 Wrap an Iterable into a new one whose iterators return an [index, value] pair. More...
 
static std::size_t volcart::LinearNeighborhoodSize (double radius, double interval, Direction dir)
 Return the size of a Linear Neighborhood calculated with the given parameters. More...
 

Detailed Description

Miscellaneous utility functions.

Enumeration Type Documentation

◆ ColorMap

enum class volcart::ColorMap
strong

Built-in color maps.

Enumerator
Magma 
Inferno 
Plasma 
Viridis 
Phase 
BWR 

Definition at line 17 of file ColorMaps.hpp.

Function Documentation

◆ ApplyLUT() [1/2]

cv::Mat volcart::ApplyLUT ( const cv::Mat &  img,
const cv::Mat &  lut,
bool  invert = false,
const cv::Mat &  mask = cv::Mat() 
)

Apply a LUT to an image.

Maps the pixel values of an image to the range of a LUT. LUT must be a cv::Mat with shape $(1, bins)$. Input images should be CV_8U, CV_16U, or CV_32F. Inputs with more than one channel will be converted to grayscale prior to mapping. If invert is true, the bin mapping will be reversed.

This overload calculates the range of data values and maps that to the range of the LUT. A mask image may be provided to control the region used for calculating the data min/max.

◆ ApplyLUT() [2/2]

cv::Mat volcart::ApplyLUT ( const cv::Mat &  img,
const cv::Mat &  lut,
float  min,
float  max,
bool  invert = false 
)

Apply a LUT to an image.

Maps the pixel values of an image to the range of a LUT. LUT must be a cv::Mat with shape $(1, bins)$. Input images should be CV_8U, CV_16U, or CV_32F. Inputs with more than one channel will be converted to grayscale prior to mapping. Pixel values $\leq$ min will be mapped to the first bin and values $\geq$ max will be mapped to the last bin. If invert is true, the bin mapping will be reversed.

◆ enumerate() [1/2]

template<typename... Args>
EnumerateIterable< std::vector< std::common_type_t< Args... > > > volcart::enumerate ( Args &&...  args)
inline

Wrap an Iterable into a new one whose iterators return an [index, value] pair.

This is an overload for lists of arguments:

for(auto val : enumerate(0, 1, 2, 3)) {
std::cout "values[" << val.first << "] == " << val.second << std::endl;
}
auto enumerate(Iterable &&it)
Wrap an Iterable into a new one whose iterators return an [index, value] pair.
Definition: Iteration.hpp:527

Definition at line 549 of file Iteration.hpp.

◆ enumerate() [2/2]

template<class Iterable >
auto volcart::enumerate ( Iterable &&  it)
inline

Wrap an Iterable into a new one whose iterators return an [index, value] pair.

This roughly approximates the functionality of Python's enumerate function.

// Use as std::pair
std::vector<int> values{1, 2, 3, 4};
for(auto val : enumerate(values)) {
std::cout "values[" << val.first << "] == " << val.second << std::endl;
}
// Use structured bindings (C++17 and up)
// Update the underlying data
for(auto [idx, val] : enumerate(values) {
std::cout << val == values[idx] std::endl;
val++;
std::cout << val == values[idx] std::endl;
}
Template Parameters
IterableIterable container class. Iterable::iterator must meet LegacyIterator requirements
Parameters
itObject of type Iterable

Definition at line 527 of file Iteration.hpp.

◆ FormatStrToRegexStr()

std::string volcart::FormatStrToRegexStr ( const std::string &  s)

Converts a printf-style format string to a std::regex string.

Currently only supports decimal and width specifiers such as %d or %04d.

◆ GenerateLUTScaleBar()

cv::Mat volcart::GenerateLUTScaleBar ( const cv::Mat &  lut,
bool  invert = false,
std::size_t  height = 36,
std::size_t  width = 256 
)

Generate a LUT scale bar image.

Generates an image plot of a LUT for use as a scale bar. If output image has a horizontal aspect ratio (width >= height), min to max values will be plotted left to right. If the output image has a vertical aspect ratio, then min to max values will be plotted bottom to top. If invert is true, the bin mapping will be reversed. If experiencing color banding, consider increasing the number of bins used when calling GetColorMap.

◆ LinearNeighborhoodSize()

static std::size_t volcart::LinearNeighborhoodSize ( double  radius,
double  interval,
Direction  dir 
)
static

Return the size of a Linear Neighborhood calculated with the given parameters.

Definition at line 18 of file LinearNeighborhoodSize.hpp.

◆ QuantizeImage()

auto volcart::QuantizeImage ( const cv::Mat &  m,
int  depth = CV_16U,
bool  scaleMinMax = true 
) -> cv::Mat

Convert image to specified depth using max scaling.

If scaleMinMax == true, the input min and max will be calculated and scaled the full range of the output depth. Otherwise, the range of the input depth will be scaled to the range of the output depth. For floating-point images, the default input range is assumed to be [0,1].

◆ range() [1/3]

template<typename T >
auto volcart::range ( stop)

Convenience method for constructing iterable ranges. Starting value is 0.

Parameters
stopending value (non-inclusive)
Returns
RangeIterable<T>

Definition at line 148 of file Iteration.hpp.

◆ range() [2/3]

template<typename T0 , typename T1 >
auto volcart::range ( T0  start,
T1  stop 
)

Convenience method for constructing iterable ranges. Step value is 1.

Parameters
stopending value (non-inclusive)
Returns
RangeIterable<T>

Definition at line 162 of file Iteration.hpp.

◆ range() [3/3]

template<typename T0 , typename T1 , typename T2 >
auto volcart::range ( T0  start,
T1  stop,
T2  step 
)

Convenience method for constructing iterable ranges.

Parameters
startstarting value
stopending value (non-inclusive)
stepstep size
Returns
RangeIterable<T0>

Definition at line 178 of file Iteration.hpp.

◆ range2D() [1/3]

template<typename T0 , typename T1 , typename T2 , typename T3 >
auto volcart::range2D ( T0  vStart,
T1  vStop,
T2  uStart,
T3  uStop 
)

Convenience method for constructing iterable 2D ranges. Step value is 1.

Parameters
vStartStarting value for outer loop index
vStopUpper limit for outer loop
uStartStarting value for inner loop index
uStopUpper limit for inner loop
Returns
Range2DIterable<T0>

Definition at line 358 of file Iteration.hpp.

◆ range2D() [2/3]

template<typename T0 , typename T1 , typename T2 , typename T3 , typename T4 >
auto volcart::range2D ( T0  vStart,
T1  vStop,
T2  uStart,
T3  uStop,
T4  step 
)

Convenience method for constructing iterable 2D ranges.

Parameters
vStartStarting value for outer loop index
vStopUpper limit for outer loop
uStartStarting value for inner loop index
uStopUpper limit for inner loop
stepStep size for both loops
Returns
Range2DIterable<T0>

Definition at line 376 of file Iteration.hpp.

◆ range2D() [3/3]

template<typename T0 , typename T1 >
auto volcart::range2D ( T0  vStop,
T1  uStop 
)

Convenience method for constructing iterable 2D ranges. Starting value is 0.

Parameters
vStopUpper limit for outer loop
uStopUpper limit for inner loop
Returns
Range2DIterable<T0>

Definition at line 341 of file Iteration.hpp.