Ask Your Question
0

keep values in a specific range in a mat using opencv

asked 2014-02-21 03:06:43 -0600

mahsa gravatar image

updated 2014-02-21 03:59:32 -0600

berak gravatar image

I have a matrix which has values between 100 to 900. I want to just keep values between 300 to 400 and make zero rest of them. I could not find any thresholding function which keep values between a Range. Does Opencv have any function to do that?

Thanks in advance...

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-02-21 03:52:55 -0600

Haris gravatar image

updated 2014-02-21 03:54:50 -0600

Simply do the following...

  1. First create a mask image using inRange, here you should use your upper and lower threshold.

  2. Now using Mat::copyTo copy your source Mat to a new Mat, with the above mask.

Code:

    Mat src; //Your source image
    Mat mask,dst;
    inRange(src,Scalar(300),Scalar(400),mask); // Create a mask image in the range 300 and 400
    src.copyTo(dst,mask); // Your final mat with value between 300 and 400
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-21 03:06:43 -0600

Seen: 5,641 times

Last updated: Feb 21 '14