简体   繁体   中英

OpenCV threshold function


I'm looking for an OpenCV function in python, that is similar to THRESH_TOZERO_INV, but instead of 0 it returns maxvalue.
So instead of:
 dst(x,y) = { 0 if src(x,y) > thresh src(x,y) otherwise }

I'm looking for:

 dst(x,y) = { maxvalue if src(x,y) > thresh src(x,y) otherwise }

Is there an option like that?

If you use THRESH_BINARY first, with a maxval of 1 then you will get a binary matrix with 0 s and 1 s. Call this matrix M . It has a 1 where src(x,y) > thresh and a 0 everywhere else.

Now compute

maxvalue * M + src * (1-M)

where * is the element-wise matrix-product and 1-M means a matrix with all 1 s minus M, ie invert the binary matrix M .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM