Commit 4de49b92 authored by Michaël Roynard's avatar Michaël Roynard
Browse files

Merge remote-tracking branch 'origin/development/algo-migration' into development/ranges

parent 756128bd
......@@ -22,7 +22,7 @@ before_script:
- cmake --build apps --config $PYLENE_CONFIGURATION
- cmake --build tests --config $PYLENE_CONFIGURATION
- cmake --build bench/tests --config $PYLENE_CONFIGURATION
- ctest -L UnitTests
- ctest -L UnitTests --schedule-random --output-on-failure
dependencies: []
artifacts:
reports:
......
#pragma once
#include <mln/core/algorithm/all_of.hpp>
#include <mln/core/grays.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/trace.hpp>
......@@ -88,7 +90,10 @@ namespace mln
}
}
mln_postcondition(all(curv >= 0));
using namespace mln::experimental::ops;
mln_postcondition(all_of(curv >= 0));
return curv;
}
} // namespace mln
......@@ -257,7 +257,7 @@ namespace mln
if (maxv > value_traits<uint16>::max())
std::cerr << "Warning: too many values in the depth (depth image output is wrong)\n";
maxdepth = eval(imcast<uint16>(maxdepth_));
maxdepth = eval(mln::imcast<uint16>(maxdepth_));
}
else
{
......
......@@ -25,6 +25,24 @@
typedef mln::morpho::component_tree<unsigned, mln::image2d<unsigned>> tree_t;
// FIXME:
namespace to_migrate
{
template <typename I, class AccuLike, class Extractor = mln::accu::default_extractor>
[[deprecated]] typename mln::accu::result_of<AccuLike, mln_value(I), Extractor>::type
__accumulate(const mln::Image<I>& input, const mln::AccumulatorLike<AccuLike>& accu_,
const Extractor& ex = Extractor())
{
const I& ima = exact(input);
auto a = mln::accu::make_accumulator(exact(accu_), mln_value(I)());
mln_foreach (const auto& v, ima.values())
a.take(v);
return ex(a);
}
} // namespace to_migrate
namespace mln
{
......@@ -41,7 +59,8 @@ namespace mln
float amap_max;
{
auto tmp = make_image(tree, amap);
amap_max = mln::accumulate(tmp, accu::features::max<>());
// FIXME:
amap_max = ::to_migrate::__accumulate(tmp, accu::features::max<>());
for (float x = 0.1; x < amap_max; x += 0.1)
lambdas.push_back(x);
......@@ -82,7 +101,7 @@ namespace mln
for (unsigned i = 0; i < lambdas.size(); ++i)
{
out[i] = eval(imcast<float>(imtransform(res[i + 1] - res[i], functional::l2norm_t<>())));
out[i] = eval(mln::imcast<float>(imtransform(res[i + 1] - res[i], functional::l2norm_t<>())));
}
return out;
......
......@@ -26,5 +26,5 @@ int main(int argc, char** argv)
resize(out, tree._get_data()->m_pmap);
morpho::reconstruction(tree, dmap, out);
io::imsave(imcast<uint16>(out), argv[2]);
io::imsave(mln::imcast<uint16>(out), argv[2]);
}
......@@ -35,7 +35,7 @@ int main(int argc, char** argv)
{
image2d<uint8> g;
io::imread(argv[i], g);
f = eval(imcast<rgb8>(g));
f = eval(mln::imcast<rgb8>(g));
}
tree = compute_ctos(f);
......
......@@ -6,6 +6,24 @@
#include <mln/io/imsave.hpp>
// FIXME:
namespace to_migrate
{
template <typename I, class AccuLike, class Extractor = mln::accu::default_extractor>
[[deprecated]] typename mln::accu::result_of<AccuLike, mln_value(I), Extractor>::type
__accumulate(const mln::Image<I>& input, const mln::AccumulatorLike<AccuLike>& accu_,
const Extractor& ex = Extractor())
{
const I& ima = exact(input);
auto a = mln::accu::make_accumulator(exact(accu_), mln_value(I)());
mln_foreach (const auto& v, ima.values())
a.take(v);
return ex(a);
}
} // namespace to_migrate
int main(int argc, char** argv)
{
using namespace mln;
......@@ -21,13 +39,14 @@ int main(int argc, char** argv)
io::imread(argv[1], f);
io::imread(argv[2], g);
auto f_ = imcast<rgb<float>>(f);
auto g_ = imcast<rgb<float>>(g);
auto f_ = mln::imcast<rgb<float>>(f);
auto g_ = mln::imcast<rgb<float>>(g);
auto diff = imtransform(f_ - g_, [](rgb<float> x) -> double { return l2norm_sqr(x); });
auto dims = f.domain().shape();
double sum = mln::accumulate(diff, accu::features::sum<double>());
double MSE = sum / (3 * dims[0] * dims[1]);
auto dims = f.domain().shape();
// FIXME:
double sum = ::to_migrate::__accumulate(diff, accu::features::sum<double>());
double MSE = sum / (3 * dims[0] * dims[1]);
std::cout << "MSE: " << MSE << "\n";
if (MSE == 0)
......
......@@ -179,11 +179,11 @@ void fill_baseline(mln::image2d<mln::rgb8>& ima, mln::rgb8 v)
}
void fill(mln::image2d<mln::uint8>& ima, mln::uint8 v)
{
mln::experimental::fill(ima, v);
mln::fill(ima, v);
}
void fill(mln::image2d<mln::rgb8>& ima, mln::rgb8 v)
{
mln::experimental::fill(ima, v);
mln::fill(ima, v);
}
......@@ -221,11 +221,11 @@ std::ptrdiff_t count_if_baseline(const mln::image2d<mln::rgb8>& in)
}
std::ptrdiff_t count_if(const mln::image2d<mln::uint8>& in)
{
return mln::experimental::count_if(in, is_uint8_15);
return mln::count_if(in, is_uint8_15);
}
std::ptrdiff_t count_if(const mln::image2d<mln::rgb8>& in)
{
return mln::experimental::count_if(in, is_rgb8_black);
return mln::count_if(in, is_rgb8_black);
}
......@@ -239,11 +239,11 @@ std::ptrdiff_t count_baseline(const mln::image2d<mln::rgb8>& in)
}
std::ptrdiff_t count(const mln::image2d<mln::uint8>& in)
{
return mln::experimental::count(in, mln::uint8(15));
return mln::count(in, mln::uint8(15));
}
std::ptrdiff_t count(const mln::image2d<mln::rgb8>& in)
{
return mln::experimental::count(in, mln::rgb8{0, 0, 0});
return mln::count(in, mln::rgb8{0, 0, 0});
}
......@@ -257,11 +257,11 @@ bool equal_baseline(const mln::image2d<mln::rgb8>& lhs, const mln::image2d<mln::
}
bool equal(const mln::image2d<mln::uint8>& lhs, const mln::image2d<mln::uint8>& rhs)
{
return mln::experimental::equal(lhs, rhs);
return mln::equal(lhs, rhs);
}
bool equal(const mln::image2d<mln::rgb8>& lhs, const mln::image2d<mln::rgb8>& rhs)
{
return mln::experimental::equal(lhs, rhs);
return mln::equal(lhs, rhs);
}
......@@ -275,11 +275,11 @@ void paste_baseline(const mln::image2d<mln::rgb8>& in, mln::image2d<mln::rgb8>&
}
void paste(const mln::image2d<mln::uint8>& in, mln::image2d<mln::uint8>& out)
{
mln::experimental::paste(in, out);
mln::paste(in, out);
}
void paste(const mln::image2d<mln::rgb8>& in, mln::image2d<mln::rgb8>& out)
{
mln::experimental::paste(in, out);
mln::paste(in, out);
}
......@@ -299,11 +299,11 @@ void transform_baseline(const mln::image2d<mln::rgb8>& in, mln::image2d<mln::rgb
}
void transform(const mln::image2d<mln::uint8>& in, mln::image2d<mln::uint8>& out)
{
mln::experimental::transform(in, out, plus_one);
mln::transform(in, out, plus_one);
}
void transform(const mln::image2d<mln::rgb8>& in, mln::image2d<mln::rgb8>& out)
{
mln::experimental::transform(in, out, plus_one);
mln::transform(in, out, plus_one);
}
......@@ -317,11 +317,11 @@ void for_each_baseline(mln::image2d<mln::rgb8>& in)
}
void for_each(mln::image2d<mln::uint8>& in)
{
mln::experimental::for_each(in, plus_one_inplace);
mln::for_each(in, plus_one_inplace);
}
void for_each(mln::image2d<mln::rgb8>& in)
{
mln::experimental::for_each(in, plus_one_inplace);
mln::for_each(in, plus_one_inplace);
}
......@@ -338,7 +338,7 @@ void generate_baseline(mln::image2d<mln::uint8>& ima)
}
void generate(mln::image2d<mln::uint8>& ima)
{
mln::experimental::generate(ima, iota_generator);
mln::generate(ima, iota_generator);
}
......@@ -350,11 +350,11 @@ int accumulate_baseline(const mln::image2d<mln::uint8>& ima)
}
int accumulate(const mln::image2d<mln::uint8>& ima)
{
return mln::experimental::accumulate(ima, 0, std::plus<>{});
return mln::accumulate(ima, 0, std::plus<>{});
}
int accumulate_accu(const mln::image2d<mln::uint8>& ima)
{
return mln::experimental::accumulate(ima, mln::accu::features::sum<int>());
return mln::accumulate(ima, mln::accu::features::sum<int>());
}
......
#include <mln/colors/rgba.hpp>
#include <mln/core/algorithm/clone.hpp>
#include <mln/core/algorithm/transform.hpp>
#include <mln/core/image/image2d.hpp>
......@@ -66,7 +67,8 @@ class BMAlgorithms : public benchmark::Fixture
mln::io::imread(filename, m_input_rgb8);
m_input_uint8 = mln::clone(mln::red(m_input_rgb8));
auto ima_red = mln::transform(m_input_rgb8, [](auto& rgb8) -> auto& { return mln::getter<0>{}(rgb8); });
m_input_uint8 = mln::clone(ima_red);
m_pixel_count = m_input_rgb8.domain().size();
}
......@@ -398,7 +400,7 @@ BENCHMARK_F(BMAlgorithms, sort_points_buffer2d_large_int)(benchmark::State& st)
return res;
};
mln::image2d<int> tmp = mln::experimental::transform(m_input_rgb8, bit_mix);
mln::image2d<int> tmp = mln::transform(m_input_rgb8, bit_mix);
while (st.KeepRunning())
sort_points(tmp);
st.SetBytesProcessed(st.iterations() * m_pixel_count);
......
......@@ -2,6 +2,7 @@
#include <mln/core/algorithm/accumulate.hpp>
#include <mln/core/algorithm/copy.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/utils/ptroffset.hpp>
using namespace mln;
......@@ -80,6 +81,8 @@ unsigned threshold3(const image2d<uint8>& f, uint8 v)
unsigned threshold4(const image2d<uint8>& f, uint8 v)
{
using namespace mln::experimental::ops;
return mln::accumulate(f < v, accu::accumulators::sum<unsigned>());
}
......
#include <mln/core/algorithm/transform.hpp>
#include <mln/core/image/image2d.hpp>
#include <mln/core/image/private/image_operators.hpp>
#include <mln/core/neighb2d.hpp>
#include <mln/core/neighborhood/dyn_wneighborhood.hpp>
#include <mln/core/se/disc.hpp>
......@@ -112,9 +113,10 @@ mln::rgb8 heat_lut(float x)
}
}
int main(int argc, char** argv)
{
using namespace mln::experimental::ops;
if (argc < 4)
{
std::cout << "Usage:" << argv[0] << " input distance output\n";
......@@ -136,14 +138,16 @@ int main(int argc, char** argv)
// (3) Run the watershed segmentation
int nlabel;
auto ws = mln::morpho::watershed<mln::int16>(dinv, mln::c8, nlabel);
auto ws = mln::morpho::experimental::watershed<mln::int16>(dinv, mln::c8, nlabel);
// (4) Labelize input
auto output = mln::where(ws == 0, 1, mln::where(input, ws, 0));
[[maybe_unused]] auto output = mln::experimental::where(ws == 0, 1, mln::experimental::where(input, ws, 0));
// END
auto d_stretched = mln::data::stretch<float>(d);
mln::io::imsave(mln::transform(d_stretched, heat_lut), argv[2]);
mln::io::imsave(mln::transform(output, regions_lut), argv[3]);
// FIXME: migrate rangev3 @HEAD
// mln::io::experimental::imsave(mln::transform(output, regions_lut), argv[3]);
}
......@@ -7,84 +7,41 @@
namespace mln
{
template <typename I, class AccuLike, class Extractor = accu::default_extractor>
[[deprecated]]
typename accu::result_of<AccuLike, mln_value(I), Extractor>::type
accumulate(const Image<I>& input, const AccumulatorLike<AccuLike>& accu, const Extractor& ex = Extractor());
template <typename InputImage, class AccuLike, class Extractor = accu::default_extractor>
typename accu::result_of<AccuLike, image_value_t<InputImage>, Extractor>::type
accumulate(InputImage input, const AccumulatorLike<AccuLike>& accu, const Extractor& ex = Extractor());
template <typename I, class BinaryOperator, class V>
[[deprecated]]
typename std::enable_if<!is_a<BinaryOperator, AccumulatorLike>::value, V>::type
accumulate(const Image<I>& input, const BinaryOperator& op, V init);
namespace experimental
{
template <typename InputImage, class AccuLike, class Extractor = accu::default_extractor>
typename accu::result_of<AccuLike, image_value_t<InputImage>, Extractor>::type
accumulate(InputImage input, const AccumulatorLike<AccuLike>& accu, const Extractor& ex = Extractor());
template <typename InputImage, class V, class BinaryOperator>
std::enable_if_t<!is_a<V, AccumulatorLike>::value, V>
accumulate(InputImage input, V init, BinaryOperator op);
}
template <typename InputImage, class V, class BinaryOperator>
std::enable_if_t<!is_a<V, AccumulatorLike>::value, V> accumulate(InputImage input, V init, BinaryOperator op);
/*********************/
/*** Implementation */
/*********************/
template <typename I, class AccuLike, class Extractor>
typename accu::result_of<AccuLike, mln_value(I), Extractor>::type
accumulate(const Image<I>& input, const AccumulatorLike<AccuLike>& accu_, const Extractor& ex)
template <typename InputImage, class AccuLike, class Extractor>
typename accu::result_of<AccuLike, image_value_t<InputImage>, Extractor>::type
accumulate(InputImage input, const AccumulatorLike<AccuLike>& accu, const Extractor& ex)
{
const I& ima = exact(input);
auto a = accu::make_accumulator(exact(accu_), mln_value(I)());
mln_foreach (const auto& v, ima.values())
a.take(v);
static_assert(mln::is_a<InputImage, experimental::Image>());
auto a = accu::make_accumulator(exact(accu), image_value_t<InputImage>());
auto&& vals = input.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto&& v : row)
a.take(v);
return ex(a);
}
template <typename I, class BinaryOperator, class V>
typename std::enable_if<!is_a<BinaryOperator, AccumulatorLike>::value, V>::type
accumulate(const Image<I>& input, const BinaryOperator& op, V init)
template <typename InputImage, class V, class BinaryOperator>
std::enable_if_t<!is_a<V, AccumulatorLike>::value, V> accumulate(InputImage input, V init, BinaryOperator op)
{
const I& ima = exact(input);
static_assert(mln::is_a<InputImage, experimental::Image>());
mln_foreach (const auto& v, ima.values())
init = op(init, v);
auto&& vals = input.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto&& v : row)
init = op(init, v);
return init;
}
namespace experimental
{
template <typename InputImage, class AccuLike, class Extractor>
typename accu::result_of<AccuLike, image_value_t<InputImage>, Extractor>::type
accumulate(InputImage input, const AccumulatorLike<AccuLike>& accu, const Extractor& ex)
{
static_assert(mln::is_a<InputImage, Image>());
auto a = accu::make_accumulator(exact(accu), image_value_t<InputImage>());
auto&& vals = input.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto&& v : row)
a.take(v);
return ex(a);
}
template <typename InputImage, class V, class BinaryOperator>
std::enable_if_t<!is_a<V, AccumulatorLike>::value, V>
accumulate(InputImage input, V init, BinaryOperator op)
{
static_assert(mln::is_a<InputImage, Image>());
auto&& vals = input.new_values();
for (auto row : mln::ranges::rows(vals))
for (auto&& v : row)
init = op(init, v);
return init;
}
} // namespace experimental
} // namespace mln
......@@ -7,49 +7,41 @@
namespace mln
{
template <class InputImage>
bool all_of(InputImage input);
namespace experimental
{
template <class InputImage>
bool all_of(InputImage input);
template <class InputImage, class UnaryPredicate>
bool all_of(InputImage input, UnaryPredicate p);
}
template <class InputImage, class UnaryPredicate>
bool all_of(InputImage input, UnaryPredicate p);
/******************/
/* Implem */
/******************/
namespace experimental
template <class InputImage, class UnaryPredicate>
bool all_of(InputImage input, UnaryPredicate p)
{
static_assert(mln::is_a<InputImage, experimental::Image>());
static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
if (!::ranges::all_of(r, p))
return false;
return true;
}
template <class InputImage>
bool all_of(InputImage input)
{
template <class InputImage, class UnaryPredicate>
bool all_of(InputImage input, UnaryPredicate p)
{
static_assert(mln::is_a<InputImage, Image>());
static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
if (!::ranges::all_of(r, p))
static_assert(mln::is_a<InputImage, experimental::Image>());
static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>);
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
for (auto&& v : r)
if (!v)
return false;
return true;
}
template <class InputImage>
bool all_of(InputImage input)
{
static_assert(mln::is_a<InputImage, Image>());
static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>);
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
for (auto&& v : r)
if (!v)
return false;
return true;
}
} // namespace experimental
return true;
}
} // namespace mln
......@@ -7,49 +7,41 @@
namespace mln
{
template <class InputImage, class UnaryPredicate>
bool any_of(InputImage input, UnaryPredicate p);
namespace experimental
{
template <class InputImage, class UnaryPredicate>
bool any_of(InputImage input, UnaryPredicate p);
template <class InputImage>
bool any_of(InputImage input);
}
template <class InputImage>
bool any_of(InputImage input);
/******************/
/* Implem */
/******************/
namespace experimental
template <class InputImage, class UnaryPredicate>
bool any_of(InputImage input, UnaryPredicate p)
{
static_assert(mln::is_a<InputImage, experimental::Image>());
static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
if (::ranges::any_of(r, p))
return true;
return false;
}
template <class InputImage>
bool any_of(InputImage input)
{
template <class InputImage, class UnaryPredicate>
bool any_of(InputImage input, UnaryPredicate p)
{
static_assert(mln::is_a<InputImage, Image>());
static_assert(::ranges::Predicate<UnaryPredicate, image_reference_t<InputImage>>());
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
if (::ranges::any_of(r, p))
static_assert(mln::is_a<InputImage, experimental::Image>());
static_assert(std::is_convertible_v<image_reference_t<InputImage>, bool>);
auto&& vals = input.new_values();
for (auto r : ranges::rows(vals))
for (auto&& v : r)
if (v)
return true;
return false;
}
template <class InputImage>
bool any_of(InputImage input)
{