Ask Your Question
1

threshold function

asked 2014-02-11 03:40:20 -0500

ati gravatar image

updated 2015-10-05 06:38:51 -0500

I am getting creazy with Thresholding function in opencv...

I want to keep all values higher than 200 and remove rest of them!

seems I should use this THRESH_TOZERO type but I do not know what should I write instead of double maxval

threshold( Src2, dst, 200, double maxval ,THRESH_TOZERO );

any idea would be appreciated...

EDIT:

Thanks for your comments, I changed it like this but still I do not get the correct result:

#define THRESHOLD TO ZERO 3
threshold(Src2, dst, 200, CV_THRESH_BINARY , 3);
edit retag flag offensive close merge delete

Comments

1

all values < 200 will be 0, and all values >200 will be ? maxVal!

berak gravatar imageberak ( 2014-02-11 03:52:17 -0500 )edit

they should not be changed..if it is 587 after thresholding should remain 587!

ati gravatar imageati ( 2014-02-11 04:06:02 -0500 )edit
1

then you got the idea of thresholding wrong. it's a binarization. there's only 2 values left after it. low and high

berak gravatar imageberak ( 2014-02-11 04:59:39 -0500 )edit
1

just to clarify @beraks comments: it won't be binary with THRESH_TOZERO, but with THRESH_BINARY / THRESH_BINARY_INV, i.e. your first line is correct (with an arbitrary maxval) and your last one isn't (logically and syntactically).

Guanta gravatar imageGuanta ( 2014-02-12 03:09:29 -0500 )edit

2 answers

Sort by » oldest newest most voted
1

answered 2014-02-11 03:52:38 -0500

Moster gravatar image

Just read the documentation:

src – input array (single-channel, 8-bit or 32-bit floating point).
dst – output array of the same size and type as src.
thresh – threshold value.
maxval – maximum value to use with the THRESH_BINARY and THRESH_BINARY_INV thresholding types.
type – thresholding type (see the details below).

Obviously maxval is only used with thresh_binary and its inverted variant. So just put in some random number for maxval. It will be ignored anyways.

edit flag offensive delete link more

Comments

shouldn't I use "THRESHOLD TO ZERO" as its type? if yes, what should I write in maxval part?!

ati gravatar imageati ( 2014-02-11 04:17:56 -0500 )edit
1

Yes, I didnt say anything different. Just read what I said. If you use threshold to zero, its not important what you put in maxval. It will be ignored.

Moster gravatar imageMoster ( 2014-02-11 16:02:14 -0500 )edit
1

answered 2014-02-11 03:50:40 -0500

Guanta gravatar image

Take any value you like, it's only used with THRESH_BINARY (and THRESH_BINARY_INV) as stated in the documentation.

edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-02-11 03:40:20 -0500

Seen: 272 times

Last updated: Feb 11 '14