Commit 79ee98c0 authored by Guillaume Lazzara's avatar Guillaume Lazzara
Browse files

Add fastest implementations in labeling::compute.

	* mln/labeling/compute.hh: New fastest implementations.
parent 669c38a5
2010-04-30 Guillaume Lazzara <z@lrde.epita.fr>
Add fastest implementations in labeling::compute.
* mln/labeling/compute.hh: New fastest implementations.
2010-04-30 Guillaume Lazzara <z@lrde.epita.fr>
 
Small fixes in Milena.
// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
// (LRDE)
// Copyright (C) 2008, 2009, 2010 EPITA Research and Development
// Laboratory (LRDE)
//
// This file is part of Olena.
//
......@@ -65,7 +65,7 @@ namespace mln
/// \param[in] input The input image.
/// \param[in] label The labeled image.
/// \param[in] nlabels The number of labels in \p label.
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename I, typename L>
util::array<mln_result(A)>
......@@ -82,7 +82,7 @@ namespace mln
/// \param[in] input The input image.
/// \param[in] label The labeled image.
/// \param[in] nlabels The number of labels in \p label.
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename I, typename L>
util::array<mln_meta_accu_result(A, mln_value(I))>
......@@ -98,7 +98,7 @@ namespace mln
/// \param[in] a An accumulator.
/// \param[in] label The labeled image.
/// \param[in] nlabels The number of labels in \p label.
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename L>
util::array<mln_result(A)>
......@@ -113,7 +113,7 @@ namespace mln
/// \param[in] a A meta-accumulator.
/// \param[in] label The labeled image.
/// \param[in] nlabels The number of labels in \p label.
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename L>
util::array<mln_meta_accu_result(A, mln_psite(L))>
......@@ -129,7 +129,7 @@ namespace mln
/// \param[in] input The input image.
/// \param[in] label The labeled image.
/// \param[in] nlabels The number of labels in \p label.
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename I, typename L>
util::array<mln_result(A)>
......@@ -188,13 +188,13 @@ namespace mln
{
/// Generic implementation of labeling::compute.
/// Generic implementation of labeling::compute.
///
/// \param[in] a_ An accumulator.
/// \param[in] label_ The labeled image.
/// \param[in] nlabels The number of labels in \p label.
///
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename L>
inline
......@@ -231,7 +231,7 @@ namespace mln
/// \param[in] label_ The labeled image.
/// \param[in] nlabels The number of labels in \p label.
///
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename L>
inline
......@@ -273,7 +273,7 @@ namespace mln
/// \param[in] label_ The labeled image.
/// \param[in] nlabels The number of labels in \p label.
///
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename I, typename L>
inline
......@@ -311,7 +311,7 @@ namespace mln
/// \param[in] label_ The labeled image.
/// \param[in] nlabels The number of labels in \p label.
///
/// \return A mln::p_array of accumulator result (one result per label).
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename I, typename L>
inline
......@@ -329,8 +329,13 @@ namespace mln
const L& label = exact(label_);
(void) nlabels;
// FIXME: Check accus size with nlabels.
//util::array<A> accus(static_cast<unsigned>(nlabels) + 1, a);
if (static_cast<unsigned>(nlabels) + 1 != accus.size())
{
accus.resize(0); // Make sure all the accumulators are
// re-initialized when resizing on next
// line.
accus.resize(static_cast<unsigned>(nlabels) + 1);
}
mln_piter(I) p(input.domain());
for_all(p)
......@@ -345,6 +350,125 @@ namespace mln
} // end of namespace mln::labeling::impl::generic
// FIXME: is there any optimization if border::get(input) ==
// border::get(label)) ?
//
/// Fastest implementation of labeling::compute.
///
/// \param[in] a_ An accumulator.
/// \param[in] input_ The input image.
/// \param[in] label_ The labeled image.
/// \param[in] nlabels The number of labels in \p label.
///
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_fastest(const Accumulator<A>& a_,
const Image<I>& input_,
const Image<L>& label_,
const mln_value(L)& nlabels)
{
trace::entering("labeling::impl::compute_fastest");
internal::compute_tests(a_, input_, label_, nlabels);
const A& a = exact(a_);
const I& input = exact(input_);
const L& label = exact(label_);
// FIXME: check image properties + add doc.
util::array<A> accus(static_cast<unsigned>(nlabels) + 1, a);
unsigned ncols = geom::ncols(label);
typedef mln_site(I) P;
typedef const mln_value(I) * iptr_t;
typedef const mln_value(L) * lptr_t;
box_runstart_piter<P> p(label.domain());
for_all(p)
{
iptr_t iptr = & input(p);
lptr_t lptr = & label(p);
for (unsigned i = 0; i < ncols; ++i)
accus[*lptr++].take(*iptr++);
}
util::array<mln_result(A)> res;
convert::from_to(accus, res);
trace::exiting("labeling::impl::generic::compute_fastest");
return res;
}
// FIXME: is there any optimization if border::get(input) ==
// border::get(label)) ?
//
/// Fastest implementation of labeling::compute.
///
/// \param[in] accus An array of accumulators.
/// \param[in] input_ The input image.
/// \param[in] label_ The labeled image.
/// \param[in] nlabels The number of labels in \p label.
///
/// \return A util::array of accumulator result (one result per label).
//
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_fastest(util::array<A>& accus,
const Image<I>& input_,
const Image<L>& label_,
const mln_value(L)& nlabels)
{
trace::entering("labeling::impl::generic::compute_fastest");
//internal::compute_tests(a_, input_, label_, nlabels);
// FIXME: check image properties + add doc.
//const A& a = exact(a_);
const I& input = exact(input_);
const L& label = exact(label_);
(void) nlabels;
if (static_cast<unsigned>(nlabels) + 1 != accus.size())
{
accus.resize(0); // Make sure all the accumulators are
// re-initialized when resizing on next
// line.
accus.resize(static_cast<unsigned>(nlabels) + 1);
}
unsigned ncols = geom::ncols(label);
typedef mln_site(I) P;
typedef const mln_value(I) * iptr_t;
typedef const mln_value(L) * lptr_t;
box_runstart_piter<P> p(label.domain());
for_all(p)
{
iptr_t iptr = & input(p);
lptr_t lptr = & label(p);
for (unsigned i = 0; i < ncols; ++i)
accus[*lptr++].take(*iptr++);
}
util::array<mln_result(A)> res;
convert::from_to(accus, res);
trace::exiting("labeling::impl::generic::compute_fastest");
return res;
}
} // end of namespace mln::labeling::impl
......@@ -364,6 +488,74 @@ namespace mln
}
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_dispatch(
mln::trait::image::value_access::any,
mln::trait::image::value_access::any,
mln::trait::image::ext_domain::any,
mln::trait::image::ext_domain::any,
const Accumulator<A>& a,
const Image<I>& input,
const Image<L>& label,
const mln_value(L)& nlabels)
{
return impl::generic::compute(a, input, label, nlabels);
}
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_dispatch(
mln::trait::image::value_access::direct,
mln::trait::image::value_access::direct,
mln::trait::image::ext_domain::some,
mln::trait::image::ext_domain::some,
const Accumulator<A>& a,
const Image<I>& input,
const Image<L>& label,
const mln_value(L)& nlabels)
{
return impl::compute_fastest(a, input, label, nlabels);
}
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_dispatch(mln::trait::image::value_storage::one_block,
mln::trait::image::value_storage::one_block,
const Accumulator<A>& a,
const Image<I>& input_,
const Image<L>& label_,
const mln_value(L)& nlabels)
{
const I& input = exact(input_);
const L& label = exact(label_);
/// Check basic properties
if (mlc_is(mln_trait_image_value_alignment(I),
trait::image::value_alignment::with_grid)::value &&
mlc_is(mln_trait_image_value_alignment(L),
trait::image::value_alignment::with_grid)::value)
{
return compute_dispatch(
mln_trait_image_value_access(I)(),
mln_trait_image_value_access(L)(),
mln_trait_image_ext_domain(I)(),
mln_trait_image_ext_domain(L)(),
a, input, label, nlabels);
}
else
return impl::generic::compute(a, input, label, nlabels);
}
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
......@@ -371,11 +563,84 @@ namespace mln
const Image<I>& input,
const Image<L>& label,
const mln_value(L)& nlabels)
{
return compute_dispatch(mln_trait_image_value_storage(I)(),
mln_trait_image_value_storage(L)(),
a, input, label, nlabels);
}
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_dispatch(
mln::trait::image::value_access::any,
mln::trait::image::value_access::any,
mln::trait::image::ext_domain::any,
mln::trait::image::ext_domain::any,
util::array<A>& a,
const Image<I>& input,
const Image<L>& label,
const mln_value(L)& nlabels)
{
return impl::generic::compute(a, input, label, nlabels);
}
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_dispatch(
mln::trait::image::value_access::direct,
mln::trait::image::value_access::direct,
mln::trait::image::ext_domain::some,
mln::trait::image::ext_domain::some,
util::array<A>& a,
const Image<I>& input,
const Image<L>& label,
const mln_value(L)& nlabels)
{
return impl::compute_fastest(a, input, label, nlabels);
}
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
compute_dispatch(mln::trait::image::value_storage::one_block,
mln::trait::image::value_storage::one_block,
util::array<A>& a,
const Image<I>& input_,
const Image<L>& label_,
const mln_value(L)& nlabels)
{
const I& input = exact(input_);
const L& label = exact(label_);
/// Check basic properties
if (mlc_is(mln_trait_image_value_alignment(I),
trait::image::value_alignment::with_grid)::value &&
mlc_is(mln_trait_image_value_alignment(L),
trait::image::value_alignment::with_grid)::value)
{
return compute_dispatch(
mln_trait_image_value_access(I)(),
mln_trait_image_value_access(L)(),
mln_trait_image_ext_domain(I)(),
mln_trait_image_ext_domain(L)(),
a, input, label, nlabels);
}
else
return impl::generic::compute(a, input, label, nlabels);
}
template <typename A, typename I, typename L>
inline
util::array<mln_result(A)>
......@@ -384,9 +649,15 @@ namespace mln
const Image<L>& label,
const mln_value(L)& nlabels)
{
return impl::generic::compute(a, input, label, nlabels);
return compute_dispatch(mln_trait_image_value_storage(I)(),
mln_trait_image_value_storage(L)(),
a, input, label, nlabels);
}
template <typename A, typename L>
inline
util::array<mln_result(A)>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment