33 #include <unordered_set> 35 #include <boost/core/typeinfo.hpp> 41 namespace manipulators {
43 class Slice :
public boost::static_visitor< MultiChannelMap::val_type >
46 Slice(
size_t left,
size_t right)
60 for(
size_t i = m_left; i<
m_right; i++)
62 for(
int j=0; j<channel.
width(); j++)
64 ret[i-
m_left][j] = channel[i][j];
85 class SliceShallow :
public boost::static_visitor< MultiChannelMap::val_type >
100 size_t offset = m_left * channel.
width();
102 boost::core::typeinfo
const & ti = BOOST_CORE_TYPEID(T);
104 boost::shared_array<T> shallow_ptr(
105 channel.
dataPtr().get() + offset,
123 class RandomSample :
public boost::static_visitor< MultiChannelMap::val_type >
127 :m_num_samples(num_samples)
128 ,m_seed(
std::chrono::steady_clock::now().time_since_epoch().count())
141 std::vector<size_t> indices(channel.
numElements());
142 std::iota(indices.begin(), indices.end(), 0);
143 std::shuffle(indices.begin(), indices.end(), std::default_random_engine(m_seed));
145 for(
size_t i=0; i<m_num_samples; i++)
147 for(
size_t j=0; j<channel.
width(); j++)
149 res[i][j] = channel[indices[i]][j];
153 std::unordered_set<size_t> indices;
155 auto eng = std::default_random_engine(m_seed);
156 std::uniform_int_distribution<> distr(0, channel.
numElements() - 1);
158 while(indices.size() < m_num_samples )
160 indices.insert(distr(eng));
164 for(
const size_t& index : indices)
166 for(
size_t j=0; j<channel.
width(); j++)
168 res[i][j] = channel[index][j];
const DataPtr dataPtr() const
SliceShallow(size_t left, size_t right)
MultiChannelMap::val_type operator()(Channel< T > &channel) const
MultiChannelMap::val_type operator()(Channel< T > &channel) const
const size_t m_num_samples
MultiChannelMap::val_type operator()(Channel< T > &channel) const
size_t numElements() const
Slice(size_t left, size_t right)
RandomSample(size_t num_samples)