Sort_points, sort_indexes

Include <mln/core/algorithm/sort.hpp>

  1. void sort_points(InputImage ima, OutputRange &&rng)
    void sort_points(InputImage ima, OutputRange &&rng, Compare cmp)
  2. std::vector<image_point_t<InputImage>> sort_points(InputImage ima)
    std::vector<image_point_t<InputImage>> sort_points(InputImage ima, Compare cmp)
  3. void sort_indexes(InputImage ima, OutputRange &&rng)
    void sort_indexes(InputImage ima, OutputRange &&rng, Compare cmp)
  4. std::vector<image_point_t<InputImage>> sort_indexes(InputImage ima)
    std::vector<image_point_t<InputImage>> sort_indexes(InputImage ima, Compare cmp)

    Sort the points (versions 1-2) or the indexes (versions 3-4) of an image w.r.t their values.

    Parameters:
    • ima – The source image

    • rng – (versions 1,3) The destination range where points or indexes are going to be stored.

    • cmp – (optional) The comparison function between values

    Template Parameters:
    • InputImage – A model of InputImage

    • OutputRange – A model of OutputRange

    • Compare – A model of Compare

    Returns:

    (versions 2-4) A std::vector with the points or the indexes sorted.

Examples

  1. Sort the points by increasing level:

    mln::image2d<mln::uint8> f = ...;
    std::vector<mln::point2d> pts = sort_points(f);
    
  2. Sort the image indexes with a lexicographical comparison (a preorder) on red/blue channels:

    mln::image2d<mln::rgb8> f = ...;
    auto comp = [](mln::rb8 x, mln::rgb8 y) { return std::tie(x[0], x[2]) < std::tie(y[0], y[2]); };
    std::vector<mln::point2d> pts = sort_points(f, comp);
    

Complexity

  • In the general case: \(O(n \log n)\)

  • For low-quantized values: \(\Theta(n)\)