I am trying to find a fast algorithm such as :
input:
Image (width w x height h),radius Rcontent: for each pixel (x,y) as
- x in [R, w-R]
- y in [R, h-R]
find the most represented color in the circle of radius
Rand center (x,y). (In the image)output:
Image (w-2R x h-2R)the image built from the results
I have, for now, implemented the base algorithm of that in python, that has a complexity O(n*R^2) (with n = w*h).
I'm now wondering if an algorithm of complexity O(n) may exist. It sounds possible to me, but I cannot manage to build one.
So:
- Do you think a such algorithm may exist ?
- If so, what would he use / how would he work ?
- Otherwise, why ?
- How can I speed up the execution of my algorithm ? (in an algorithm way, i.e. regardless of parallelization)
Edits:
- I use an image representation with a 2 dimensions array. Each pixel (i.e. cell of the array) is a tuple of ints: Red, Green, Blue, between 0 and 255.
- Before running this algorithm, I "level" the image: reduce the number of different colors present in the image (by a kind of clustering on color and proximity)
- If every pixel is different in the surrounding, then it should remain with the same color (for now implemented by giving a "weight" more important to the original pixel's color)
Note: I am not sure that "comparing a pixel with its surrounding" is the best way to describe what I want to do, so if you have ideas to improve the title, let me know in the comments