I am writing a small program in C++ using OpenCV-2.3 API.
I have an issue processing an adaptive threshold using a non rectangular mask.
So far, I was performing the adaptive threshold on the whole image and masking afterwards. I realise that,in my case , this was a mistake since the masked pixels would be used to calculate the threshold of my pixels of interest (while I simply want to exclude the former from the analysis)…
However, unlike functions such as cv:: norm, cv::adaptiveThreshold does not seem to support explicitly a mask.
Do you know any obvious solution or workaround?
Thank you very muck for your suggestions,
Quentin
I’ve written some Python (sorry not c++) code that will allow for masked adaptive thresholding. Its not very fast, but it does what you want, and you may be able to use it as a basis for C++ code. It works as follows:
mean_convThe images show, the initial image, the mask, the final processed image.
Here’s the code:
After writing this I found this great link that has a good explanation with plenty of image examples, I used their text image for the above example.
Note. Numpy masks do not seem to be respected by scipy
signal.convolve2d(), so the above workarounds were necessary.