mlpack 3.4.2
binarize.hpp
Go to the documentation of this file.
1
13#ifndef MLPACK_CORE_DATA_BINARIZE_HPP
14#define MLPACK_CORE_DATA_BINARIZE_HPP
15
16#include <mlpack/prereqs.hpp>
17
18namespace mlpack {
19namespace data {
20
40template<typename T>
41void Binarize(const arma::Mat<T>& input,
42 arma::Mat<T>& output,
43 const double threshold)
44{
45 output.copy_size(input);
46
47 const T *inPtr = input.memptr();
48 T *outPtr = output.memptr();
49
50 #pragma omp parallel for
51 for (omp_size_t i = 0; i < (omp_size_t) input.n_elem; ++i)
52 outPtr[i] = inPtr[i] > threshold;
53}
54
76template<typename T>
77void Binarize(const arma::Mat<T>& input,
78 arma::Mat<T>& output,
79 const double threshold,
80 const size_t dimension)
81{
82 output = input;
83
84 #pragma omp parallel for
85 for (omp_size_t i = 0; i < (omp_size_t) input.n_cols; ++i)
86 output(dimension, i) = input(dimension, i) > threshold;
87}
88
89} // namespace data
90} // namespace mlpack
91
92#endif
void Binarize(const arma::Mat< T > &input, arma::Mat< T > &output, const double threshold)
Given an input dataset and threshold, set values greater than threshold to 1 and values less than or ...
Definition: binarize.hpp:41
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
#define omp_size_t
Definition: prereqs.hpp:136