Count If

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

std::ptrdiff_t count_if(InputImage ima, std::UnaryPredicate p)

Count the number of pixel whose value verify the predicate p in ima.

Parameters:
  • ima – The image to be trasversed

  • p – The predicate to verify

Template Parameters:
  • InputImage – A model of InputImage

  • std::UnaryPredicate – A model of std::UnaryPredicate

Returns:

number of pixels whose value verifies p in ima

Examples

  1. Counts the number of non-black pixel in an image:

    mln::image2d<mln::rgb8> ima = ...;
    mln::rgb8 black{0, 0, 0};
    std::ptrdiff_t nb_black = mln::count_if(ima, [&](mln::rgb8 v){ return v != black; });
    

Complexity

Linear in the number of pixels.