1 #ifndef SOPT_UTILITIES_H
2 #define SOPT_UTILITIES_H
5 #include "sopt/config.h"
23 template<
typename T,
typename U>
31 }
catch(
const std::exception& e) {
37 template <
typename T = std::
string>
38 std::vector<T>
split(std::string s,
const std::string& sep) {
41 const size_t delim_pos = s.find(sep);
42 if (delim_pos == std::string::npos)
break;
43 const std::string sub = s.substr(0, delim_pos);
45 if constexpr(std::is_same<T, std::string>::value) {
49 rtn.push_back(lexical_cast<T>(sub));
52 s.replace(0, delim_pos+1,
"");
56 if constexpr(std::is_same<T, std::string>::value) {
60 rtn.push_back(lexical_cast<T>(s));
68 std::vector<float> float_image(image.size());
69 for (
int i = 0; i < image.size(); i++) {
70 if constexpr(std::is_same<T, t_complex>::value)
72 float_image[i] = image[i].real();
76 float_image[i] =
static_cast<float>(image[i]);
85 for (
int i = 0; i < float_image.size(); i++) {
86 if constexpr(std::is_same<T, t_complex>::value)
92 image[i] =
static_cast<T
>(float_image[i]);
void write_tiff(Image<> const &image, std::string const &filename)
Writes a tiff greyscale file.
std::vector< T > split(std::string s, const std::string &sep)
Split a string on a specified delimiter with optional cast to another type.
Image read_tiff(std::string const &filename)
Reads tiff image.
T lexical_cast(const U &in)
Convert between any types via stringstream.
sopt::Vector< T > floatToImage(std::vector< float > const &float_image)
std::vector< float > imageToFloat(sopt::Vector< T > const &image)
Eigen::Array< T, Eigen::Dynamic, Eigen::Dynamic > Image
A 2-dimensional list of elements of given type.
Eigen::Matrix< T, Eigen::Dynamic, 1 > Vector
A vector of a given type.
std::complex< t_real > t_complex
Root of the type hierarchy for (real) complex numbers.
Exception to be thrown by lexical_cast (below)
bad_lexical_cast(const std::string &what)
sopt::Image< Scalar > Image