Skip to content

Thresholding an image

Romain Milbert edited this page Oct 2, 2017 · 3 revisions

You can apply a threshold over an image to find pixels that match the values you've chosen.

Arcv::Matrix<float> mat = Arcv::Image::read("lena.png");

// Parameters are: an Arcv::Matrix<>, a list of values for lower boundaries, and the same for upper boundaries
Arcv::Matrix<float> res = Arcv::Image::threshold<ARCV_THRESH_TYPE_XXXXX>(mat, { 0.f, 50.f, 50.f }, { 15.f, 150.f, 150.f });

The template ARCV_THRESH_TYPE_XXXXX is to be subsituted with any of the following values:

ARCV_THRESH_TYPE_BINARY        // Above upper bound -> 255, under lower bound -> 0

The values passed as parameters are obviously yours to decide. You can apply this function to any kind of image, but it makes more sense here to threshold over an HSV one.

Please note that the function will fail if you don't specify the same number of values in lower and upper boundaries.

Original HSV image:

Lena HSV

Thresholding type Output image
ARCV_THRESH_TYPE_BINARY (with above values) Thresholded Lena