9#include <opencv2/core.hpp>
11#define BGR_RED cv::Scalar(0, 0, 0xFF)
12#define BGR_GREEN cv::Scalar(0, 0xFF, 0)
13#define BGR_BLUE cv::Scalar(0xFF, 0, 0)
14#define BGR_YELLOW cv::Scalar(0, 0xFF, 0xFF)
15#define BGR_MAGENTA cv::Scalar(0xFF, 0, 0xFF)
16#define BGR_BLACK cv::Scalar(0, 0, 0)
18using IndexIntensityPair = std::pair<int, double>;
19using IndexIntensityPairVec = std::vector<IndexIntensityPair>;
20using Voxel = cv::Vec3d;
21using Pixel = cv::Vec2d;
34template <
typename T1,
typename T2>
35std::ostream&
operator<<(std::ostream& s, std::pair<T1, T2> p)
37 return s <<
"(" << std::get<0>(p) <<
", " << std::get<1>(p) <<
")";
52std::ostream&
operator<<(std::ostream& s, std::vector<T> v)
57 }
else if (v.size() == 1) {
58 return s << v[0] <<
"]";
61 std::for_each(v.begin(), v.end() - 1, [&s](
const T& t) { s << t <<
", "; });
62 return s << v.back() <<
"]";
84template <
typename T1,
typename T2>
85std::vector<std::pair<T1, T2>>
Zip(
86 const std::vector<T1>& v1,
const std::vector<T2>& v2)
88 assert(v1.size() == v2.size() &&
"v1 and v2 must be the same size");
89 std::vector<std::pair<T1, T2>> res;
90 res.reserve(v1.size());
91 for (
int i = 0; i < int(v1.size()); ++i) {
92 res.push_back(std::make_pair(v1[i], v2[i]));
105template <
typename T,
int Length>
106std::pair<std::vector<T>, std::vector<T>>
Unzip(
107 const std::vector<cv::Vec<T, Length>>& vs)
109 std::vector<T> xs, ys;
110 xs.reserve(vs.size());
111 ys.reserve(vs.size());
112 for (
const auto& v : vs) {
116 return std::make_pair(xs, ys);
130 const std::vector<T>& v,
double newMin = 0,
double newMax = 1)
133 if (std::all_of(std::begin(v), std::end(v), [newMin, newMax](T e) {
134 return newMin <= e && e <= newMax;
136 return std::vector<double>{std::begin(v), std::end(v)};
141 return std::vector<double>{};
144 return std::vector<double>{newMax};
147 auto p = std::minmax_element(begin(v), end(v));
149 auto max = *p.second;
150 std::vector<double> vNorm(v.size());
154 begin(v), end(v), begin(vNorm), [min, max, newMin, newMax](T t) {
155 return ((newMax - newMin) /
double(max - min)) * t +
156 ((newMin * max - min * newMax) /
double(max - min));
168template <
typename T,
int Len>
170 const std::vector<cv::Vec<T, Len>> vs)
172 std::vector<cv::Vec<double, Len>> vsNew(vs.size());
173 std::transform(begin(vs), end(vs), std::begin(vsNew), [](
auto v) {
174 cv::Vec<double, Len> dv(v);
175 if (cv::norm(dv) < 1e-5) {
178 return dv / cv::norm(dv);
196 const std::vector<Voxel>& v1,
const std::vector<Voxel>& v2);
207 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