The most efficient way to pin values ​​in Matrix OpenCv

I have an OpenCv Mat that I am going to use to override a pixel called remap , which has CV_32FC2 elements.

Some of these items may be out of range for reassignment. So I need to pinch them between Point2f(0, 0) and Point2f(w, h) . What is the shortest or most efficient way to accomplish this with OpenCv 2.x?

Here is one solution:

 void clamp(Mat& mat, Point2f lowerBound, Point2f upperBound) { vector<Mat> matc; split(mat, matc); min(max(matc[0], lowerBound.x), upperBound.x, matc[0]); min(max(matc[1], lowerBound.y), upperBound.y, matc[1]); merge(matc, mat); } 

But I'm not sure if it is the shortest, or if split / merge is effective.

+7
source share
1 answer

Try to split using cvThreshold and then merge. You can also avoid using cvSetImageCOI to avoid splitting. I am not sure if the threshold code supports COI.

You might want to review both versions and compare their performance. I have a feeling that he will do the same.

+1
source

All Articles