5#include <opencv2/core.hpp>
24auto ReadImage(
const filesystem::path& path) -> cv::Mat;
53 const filesystem::path& path,
const cv::Mat& img,
WriteImageOpts = {});
71template <
class Iterable>
73 const filesystem::path& path,
74 const Iterable& iterable,
76 const std::size_t idxOffset = 0)
78 namespace fs = filesystem;
87 if (fs::is_directory(path)) {
94 parent = path.parent_path();
95 ext = path.extension();
98 auto stem = path.stem().string();
100 std::tie(prefix, sep, suffix) =
partition(stem,
"{}");
105 "Index placement separator {{}} not found in stem: {}", stem);
110 auto pad = std::to_string(std::size(iterable)).size();
111 pad = opts.padding.value_or(pad);
114 for (
const auto [i, image] :
enumerate(iterable)) {
117 auto filepath = (parent / name).replace_extension(ext);
auto enumerate(Iterable &&it)
Wrap an Iterable into a new one whose iterators return an [index, value] pair.
Volume Cartographer library
auto Logger() -> std::shared_ptr< spdlog::logger >
Volume Cartographer global logger.
auto to_padded_string(Integer val, const int padding, const char fill='0') -> std::string
Convert an Integer to a padded string.
auto ReadImage(const filesystem::path &path) -> cv::Mat
Read an image from the specified path.
static auto partition(std::string_view s, std::string_view sep) -> std::tuple< std::string, std::string, std::string >
Partition a string by a separator substring.
void WriteImage(const filesystem::path &path, const cv::Mat &img, WriteImageOpts={})
Write image to the specified path.
void WriteImageSequence(const filesystem::path &path, const Iterable &iterable, const WriteImageOpts &opts={}, const std::size_t idxOffset=0)
Write a sequence of images to disk.
std::optional< int > padding
std::optional< int > compression