I have got an Image of around 4048 x 3040 pixels. My task is to find some regions of interest.
These regions can be easily found by computing the variance of border of a rectangle.
I have to do this for every pixel in image with rectangle size of around 10x10.
Just imagine this would be my image (1 are the pixels I want to get variance of, x is my current pixel):
Now I want to calculate variance for this small rectangle (width=3, height=3). Therefore I have to iterate over each pixel in rectangle border and get mean and then variance.Quote:
00000
01110
01x10
01110
Doing this for 4048 x 3040 pixels will end in summing up (and dividing) around 4048 * 3040 * 36 * 2 = 886026240 pixels.
This sounds like a huge number and in fact it is a huge number but there is no possibility to avoid checking every pixel.
However at the moment iterating these much pixels takes around 60seconds (no multithreading, using only one core).
This is "ok" for my application because I do not have to do some kind of real-time processing.
But 60s are still not good at all.
Because this project is not for personal purpose, I have to rewrite my code so it uses OpenCV.
I am not that familar with OpenCV but I did not find any kind of "Get Variance/Mean of Pixel-Rectangle".
Of coz I can iterate again over all pixels but OpenCV uses on default the GPU this means if there is some built-in function which calculates this for me. It would speed up the code enourmos (From 60s to around 3s or even better).
So my main question is:
Is there any kind of function which has low overhead but gives me what I want to have?
If such a function is not existent I will use OpenCL and write my own function, however it would be cool if I could avoid this step.
Thanks in advance.
Edit:
drawContours seems not to solve the problem. Some timings said:
15.7ms for 1280*720 for around 100 conturs.
However I would have around 12000000 conturs (one for each pixel). This would result in total time of:
12000000/100*15.7ms = 1884s
This would be even worse...






but I don't know if it uses the gpu.