8#include <opencv2/core.hpp>
10#define BGR_RED cv::Scalar(0, 0, 0xFF)
11#define BGR_GREEN cv::Scalar(0, 0xFF, 0)
12#define BGR_BLUE cv::Scalar(0xFF, 0, 0)
13#define BGR_YELLOW cv::Scalar(0, 0xFF, 0xFF)
14#define BGR_MAGENTA cv::Scalar(0xFF, 0, 0xFF)
15#define BGR_BLACK cv::Scalar(0, 0, 0)
17using IndexIntensityPair = std::pair<int, double>;
18using IndexIntensityPairVec =
typename std::vector<IndexIntensityPair>;
19using Voxel = cv::Vec3d;
20using Pixel = cv::Vec2d;
33template <
typename T1,
typename T2>
34std::ostream&
operator<<(std::ostream& s, std::pair<T1, T2> p)
36 return s <<
"(" << std::get<0>(p) <<
", " << std::get<1>(p) <<
")";
51std::ostream&
operator<<(std::ostream& s, std::vector<T> v)
56 }
else if (v.size() == 1) {
57 return s << v[0] <<
"]";
60 std::for_each(v.begin(), v.end() - 1, [&s](
const T& t) { s << t <<
", "; });
61 return s << v.back() <<
"]";
83template <
typename T1,
typename T2>
84std::vector<std::pair<T1, T2>>
Zip(
85 const std::vector<T1>& v1,
const std::vector<T2>& v2)
87 assert(v1.size() == v2.size() &&
"v1 and v2 must be the same size");
88 std::vector<std::pair<T1, T2>> res;
89 res.reserve(v1.size());
90 for (
int i = 0; i < int(v1.size()); ++i) {
91 res.push_back(std::make_pair(v1[i], v2[i]));
104template <
typename T,
int Length>
105std::pair<std::vector<T>, std::vector<T>>
Unzip(
106 const std::vector<cv::Vec<T, Length>>& vs)
108 std::vector<T> xs, ys;
109 xs.reserve(vs.size());
110 ys.reserve(vs.size());
111 for (
const auto& v : vs) {
115 return std::make_pair(xs, ys);
129 const std::vector<T>& v,
double newMin = 0,
double newMax = 1)
132 if (std::all_of(std::begin(v), std::end(v), [newMin, newMax](T e) {
133 return newMin <= e && e <= newMax;
135 return std::vector<double>{std::begin(v), std::end(v)};
140 return std::vector<double>{};
143 return std::vector<double>{newMax};
146 auto p = std::minmax_element(begin(v), end(v));
148 auto max = *p.second;
149 std::vector<double> vNorm(v.size());
153 begin(v), end(v), begin(vNorm), [min, max, newMin, newMax](T t) {
154 return ((newMax - newMin) /
double(max - min)) * t +
155 ((newMin * max - min * newMax) /
double(max - min));
167template <
typename T,
int Len>
169 const std::vector<cv::Vec<T, Len>> vs)
171 std::vector<cv::Vec<double, Len>> vsNew(vs.size());
172 std::transform(begin(vs), end(vs), std::begin(vsNew), [](
auto v) {
173 cv::Vec<double, Len> dv(v);
174 if (cv::norm(dv) < 1e-5) {
177 return dv / cv::norm(dv);
195 const std::vector<Voxel>& v1,
const std::vector<Voxel>& v2);
206 const std::vector<double>& v1,
const std::vector<double>& v2);
std::ostream & operator<<(std::ostream &s, const volcart::Tensor3D< DType > &tensor)
Write a Tensor3D to an output stream.
std::vector< double > NormalizeVector(const std::vector< T > &v, double newMin=0, double newMax=1)
Normalize vector elements to within the range [newMin, newMax].
double SumSquareDiff(const std::vector< double > &v1, const std::vector< double > &v2)
Sums the square differences between two vectors.
std::vector< std::pair< T1, T2 > > Zip(const std::vector< T1 > &v1, const std::vector< T2 > &v2)
Combine two equal-sized vectors into a single vector of paired elements.
std::vector< double > SquareDiff(const std::vector< Voxel > &v1, const std::vector< Voxel > &v2)
Computes the difference of Squares on two vectors.
std::pair< std::vector< T >, std::vector< T > > Unzip(const std::vector< cv::Vec< T, Length > > &vs)
Separate single vector of paired elements into two vectors of single elements.
Segmentation algorithms and utilities library