OpenCV threshold with mask

In general, you can simply compute the threshold using cv::threshold, and then copy the src image on dst using the inverted mask. // Apply cv::threshold on all image thresh = cv::threshold(src, dst, thresh, maxval, type); // Copy original image on inverted mask src.copyTo(dst, ~mask); With THRESH_OTSU, however, you also need to compute the threshold value … Read more

Efficient thresholding filter of an array with numpy

b = a[a>threshold] this should do I tested as follows: import numpy as np, datetime # array of zeros and ones interleaved lrg = np.arange(2).reshape((2,-1)).repeat(1000000,-1).flatten() t0 = datetime.datetime.now() flt = lrg[lrg==0] print datetime.datetime.now() – t0 t0 = datetime.datetime.now() flt = np.array(filter(lambda x:x==0, lrg)) print datetime.datetime.now() – t0 I got $ python test.py 0:00:00.028000 0:00:02.461000 http://docs.scipy.org/doc/numpy/user/basics.indexing.html#boolean-or-mask-index-arrays