Apply function to each pixel of the image

Is there a method in OpenCV which takes an input matrix, an output matrix and a function, and applies this function to each pixel? E.g a function like "check value of pixel, if it's below a certain threshold, set it to 0, otherwise keep the value"

I know I can iterate myself over the pixels of a matrix and apply the function myself, just wondering if there is a function which would save me this work.

Answers


If performance is a concern, the following links might be of interest to you:

You can easily create an appropriate LUT if you work with gray scale images.


You can apply lambda function like this (assume for a gray-scale image):

std::for_each(mat.begin<uchar>(), mat.end<uchar>()
              , [](uchar& pixel) {  
                     /* do something with pixel */ 
                });

But still, it's actually a loop.


Edit: You can use remap if you want to apply a generic geometrical transformation to an image.


Need Your Help

Search by an inputstream property

full-text-search inputstream jackrabbit jcr

I have a question about making a xpath expression for filtering resources by a property of type inputStream called data.

Running Angular 2 tests with Karma, issues with templateUrl

angular karma-runner

I am having some trouble running Angular 2 tests with Karma when using templateUrl in my components.